Skip to content

Commit

Permalink
implement differential and unit tests for complete merkle
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfxyz committed Mar 23, 2024
1 parent 1665dd7 commit de24c41
Show file tree
Hide file tree
Showing 10 changed files with 1,259 additions and 347 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ jobs:
- name: Run Fuzzed Unit Tests
run: forge test --no-match-path src/test/StandardInput.t.sol --fuzz-runs 10000

- name: Run Differential Tests
- name: Run Murky Differential Tests
run: |
npm --prefix differential_testing/scripts/ install
npm --prefix differential_testing/scripts/ run compile
forge test --ffi --contracts differential_testing/test/DifferentialTests.t.sol --fuzz-runs 512
forge test --ffi --contracts differential_testing/test/DifferentialTests.t.sol --fuzz-runs 512
- name: Run Complete Differential Tests
run: |
npm --prefix differential_testing/scripts/ install
npm --prefix differential_testing/scripts/ run compile
forge test --ffi --contracts differential_testing/test/CompleteDifferentialTests.t.sol --fuzz-runs 512
- name: Run Standard Gas Snapshotting
run: forge snapshot --gas-report --ffi --match-path src/test/StandardInput.t.sol
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ out/
*.txt
differential_testing/**/node_modules
differential_testing/**/*.js
differential_testing/**/*.json
differential_testing/data/input

!remappings.txt
24 changes: 24 additions & 0 deletions differential_testing/scripts/generate_complete_proof.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { StandardMerkleTree } from "@openzeppelin/merkle-tree";
import { ethers } from 'ethers';

const fs = require('fs');
const input_file = process.argv[2];
const input = JSON.parse(fs.readFileSync(input_file, 'utf8'));
const one_word = "0x0000000000000000000000000000000000000000000000000000000000000001"
const leafs = input['leafs'].map((bytes32) => [bytes32, one_word]);
const indexToProve = input['index'];
const tree = StandardMerkleTree.of(leafs, ["bytes32", "bytes32"], { sortLeaves: false }); // NO DEFAULT SORTING LEAVES
const proof = tree.getProof(indexToProve);
process.stdout.write(ethers.utils.defaultAbiCoder.encode(['bytes32[]'], [proof]));
// // const root = tree.root;
// // console.log(tree.entries());
// for (const [i, v] of tree.entries()) {
// if (i == indexToProve) {
// const proof = tree.getProof(i);
// console.log('Value:', v);
// console.log('Proof:', proof);
// }
// }
// console.log(tree.root)
// console.log(tree.render())

9 changes: 9 additions & 0 deletions differential_testing/scripts/generate_complete_root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { StandardMerkleTree } from "@openzeppelin/merkle-tree";
const fs = require('fs');
const input_file = process.argv[2];
const input = JSON.parse(fs.readFileSync(input_file, 'utf8'));
const one_word = "0x0000000000000000000000000000000000000000000000000000000000000001"
const leafs = input['leafs'].map((bytes32) => [bytes32, one_word]);
const tree = StandardMerkleTree.of(leafs, ["bytes32", "bytes32"], { sortLeaves: false }); // NO DEFAULT SORTING LEAVES
process.stdout.write(tree.root);

Loading

0 comments on commit de24c41

Please sign in to comment.