Skip to content

Commit

Permalink
standard prefix approach for extension nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
web3security committed Oct 23, 2024
1 parent a323af3 commit f4d3acf
Showing 1 changed file with 3 additions and 28 deletions.
31 changes: 3 additions & 28 deletions contracts/lib/MerklePatriciaProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,16 @@ library MerklePatriciaProof {
);
pathPtr += 1;
} else if (currentNodeList.length == 2) {
// Alternative 1 start
bytes memory nodeValue = RLPReader.toBytes(currentNodeList[0]);
uint256 traversed = _nibblesToTraverse(
nodeValue,
path,
pathPtr
);
//enforce correct nibble
bytes1 prefix = _getNthNibbleOfBytes(0, nodeValue);
if (pathPtr + traversed == path.length) {
//leaf node
//enforce correct nibble
bytes1 prefix = _getNthNibbleOfBytes(0, nodeValue);
if (
keccak256(RLPReader.toBytes(currentNodeList[1])) == keccak256(value) &&
(prefix == bytes1(uint8(2)) || prefix == bytes1(uint8(3)))
Expand All @@ -91,36 +90,12 @@ library MerklePatriciaProof {
}

//extension node
if (traversed == 0) {
if (traversed == 0 || (prefix != bytes1(uint8(0)) && prefix != bytes1(uint8(1)))) {
return false;
}

pathPtr += traversed;
nodeKey = bytes32(RLPReader.toUintStrict(currentNodeList[1]));
// Alternative 1 end

// // Alternative 2 start
// bytes memory nodeValue = RLPReader.toBytes(currentNodeList[0]);
// bytes1 prefix = _getNthNibbleOfBytes(0, nodeValue);
// // Extension node
// if (prefix == bytes1(uint8(0)) || prefix == bytes1(uint8(1))) {
// uint256 traversed = _nibblesToTraverse(
// nodeValue,
// path,
// pathPtr
// );
// if (traversed == 0) {
// return false;
// }
// pathPtr += traversed;
// nodeKey = bytes32(RLPReader.toUintStrict(currentNodeList[1]));
// // Leaf node
// } else if (prefix == bytes1(uint8(2)) || prefix == bytes1(uint8(3))){
// return keccak256(RLPReader.toBytes(currentNodeList[1])) == keccak256(value);
// } else {
// return false;
// }
// // Alternative 2 end
} else {
return false;
}
Expand Down

0 comments on commit f4d3acf

Please sign in to comment.