Skip to content

Commit

Permalink
fix(contracts): OZ-L04 Trie Depth Is Not Explicitly Capped (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimpha authored Mar 5, 2024
1 parent 8a4645e commit 1495645
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions integration-test/ZkTrieVerifier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,28 @@ describe("ZkTrieVerifier", async () => {
});
}

it("should revert, when InvalidNodeDepth", async () => {
const test = testcases[0];
{
const proof = concat([
`0xfa`,
...test.accountProof,
`0x${test.storageProof.length.toString(16).padStart(2, "0")}`,
...test.storageProof,
]);
await expect(verifier.verifyZkTrieProof(test.account, test.storage, proof)).to.revertedWith("InvalidNodeDepth");
}
{
const proof = concat([
`0x${test.accountProof.length.toString(16).padStart(2, "0")}`,
...test.accountProof,
`0xfa`,
...test.storageProof,
]);
await expect(verifier.verifyZkTrieProof(test.account, test.storage, proof)).to.revertedWith("InvalidNodeDepth");
}
});

it("should revert, when InvalidBranchNodeType", async () => {
const test = testcases[0];
for (const i of [0, 1, test.accountProof.length - 3]) {
Expand Down
1 change: 1 addition & 0 deletions src/libraries/verifier/ZkTrieVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ library ZkTrieVerifier {

// the first byte is the number of nodes + 1
let nodes := sub(byte(0, calldataload(ptr)), 1)
require(lt(nodes, 249), "InvalidNodeDepth")
ptr := add(ptr, 1)

// treat the leaf node with different logic
Expand Down

0 comments on commit 1495645

Please sign in to comment.