Skip to content

Commit

Permalink
Retains a pattern of generated proof data
Browse files Browse the repository at this point in the history
Resolves: OpenST#754
  • Loading branch information
Paruyr Gevorgyan committed May 29, 2019
1 parent ffff482 commit 93482a1
Show file tree
Hide file tree
Showing 5 changed files with 369 additions and 5 deletions.
362 changes: 361 additions & 1 deletion test/data/generatedProofData.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tools/fuzzy_proof_generator_tool/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ProofData from './src/ProofData';
import patterns from './patterns';

interface HexProof {
pattern: string;
value: string;
encodedPath: string;
rlpParentNodes: string;
Expand All @@ -20,6 +21,7 @@ function bufferToHex(buffer: Buffer): string {
/** Converts a proof to a hex proof. */
function proofToHexProof(proof: ProofData): HexProof {
return {
pattern: proof.pattern,
value: bufferToHex(proof.value),
encodedPath: bufferToHex(proof.encodedPath),
rlpParentNodes: bufferToHex(proof.rlpParentNodes),
Expand Down
5 changes: 2 additions & 3 deletions tools/fuzzy_proof_generator_tool/src/FuzzyProofGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

import Nibbles from './Nibbles';
import NodeBase from './NodeBase';
import { BranchNode } from './BranchNode';
import { BranchKeys } from './BranchNode';
import { BranchNode, BranchKeys } from './BranchNode';
import ExtensionNode from './ExtensionNode';
import LeafNode from './LeafNode';
import ProofData from './ProofData';
Expand Down Expand Up @@ -109,6 +108,7 @@ const FuzzyProofGenerator = {
});

const proofData = {
pattern,
value: (endingWithBranchNode ? rlpValuehash : valueHash),
encodedPath: path,
rlpParentNodes: rlp.encode(rlpParentNodesArray),
Expand Down Expand Up @@ -152,7 +152,6 @@ const FuzzyProofGenerator = {
processBranch(pattern: string, index: number): void {
if (index === pattern.length) {
if (pattern.length === 1 || pattern[index - 2] !== 'b') {

// The verification library we are using in our project would accept
// as a valid proof only a path ending with double 'b' (putting aside
// an ending leaf node, as it's always allowed).
Expand Down
1 change: 1 addition & 0 deletions tools/fuzzy_proof_generator_tool/src/ProofData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default interface ProofData {
pattern: string;
value: Buffer;
encodedPath: Buffer;
rlpParentNodes: Buffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async function verifyProof(pattern, pathMaxLength, valueMaxLength, merklePatrici

if (!proofStatus) {
console.log(
proofData.pattern,
`0x${proofData.value.toString('hex')}`,
`0x${proofData.encodedPath.toString('hex')}`,
`0x${proofData.rlpParentNodes.toString('hex')}`,
Expand All @@ -55,11 +56,12 @@ async function verifyProof(pattern, pathMaxLength, valueMaxLength, merklePatrici
async function verifyProofs(pattern, merklePatriciaLib) {
for (let i = 0; i < TEST_PATH_LENGTHS.length; i += 1) {
for (let j = 0; j < TEST_VALUE_LENGTHS.length; j += 1) {
// eslint-disable-next-line no-await-in-loop
await verifyProof(
pattern,
Math.max(TEST_PATH_LENGTHS[i], Math.ceil(pattern.length / 2)),
Math.max(TEST_VALUE_LENGTHS[j], Math.ceil(pattern.length / 2)),
merklePatriciaLib
merklePatriciaLib,
);
}
}
Expand Down

0 comments on commit 93482a1

Please sign in to comment.