Skip to content

Commit

Permalink
Merge pull request #743 from schemar/generate_proof_data
Browse files Browse the repository at this point in the history
Generate proof data
  • Loading branch information
0xsarvesh authored May 22, 2019
2 parents 81549b1 + bd2b4ef commit 784fa38
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,12 @@
"artifacts": false,
"contract": false,
"assert": false
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
}
}
1 change: 1 addition & 0 deletions test/data/generatedProofData.json

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions tools/fuzzy_proof_generator_tool/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as fs from 'fs';
import * as path from 'path';

import FuzzyProofGenerator from './src/FuzzyProofGenerator';
import ProofData from './src/ProofData';
import patterns from './patterns';

interface HexProof {
value: string;
encodedPath: string;
rlpParentNodes: string;
root: string;
}

/** Converts a buffer to a hex string with a leading 0x. */
function bufferToHex(buffer: Buffer): string {
return `0x${buffer.toString('hex')}`;
}

/** Converts a proof to a hex proof. */
function proofToHexProof(proof: ProofData): HexProof {
return {
value: bufferToHex(proof.value),
encodedPath: bufferToHex(proof.encodedPath),
rlpParentNodes: bufferToHex(proof.rlpParentNodes),
root: bufferToHex(proof.root),
};
}

const proofs: ProofData[] = [];

// Run 4 times to generate more data.
for (let i = 0; i < 4; i += 1) {
patterns.forEach(
(pattern: string): number => proofs.push(FuzzyProofGenerator.generateByPattern(pattern)),
);
}

// Convert to hex to be in line with the rest of the code base.
const hexProofs: HexProof[] = proofs.map(
(proof: ProofData): HexProof => proofToHexProof(proof),
);

const filePath: string = path.join(
__dirname,
'..',
'..',
'test',
'data',
'generatedProofData.json',
);

fs.writeFileSync(filePath, JSON.stringify(hexProofs));
19 changes: 19 additions & 0 deletions tools/fuzzy_proof_generator_tool/patterns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const patterns: string[] = [
'l',
'bl',
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbl',
'ebl',
'bebl',
'bbebbl',
'bebbbbl',
'bbbebbbbbl',
'ebebl',
'ebebebebebl',
'bbebbebebebebbbebebl',
'bebb',
'bebebb',
'ebb',
'ebebebebbb',
];

export { patterns as default };
7 changes: 1 addition & 6 deletions tools/fuzzy_proof_generator_tool/src/FuzzyProofGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@ import { BranchNode } from './BranchNode';
import { BranchKeys } from './BranchNode';
import ExtensionNode from './ExtensionNode';
import LeafNode from './LeafNode';
import ProofData from './ProofData';

import assert = require('assert');
import ethUtil = require('ethereumjs-util');
import rlp = require('rlp');
import crypto = require('crypto');

interface ProofData {
value: Buffer;
encodedPath: Buffer;
rlpParentNodes: Buffer;
root: Buffer;
}

const FuzzyProofGenerator = {

Expand Down
6 changes: 6 additions & 0 deletions tools/fuzzy_proof_generator_tool/src/ProofData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default interface ProofData {
value: Buffer;
encodedPath: Buffer;
rlpParentNodes: Buffer;
root: Buffer;
}

0 comments on commit 784fa38

Please sign in to comment.