diff --git a/yarn-project/foundation/src/buffer/index.ts b/yarn-project/foundation/src/buffer/index.ts index 0950f7bc4122..a1071b998f9e 100644 --- a/yarn-project/foundation/src/buffer/index.ts +++ b/yarn-project/foundation/src/buffer/index.ts @@ -1,2 +1,3 @@ export * from './buffer32.js'; export * from './buffer16.js'; +export * from './utils.js'; diff --git a/yarn-project/foundation/src/buffer/utils.test.ts b/yarn-project/foundation/src/buffer/utils.test.ts new file mode 100644 index 000000000000..ce07775acd15 --- /dev/null +++ b/yarn-project/foundation/src/buffer/utils.test.ts @@ -0,0 +1,35 @@ +import { trimmedBytesLength } from './utils.js'; + +describe('trimmedBytesLength', () => { + it('returns 0 for an empty buffer', () => { + expect(trimmedBytesLength(new Uint8Array([]))).toBe(0); + }); + + it('returns 0 for an all-zeros buffer', () => { + expect(trimmedBytesLength(new Uint8Array([0, 0, 0, 0]))).toBe(0); + }); + + it('returns full length when there are no trailing zeros', () => { + expect(trimmedBytesLength(new Uint8Array([1, 2, 3]))).toBe(3); + }); + + it('excludes trailing zeros', () => { + expect(trimmedBytesLength(new Uint8Array([1, 2, 0, 0]))).toBe(2); + }); + + it('preserves leading zeros', () => { + expect(trimmedBytesLength(new Uint8Array([0, 0, 1, 0, 0]))).toBe(3); + }); + + it('preserves interior zeros', () => { + expect(trimmedBytesLength(new Uint8Array([1, 0, 0, 2, 0]))).toBe(4); + }); + + it('handles a single non-zero byte', () => { + expect(trimmedBytesLength(new Uint8Array([0, 0, 5]))).toBe(3); + }); + + it('handles a single zero byte', () => { + expect(trimmedBytesLength(new Uint8Array([0]))).toBe(0); + }); +}); diff --git a/yarn-project/foundation/src/buffer/utils.ts b/yarn-project/foundation/src/buffer/utils.ts new file mode 100644 index 000000000000..d5958f8fcdd4 --- /dev/null +++ b/yarn-project/foundation/src/buffer/utils.ts @@ -0,0 +1,8 @@ +/** Returns the number of bytes in the buffer, excluding any trailing zero bytes. */ +export function trimmedBytesLength(buf: Uint8Array): number { + let end = buf.length; + while (end > 0 && buf[end - 1] === 0) { + end--; + } + return end; +} diff --git a/yarn-project/sequencer-client/src/publisher/sequencer-publisher.ts b/yarn-project/sequencer-client/src/publisher/sequencer-publisher.ts index 7398d2fa67cb..c0bd98f6bf6f 100644 --- a/yarn-project/sequencer-client/src/publisher/sequencer-publisher.ts +++ b/yarn-project/sequencer-client/src/publisher/sequencer-publisher.ts @@ -28,6 +28,7 @@ import { FormattedViemError, formatViemError, mergeAbis, tryExtractEvent } from import { sumBigint } from '@aztec/foundation/bigint'; import { toHex as toPaddedHex } from '@aztec/foundation/bigint-buffer'; import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types'; +import { trimmedBytesLength } from '@aztec/foundation/buffer'; import { pick } from '@aztec/foundation/collection'; import type { Fr } from '@aztec/foundation/curves/bn254'; import { TimeoutError } from '@aztec/foundation/error'; @@ -547,7 +548,16 @@ export class SequencerPublisher { }); return { failedActions: requests.map(r => r.action) }; } else { - this.log.verbose(`Published bundled transactions (${actionsListStr})`, { result, requests }); + this.log.verbose(`Published bundled transactions (${actionsListStr})`, { + result, + requests: requests.map(r => ({ + ...r, + // Avoid logging large blob data + blobConfig: r.blobConfig + ? { ...r.blobConfig, blobs: r.blobConfig.blobs.map(b => ({ size: trimmedBytesLength(b) })) } + : undefined, + })), + }); const successfulActions: Action[] = []; const failedActions: Action[] = []; for (const request of requests) {