Skip to content

test: proof-length byte is mis-encoded for proofs of 16+ nodes - #178

Open
boleklebovski wants to merge 1 commit into
scroll-tech:mainfrom
boleklebovski:test/pad-proof-length-byte
Open

test: proof-length byte is mis-encoded for proofs of 16+ nodes#178
boleklebovski wants to merge 1 commit into
scroll-tech:mainfrom
boleklebovski:test/pad-proof-length-byte

Conversation

@boleklebovski

Copy link
Copy Markdown

Problem

hardhat-test/PatriciaMerkleTrieVerifier.spec.ts:130,132 builds the proof-length byte by hand:

`0x0${test.accountProof.length.toString(16)}`,
`0x0${test.storageProof.length.toString(16)}`,

The literal 0 plus a variable-width hex string only adds up to one byte while the length is below 16. From 16 onwards toString(16) returns two characters and the template becomes 0x010 — three hex digits, an odd-length byte string that concat rejects.

Every current fixture has fewer than 16 proof nodes, so the suite passes and the defect is invisible. It would surface the first time someone adds a fixture with a deeper proof, and it would look like a contract bug rather than a test-harness bug.

Fix

Use the same padding the sibling spec already uses. hardhat-test/ZkTrieVerifier.spec.ts does this at four sites (lines 284, 286, 296, 298):

`0x${test.accountProof.length.toString(16).padStart(2, "0")}`,

Two lines changed, bringing this file in line with its neighbour.

Verification

npx hardhat test runs in CI (.github/workflows/contracts.yml:139), so this file is live rather than dormant. The change is behaviour-preserving for every existing fixture: for any length below 16 both forms produce identical output.

`0x0${n.toString(16)}` only yields a byte for n < 16; ZkTrieVerifier.spec
already uses padStart.

Signed-off-by: boleklebovski <160799963+boleklebovski@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant