dmfxyz / murky

Merkle Proof Generator and Validator in Solidity
MIT License
368 stars 35 forks source link

feat: add foundry script for proof generation #6

Closed kootsZhin closed 11 months ago

kootsZhin commented 1 year ago

Script

Merkle.s.sol is implemented using forge-std for quick and simple interaction with the core contracts. The script reads from script/target/input.json, generates merkle proof using Merkle.sol and then outputs at script/target/output.json.

The hashes of the leafs are generated using keccak256(bytes.concat(keccak256(abi.encode(...)))), which is the same as OpenZeppelin/merkle-tree.

forge script script/Merkle.s.sol

Updated

Remarks

I created this PR mainly for fun to play around with the repo and file I/O + JSON parsing using forge-std! :)

The code is sort of messy because of the limitation of forge-std/StdJson.sol (e.g. string starting with "0x" could not be normally decoded, weird behaviour when decoding array of arrays, etc.). The type casting and bytes decoding parts are also a bit chunky, feel free to let me know if any part should be improved!

dmfxyz commented 1 year ago

Sweet. Without my laptop for a few days so will review this next week.

dmfxyz commented 1 year ago

Too complex to review in phone browser.