-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write a fuzzer that generates the valid Merkel Patricia Proof #716
Comments
[Has been reflected in the description] Improve following proposal:
|
Resolves: OpenST#716 See also: OpenST#718, OpenST#719
@pgev please write a summary of the work done as a handover so that tomorrow someone else on the team can continue this ticket. Then please unassign and move it to top of backlog. Thanks! |
The implementation consists of 4 main components:
Eslint (for typescript) with config files has been setup for the project. Utility (Util.ts) functions are covered by unit tests. FuzzyProofGenerator pattern validity functionality mostly covered by tests. Documentation is mostly missing. Next steps is to check why generated proof is not passing. One could modify merkle_patricia_proof.js and feed MerklePatriciaProof::verify function with generated proof data. Like this one: contract('MerklePatriciaProof.verify()', () => {
let merklePatriciaLib;
describe('Test Cases for Account proof verification', async () => {
before(async () => {
merklePatriciaLib = await MerklePatriciaProof.deployed();
});
it('Should pass when all the parameters are valid', async () => {
const proofData = FuzzyProofGenerator.generate('l', 'do', 'verb');
const proofStatus = await merklePatriciaLib.verifyDebug.call(
proofData.value,
`0x${proofData.encodedPath.toString('hex')}`,
`0x${proofData.rlpParentNodes.toString('hex')}`,
proofData.root,
);
console.log(proofStatus);
assert.equal(proofStatus.res_, true);
});
});
}); |
Implementation is ready in PR #729. As currently, MerklePatriciaProof::verify library has a different handling for a value of ending node (branch and leaf), the implementation of the fuzzy proof generator is adjusted accordingly. MerklePatriciaProof::verify library uses the following code snippet to check a value in a leaf node: if(keccak256(abi.encodePacked(RLP.toData(currentNodeList[1]))) == value) {
return true;
} else {
return false;
} RLP.toData function decodes a value before comparing with expected value. if(keccak256(abi.encodePacked(RLP.toBytes(currentNodeList[16]))) == value) {
return true;
} else {
return false;
} RLP.toBytes() function returns an underlying data without decoding. Hence, FuzzyProofGenerator::generate() function returns proof, like: const proofData = {
value: (endingWithBranchNode ? rlpValuehash : valueHash),
encodedPath: path,
rlpParentNodes: rlp.encode(rlpParentNodesArray),
root: nodes[0].hash(),
}; In case of a branch node, generator returns a rlpValueHash (instead of valueHash), as MerklePatriciaProof::verify() function compares against an expected value without decoding. |
Write a fuzzer tool which can generate random positive proofs. This tool should accept the depth and sequence of node types.
Specification of valid proof:
Input can be a
string
orArray
of character likel
,b
,e
wherel
represents leaf node,b
represents branch node ande
represents extension node.The output of the fuzzer tool:
The detailed specification of Merkel Patricia tree: https://github.com/ethereum/wiki/wiki/Patricia-Tree#modified-merkle-patricia-trie-specification-also-merkle-patricia-tree
The text was updated successfully, but these errors were encountered: