diff --git a/package.json b/package.json index a940fa40..810aa3f0 100644 --- a/package.json +++ b/package.json @@ -3,59 +3,97 @@ "version": "0.4.1", "description": "JS version of the zkProver.", "main": "index.js", + "config": { + "steps": [ + "buildrom buildconstants exec pilverify buildstarkinfo buildchelpers buildconstanttree prove verify gencircom compilecircom", + "c12a_setup c12a_buildstarkinfo c12a_buildchelpers c12a_exec c12a_pilverify c12a_buildconstanttree c12a_prove c12a_verify c12a_gencircom c12a_compilecircom", + "c12b_setup c12b_buildstarkinfo c12b_buildchelpers c12b_exec c12b_pilverify c12b_buildconstanttree c12b_prove c12b_verify c12b_gencircom c12b_compilecircom", + "g16setup g16contribute g16evk g16wc g16prove g16verify g16solidity" + ], + "steps_setup": [ + "buildrom buildconstants buildstarkinfo buildchelpers buildconstanttree gencircom compilecircom", + "c12a_setup c12a_buildstarkinfo c12a_buildchelpers c12a_buildconstanttree c12a_gencircom", + "recursive1_gencircom recursive1_compile recursive1_setup recursive1_buildstarkinfo recursive1_buildchelpers recursive1_buildconstanttree recursive1_verifier_gencircom", + "recursive2_gencircom recursive2_compile recursive2_setup recursive2_buildstarkinfo recursive2_buildchelpers recursive2_buildconstanttree recursive2_verifier_gencircom", + "recursive_pil_check recursive_verifier_check ", + "recursivef_gencircom recursivef_compile recursivef_setup recursivef_buildstarkinfo recursivef_buildchelpers recursivef_buildconstanttree recursivef_verifier_gencircom", + "final_gencircom final_compile", + "g16setup g16contribute g16evk g16solidity" + ], + "steps_proof": [ + "exec pilverify prove verify", + "c12a_exec c12a_pilverify c12a_prove c12a_verify", + "c12b_exec c12b_pilverify c12b_prove c12b_verify", + "g16wc g16prove g16verify" + ] + }, "scripts": { - "buildgenesis": "", - "buildinput": "", - "buildall": "tools/build_all.sh buildrom buildconstants exec pilverify buildstarkinfo buildchelpers buildconstanttree prove verify gencircom compilecircom c12a_setup c12a_buildstarkinfo c12a_buildchelpers c12a_exec c12a_pilverify c12a_buildconstanttree c12a_prove c12a_verify c12a_gencircom c12a_compilecircom c12b_setup c12b_buildstarkinfo c12b_buildchelpers c12b_exec c12b_pilverify c12b_buildconstanttree c12b_prove c12b_verify c12b_gencircom c12b_compilecircom g16setup g16contribute g16evk g16wc g16prove g16verify g16solidity", - "buildsetup": "tools/build_all.sh buildrom buildconstants buildstarkinfo buildchelpers buildconstanttree gencircom compilecircom c12a_setup c12a_buildstarkinfo c12a_buildchelpers c12a_buildconstanttree c12a_gencircom c12a_compilecircom c12b_setup c12b_buildstarkinfo c12b_buildchelpers c12b_buildconstanttree c12b_gencircom c12b_compilecircom g16setup g16contribute g16evk g16solidity", - "buildproof": "tools/build_all.sh exec pilverify prove verify c12a_exec c12a_pilverify c12a_prove c12a_verify c12b_exec c12b_pilverify c12b_prove c12b_verify g16wc g16prove g16verify", + "build:input": "node tools/build-genesis/build_genesis.js", + "build:input-recursive": "node tools/build-genesis-recursive/build_genesis_recursive.js", + "buildall": "tools/build_all.sh ${npm_package_config_steps}", + "buildsetup": "tools/build_all.sh ${npm_package_config_steps_setup}", + "buildproof": "tools/build_all.sh ${npm_package_config_steps_proof}", "buildrom": ". ./pre.sh && (cd node_modules/@0xpolygonhermez/zkevm-rom && npm run build -- -s 23) && cp node_modules/@0xpolygonhermez/zkevm-rom/build/rom.json $BDIR/rom.json", "buildconstants": ". ./pre.sh && node $NODE src/main_buildconstants $PIL -r $BDIR/rom.json -o $BDIR/zkevm.const", - "exec": ". ./pre.sh && INPUT=${npm_config_input:=tools/build-genesis/input_executor.json} && echo \"input: $INPUT\" && node $NODE src/main_executor $INPUT $PIL -r $BDIR/rom.json -o $BDIR/zkevm.commit && cp $INPUT $BDIR/input_executor.json", - "pilverify": ". ./pre.sh && $PILCOM/main_pilverifier.js $BDIR/zkevm.commit -c $BDIR/zkevm.const $PIL", + "exec": ". ./pre.sh && INPUT=${npm_config_input:=tools/build-genesis/input_executor.json} && echo \"input: $INPUT\" && node $NODE src/main_executor $INPUT $PIL -r $BDIR/rom.json -o $BDIR/zkevm$NTH.commit && cp $INPUT $BDIR/input_executor.json", + "pilverify": ". ./pre.sh && $PILCOM/main_pilverifier.js $BDIR/zkevm$NTH.commit -c $BDIR/zkevm.const $PIL", "buildstarkinfo": ". ./pre.sh && $PILSTARK/main_genstarkinfo.js $PIL -s $BDIR/zkevm.starkstruct.json -i $BDIR/zkevm.starkinfo.json", "buildchelpers": ". ./pre.sh && $PILSTARK/main_buildchelpers.js -m $PIL -s $BDIR/zkevm.starkstruct.json -c $BDIR/zkevm.chelpers/zkevm.chelpers.cpp", "buildconstanttree": ". ./pre.sh && $BCTREE -c $BDIR/zkevm.const $PIL -s $BDIR/zkevm.starkstruct.json -t $BDIR/zkevm.consttree -v $BDIR/zkevm.verkey.json", - "prove": ". ./pre.sh && $PILSTARK/main_prover.js -m $BDIR/zkevm.commit -c $BDIR/zkevm.const -t $BDIR/zkevm.consttree $PIL -s $BDIR/zkevm.starkstruct.json -o $BDIR/zkevm.proof.json -z $BDIR/zkevm.zkin.proof.json -b $BDIR/zkevm.public.json", - "verify": ". ./pre.sh && $PILSTARK/main_verifier.js $PIL -s $BDIR/zkevm.starkstruct.json -o $BDIR/zkevm.proof.json -b $BDIR/zkevm.public.json -v $BDIR/zkevm.verkey.json", + "prove": ". ./pre.sh && $PILSTARK/main_prover.js -m $BDIR/zkevm$NTH.commit -c $BDIR/zkevm.const -t $BDIR/zkevm.consttree $PIL -s $BDIR/zkevm.starkstruct.json -o $BDIR/zkevm$NTH.proof.json -z $BDIR/zkevm$NTH.zkin.proof.json -b $BDIR/zkevm$NTH.public.json", + "verify": ". ./pre.sh && $PILSTARK/main_verifier.js $PIL -s $BDIR/zkevm.starkstruct.json -o $BDIR/zkevm$NTH.proof.json -b $BDIR/zkevm$NTH.public.json -v $BDIR/zkevm.verkey.json", "gencircom": ". ./pre.sh && $PILSTARK/main_pil2circom.js $PIL -s $BDIR/zkevm.starkstruct.json -v $BDIR/zkevm.verkey.json -o $BDIR/zkevm.verifier.circom", "compilecircom": ". ./pre.sh && circom --O1 --prime goldilocks --r1cs --sym --wasm --c --verbose $BDIR/zkevm.verifier.circom -o $BDIR -l node_modules/pil-stark/circuits.gl", "c12a_setup": ". ./pre.sh && $PILSTARK/compressor12/main_compressor12_setup.js -r $BDIR/zkevm.verifier.r1cs -p $BDIR/zkevm.c12a.pil -c $BDIR/zkevm.c12a.const -e $BDIR/zkevm.c12a.exec", "c12a_buildstarkinfo": ". ./pre.sh && $PILSTARK/main_genstarkinfo.js -p $BDIR/zkevm.c12a.pil -s $BDIR/zkevm.c12a.starkstruct.json -i $BDIR/zkevm.c12a.starkinfo.json", - "c12a_buildchelpers": ". ./pre.sh && $PILSTARK/main_buildchelpers.js -m -p $BDIR/zkevm.c12a.pil -s $BDIR/zkevm.c12a.starkstruct.json -c $BDIR/zkevm.c12a.chelpers/zkevm.c12a.chelpers.cpp", + "c12a_buildchelpers": ". ./pre.sh && $PILSTARK/main_buildchelpers.js -m -p $BDIR/zkevm.c12a.pil -s $BDIR/zkevm.c12a.starkstruct.json -c $BDIR/zkevm.c12a.chelpers/zkevm.c12a.chelpers.cpp -C StarkC12a", "c12a_exec": ". ./pre.sh && $PILSTARK/compressor12/main_compressor12_exec.js -i $BDIR/zkevm.zkin.proof.json -w $BDIR/zkevm.verifier_js/zkevm.verifier.wasm -p $BDIR/zkevm.c12a.pil -e $BDIR/zkevm.c12a.exec -m $BDIR/zkevm.c12a.commit", "c12a_pilverify": ". ./pre.sh && $PILCOM/main_pilverifier.js $BDIR/zkevm.c12a.commit -c $BDIR/zkevm.c12a.const -p $BDIR/zkevm.c12a.pil", "c12a_buildconstanttree": ". ./pre.sh && $BCTREE -c $BDIR/zkevm.c12a.const -p $BDIR/zkevm.c12a.pil -s $BDIR/zkevm.c12a.starkstruct.json -t $BDIR/zkevm.c12a.consttree -v $BDIR/zkevm.c12a.verkey.json", "c12a_prove": ". ./pre.sh && $PILSTARK/main_prover.js -m $BDIR/zkevm.c12a.commit -c $BDIR/zkevm.c12a.const -t $BDIR/zkevm.c12a.consttree -p $BDIR/zkevm.c12a.pil -s $BDIR/zkevm.c12a.starkstruct.json -o $BDIR/zkevm.c12a.proof.json -z $BDIR/zkevm.c12a.zkin.proof.json -b $BDIR/zkevm.c12a.public.json", "c12a_verify": ". ./pre.sh && $PILSTARK/main_verifier.js -p $BDIR/zkevm.c12a.pil -s $BDIR/zkevm.c12a.starkstruct.json -o $BDIR/zkevm.c12a.proof.json -b $BDIR/zkevm.c12a.public.json -v $BDIR/zkevm.c12a.verkey.json", - "c12a_gencircom": ". ./pre.sh && $PILSTARK/main_pil2circom.js -p $BDIR/zkevm.c12a.pil -s $BDIR/zkevm.c12a.starkstruct.json -v $BDIR/zkevm.c12a.verkey.json -o $BDIR/zkevm.c12a.verifier.circom", - "c12a_compilecircom": ". ./pre.sh && circom --r1cs --sym --wasm --c --verbose --O1 --prime goldilocks $BDIR/zkevm.c12a.verifier.circom -o $BDIR -l node_modules/pil-stark/circuits.gl", - "c12b_setup": ". ./pre.sh && $PILSTARK/compressor12/main_compressor12_setup.js -r $BDIR/zkevm.c12a.verifier.r1cs -p $BDIR/zkevm.c12b.pil -c $BDIR/zkevm.c12b.const -e $BDIR/zkevm.c12b.exec", - "c12b_buildstarkinfo": ". ./pre.sh && $PILSTARK/main_genstarkinfo.js -p $BDIR/zkevm.c12b.pil -s $BDIR/zkevm.c12b.starkstruct.json -i $BDIR/zkevm.c12b.starkinfo.json", - "c12b_buildchelpers": ". ./pre.sh && $PILSTARK/main_buildchelpers.js -m -p $BDIR/zkevm.c12b.pil -s $BDIR/zkevm.c12b.starkstruct.json -c $BDIR/zkevm.c12b.chelpers/zkevm.c12b.chelpers.cpp", - "c12b_exec": ". ./pre.sh && $PILSTARK/compressor12/main_compressor12_exec.js -i $BDIR/zkevm.c12a.zkin.proof.json -w $BDIR/zkevm.c12a.verifier_js/zkevm.c12a.verifier.wasm -p $BDIR/zkevm.c12b.pil -e $BDIR/zkevm.c12b.exec -m $BDIR/zkevm.c12b.commit", - "c12b_pilverify": ". ./pre.sh && $PILCOM/main_pilverifier.js $BDIR/zkevm.c12b.commit -c $BDIR/zkevm.c12b.const -p $BDIR/zkevm.c12b.pil", - "c12b_buildconstanttree": ". ./pre.sh && $BCTREE -c $BDIR/zkevm.c12b.const -p $BDIR/zkevm.c12b.pil -s $BDIR/zkevm.c12b.starkstruct.json -t $BDIR/zkevm.c12b.consttree -v $BDIR/zkevm.c12b.verkey.json", - "c12b_prove": ". ./pre.sh && $PILSTARK/main_prover.js -m $BDIR/zkevm.c12b.commit -c $BDIR/zkevm.c12b.const -t $BDIR/zkevm.c12b.consttree -p $BDIR/zkevm.c12b.pil -s $BDIR/zkevm.c12b.starkstruct.json -o $BDIR/zkevm.c12b.proof.json -z $BDIR/zkevm.c12b.zkin.proof.json -b $BDIR/zkevm.c12b.public.json --proverAddr=0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", - "c12b_verify": ". ./pre.sh && $PILSTARK/main_verifier.js -p $BDIR/zkevm.c12b.pil -s $BDIR/zkevm.c12b.starkstruct.json -o $BDIR/zkevm.c12b.proof.json -b $BDIR/zkevm.c12b.public.json -v $BDIR/zkevm.c12b.verkey.json", - "c12b_gencircom": ". ./pre.sh && $PILSTARK/main_pil2circom.js -p $BDIR/zkevm.c12b.pil -s $BDIR/zkevm.c12b.starkstruct.json -v $BDIR/zkevm.c12b.verkey.json -o $BDIR/zkevm.c12b.verifier.circom", - "c12b_compilecircom": ". ./pre.sh && circom --r1cs --sym --wasm --c --verbose $BDIR/zkevm.c12b.verifier.circom -o $BDIR -l node_modules/pil-stark/circuits.bn128 -l node_modules/circomlib/circuits -l node_modules/pil-stark/circuits.gl", + "c12a_gencircom": ". ./pre.sh && $PILSTARK/main_pil2circom.js --skipMain -p $BDIR/zkevm.c12a.pil -s $BDIR/zkevm.c12a.starkstruct.json -v $BDIR/zkevm.c12a.verkey.json -o $BDIR/zkevm.c12a.verifier.circom", + "sandbox": ". ./pre.sh && echo \"$BDIR\" && diff /tmp/A1 /tmp/A2 || (echo \"FAIL\"; exit 1)", + "recursive1_gencircom": ". ./pre.sh && cp recursive/recursive1.circom $BDIR", + "recursive1_compile": ". ./pre.sh && circom --r1cs --sym --wasm --c --verbose --O1 --prime goldilocks $BDIR/recursive1.circom -o $BDIR -l node_modules/pil-stark/circuits.gl", + "recursive1_setup": ". ./pre.sh && $PILSTARK/compressor12/main_compressor12_setup.js --forceNBits=23 -r $BDIR/recursive1.r1cs -p $BDIR/recursive1.pil -c $BDIR/recursive1.const -e $BDIR/recursive1.exec", + "recursive1_buildstarkinfo": ". ./pre.sh && $PILSTARK/main_genstarkinfo.js -p $BDIR/recursive1.pil -s $BDIR/recursive.starkstruct.json -i $BDIR/recursive1.starkinfo.json", + "recursive1_buildchelpers": ". ./pre.sh && $PILSTARK/main_buildchelpers.js -m -p $BDIR/recursive1.pil -s $BDIR/recursive.starkstruct.json -c $BDIR/recursive1.chelpers/recursive1.chelpers.cpp -C StarkRecursive1", + "recursive1_buildconstanttree": ". ./pre.sh && $BCTREE -c $BDIR/recursive1.const -p $BDIR/recursive1.pil -s $BDIR/recursive.starkstruct.json -t $BDIR/recursive1.consttree -v $BDIR/recursive1.verkey.json", + "recursive1_verifier_gencircom": ". ./pre.sh && $PILSTARK/main_pil2circom.js --skipMain --verkeyInput -p $BDIR/recursive1.pil -s $BDIR/recursive.starkstruct.json -v $BDIR/recursive1.verkey.json -o $BDIR/recursive1.verifier.circom", + "recursive2_gencircom": ". ./pre.sh && node $NODE src/main_genrecursive.js -v $BDIR/recursive1.verkey.json -o $BDIR/recursive2.circom", + "recursive2_compile": ". ./pre.sh && circom --inspect --r1cs --sym --wasm --c --verbose --O1 --prime goldilocks $BDIR/recursive2.circom -o $BDIR -l node_modules/pil-stark/circuits.gl", + "recursive2_setup": ". ./pre.sh && $PILSTARK/compressor12/main_compressor12_setup.js -r $BDIR/recursive2.r1cs -p $BDIR/recursive2.pil -c $BDIR/recursive2.const -e $BDIR/recursive2.exec", + "recursive2_buildstarkinfo": ". ./pre.sh && $PILSTARK/main_genstarkinfo.js -p $BDIR/recursive2.pil -s $BDIR/recursive.starkstruct.json -i $BDIR/recursive2.starkinfo.json", + "recursive2_buildchelpers": ". ./pre.sh && $PILSTARK/main_buildchelpers.js -m -p $BDIR/recursive2.pil -s $BDIR/recursive.starkstruct.json -c $BDIR/recursive2.chelpers/recursive2.chelpers.cpp -C StarkRecursive2", + "recursive2_buildconstanttree": ". ./pre.sh && $BCTREE -c $BDIR/recursive2.const -p $BDIR/recursive2.pil -s $BDIR/recursive.starkstruct.json -t $BDIR/recursive2.consttree -v $BDIR/recursive2.verkey.json", + "recursive2_verifier_gencircom": ". ./pre.sh && $PILSTARK/main_pil2circom.js --skipMain --verkeyInput -p $BDIR/recursive2.pil -s $BDIR/recursive.starkstruct.json -v $BDIR/recursive2.verkey.json -o $BDIR/recursive2.verifier.circom", + "recursive_pil_check": ". ./pre.sh && F1=$BDIR/recursive1.pil && F2=$BDIR/recursive2.pil && diff $F1 $F2 || (echo \"ERROR: $F1 $F2 are different\"; exit 1)", + "recursive_verifier_check": ". ./pre.sh && F1=$BDIR/recursive1.verifier.circom && F2=$BDIR/recursive2.verifier.circom && diff $F1 $F2 || (echo \"ERROR: $F1 $F2 are different\"; exit 1)", + "recursivef_gencircom": ". ./pre.sh && node $NODE src/main_genrecursivef.js --verkey1 $BDIR/recursive1.verkey.json --verkey2 $BDIR/recursive2.verkey.json -o $BDIR/recursivef.circom", + "recursivef_compile": ". ./pre.sh && circom --r1cs --sym --wasm --c --verbose --O1 --prime goldilocks $BDIR/recursivef.circom -o $BDIR -l node_modules/pil-stark/circuits.gl -l node_modules/circomlib/circuits", + "recursivef_setup": ". ./pre.sh && $PILSTARK/compressor12/main_compressor12_setup.js -r $BDIR/recursivef.r1cs -p $BDIR/recursivef.pil -c $BDIR/recursivef.const -e $BDIR/recursivef.exec", + "recursivef_buildstarkinfo": ". ./pre.sh && $PILSTARK/main_genstarkinfo.js -p $BDIR/recursivef.pil -s $BDIR/recursivef.starkstruct.json -i $BDIR/recursivef.starkinfo.json", + "recursivef_buildchelpers": ". ./pre.sh && $PILSTARK/main_buildchelpers.js -m -p $BDIR/recursivef.pil -s $BDIR/recursivef.starkstruct.json -c $BDIR/recursivef.chelpers/recursivef.chelpers.cpp -C StarkRecursiveF", + "recursivef_buildconstanttree": ". ./pre.sh && $BCTREE -c $BDIR/recursivef.const -p $BDIR/recursivef.pil -s $BDIR/recursivef.starkstruct.json -t $BDIR/recursivef.consttree -v $BDIR/recursivef.verkey.json", + "recursivef_verifier_gencircom": ". ./pre.sh && $PILSTARK/main_pil2circom.js --skipMain -p $BDIR/recursivef.pil -s $BDIR/recursivef.starkstruct.json -v $BDIR/recursivef.verkey.json -o $BDIR/recursivef.verifier.circom", + "final_gencircom": ". ./pre.sh && cp recursive/final.circom $BDIR", + "final_compile": ". ./pre.sh && circom --r1cs --sym --wasm --c --verbose $BDIR/final.circom -o $BDIR -l node_modules/pil-stark/circuits.bn128 -l node_modules/circomlib/circuits", "downloadptaw": "wget -P build https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final.ptau", - "g16setup": ". ./pre.sh && $SNARKJS g16s $BDIR/zkevm.c12b.verifier.r1cs build/powersOfTau28_hez_final.ptau $BDIR/zkevm.g16.0000.zkey", - "g16contribute": ". ./pre.sh && $SNARKJS zkc $BDIR/zkevm.g16.0000.zkey $BDIR/zkevm.g16.0001.zkey -e=\"$(dd if=/dev/random bs=64 count=1 | base64 -w0)\"", - "g16evk": ". ./pre.sh && $SNARKJS zkev $BDIR/zkevm.g16.0001.zkey $BDIR/zkevm.g16.verkey.json", - "g16wc": ". ./pre.sh && node $NODE $BDIR/zkevm.c12b.verifier_js/generate_witness $BDIR/zkevm.c12b.verifier_js/zkevm.c12b.verifier.wasm $BDIR/zkevm.c12b.zkin.proof.json $BDIR/zkevm.g16.witness.wtns", - "g16prove": ". ./pre.sh && $SNARKJS g16p $BDIR/zkevm.g16.0001.zkey $BDIR/zkevm.g16.witness.wtns $BDIR/zkevm.g16.proof.json $BDIR/zkevm.g16.public.json", - "g16verify": ". ./pre.sh && $SNARKJS g16v $BDIR/zkevm.g16.verkey.json $BDIR/zkevm.g16.public.json $BDIR/zkevm.g16.proof.json", - "g16solidity": ". ./pre.sh && $SNARKJS zkesv $BDIR/zkevm.g16.0001.zkey $BDIR/zkevm.g16.verifier.sol", + "g16setup": ". ./pre.sh && $SNARKJS g16s $BDIR/final.r1cs build/powersOfTau28_hez_final.ptau $BDIR/final.g16.0000.zkey --verbose", + "g16contribute": ". ./pre.sh && $SNARKJS zkc $BDIR/final.g16.0000.zkey $BDIR/final.g16.0001.zkey --verbose -e=\"$(dd if=/dev/random bs=64 count=1 | base64 -w0)\"", + "g16evk": ". ./pre.sh && $SNARKJS zkev $BDIR/final.g16.0001.zkey $BDIR/final.g16.verkey.json", + "g16solidity": ". ./pre.sh && $SNARKJS zkesv $BDIR/final.g16.0001.zkey $BDIR/final.g16.verifier.sol", "preg16setup": ". ./pre.sh && [ -f build/powersOfTau28_hez_final.ptau ] || npm run downloadptaw", "prebuildstarkinfo": ". ./pre.sh && if [ \"$npm_config_starkstruct\" = \"debug\" ]; then node tools/gen_debug_starkstruct.js -t GL $PIL -s $BDIR/zkevm.starkstruct.json; else cp src/zkevm.starkstruct.json $BDIR; fi", "prec12a_buildstarkinfo": ". ./pre.sh && if [ \"$npm_config_starkstruct\" = \"debug\" ]; then node tools/gen_debug_starkstruct.js -t GL -p $BDIR/zkevm.c12a.pil -s $BDIR/zkevm.c12a.starkstruct.json; else cp src/zkevm.c12a.starkstruct.json $BDIR; fi", - "prec12b_buildstarkinfo": ". ./pre.sh && if [ \"$npm_config_starkstruct\" = \"debug\" ]; then node tools/gen_debug_starkstruct.js -t BN128 -p $BDIR/zkevm.c12b.pil -s $BDIR/zkevm.c12b.starkstruct.json; else cp src/zkevm.c12b.starkstruct.json $BDIR; fi", "buildarith": "node tools/arith/parse tools/arith/arith.ejs.pil -o pil/arith.pil && node tools/arith/arith_eq_gen tools/arith/arith.ejs.pil -o src/sm/sm_arith/sm_arith_##.js", + "prerecursive1_buildconstanttree": ". ./pre.sh && if [ \"$npm_config_starkstruct\" = \"debug\" ]; then node tools/gen_debug_starkstruct.js -t GL -p $BDIR/recursive1.pil -s $BDIR/recursive.starkstruct.json; else cp src/recursive.starkstruct.json $BDIR; fi", + "prerecursivef_buildconstanttree": ". ./pre.sh && if [ \"$npm_config_starkstruct\" = \"debug\" ]; then node tools/gen_debug_starkstruct.js -t BN128 -p $BDIR/recursivef.pil -s $BDIR/recursivef.starkstruct.json; else cp src/recursivef.starkstruct.json $BDIR; fi", "buildsetup:basic": "npm run buildsetup --pil=pil/basic_main.pil --build=build/basic_proof --starkstruct=debug", "buildall:basic": "npm run buildall --pil=pil/basic_main.pil --build=build/basic_proof --starkstruct=debug", "buildproof:basic": "npm run buildproof --pil=pil/basic_main.pil --build=build/basic_proof --starkstruct=debug", + "help": "npm_config_help=true && . ./pre.sh", "test": "mocha", "test:storage": "mocha test/sm_storage_test.js", "test:mem_align": "mocha test/sm_mem_align_test.js", @@ -74,16 +112,17 @@ "license": "UNLICENSED", "dependencies": { "@0xpolygonhermez/zkasmcom": "https://github.com/0xPolygonHermez/zkasmcom.git#v0.4.0.0", - "@0xpolygonhermez/zkevm-commonjs": "https://github.com/0xpolygonhermez/zkevm-commonjs.git#v0.4.0.1", - "@0xpolygonhermez/zkevm-rom": "https://github.com/0xpolygonhermez/zkevm-rom.git#v0.4.0.0", + "@0xpolygonhermez/zkevm-commonjs": "https://github.com/0xpolygonhermez/zkevm-commonjs.git#develop", + "@0xpolygonhermez/zkevm-rom": "https://github.com/0xpolygonhermez/zkevm-rom.git#develop", "chalk": "^3.0.0", "circomlib": "^2.0.3", - "circomlibjs": "0.1.1", + "circomlibjs": "^0.1.1", "ejs": "^3.1.6", "ethers": "^5.4.7", "ffjavascript": "^0.2.55", "fs": "^0.0.1-security", - "pil-stark": "0.0.25", + "json-bigint": "^1.0.0", + "pil-stark": "0.0.34", "pilcom": "0.0.18", "snarkjs": "0.4.27", "yargs": "^17.4.0" diff --git a/pil/basic_main.pil b/pil/basic_main.pil index 379c1760..1ae8d375 100644 --- a/pil/basic_main.pil +++ b/pil/basic_main.pil @@ -275,8 +275,6 @@ namespace Main(%N); zkPC' = doJMP * (addr - (zkPC+1)) + (zkPC+1) ; - - (A0-op0)*assert = 0; (A1-op1)*assert = 0; (A2-op2)*assert = 0; @@ -286,23 +284,99 @@ namespace Main(%N); (A6-op6)*assert = 0; (A7-op7)*assert = 0; - public globalHash0 = FREE0(0); - public globalHash1 = FREE1(0); - public globalHash2 = FREE2(0); - public globalHash3 = FREE3(0); - public globalHash4 = FREE4(0); - public globalHash5 = FREE5(0); - public globalHash6 = FREE6(0); - public globalHash7 = FREE7(0); - - Global.L1 * (FREE0 - :globalHash0) = 0; - Global.L1 * (FREE1 - :globalHash1) = 0; - Global.L1 * (FREE2 - :globalHash2) = 0; - Global.L1 * (FREE3 - :globalHash3) = 0; - Global.L1 * (FREE4 - :globalHash4) = 0; - Global.L1 * (FREE5 - :globalHash5) = 0; - Global.L1 * (FREE6 - :globalHash6) = 0; - Global.L1 * (FREE7 - :globalHash7) = 0; + public oldStateRoot0 = B0(0); + public oldStateRoot1 = B1(0); + public oldStateRoot2 = B2(0); + public oldStateRoot3 = B3(0); + public oldStateRoot4 = B4(0); + public oldStateRoot5 = B5(0); + public oldStateRoot6 = B6(0); + public oldStateRoot7 = B7(0); + Global.L1 * (B0 - :oldStateRoot0) = 0; + Global.L1 * (B1 - :oldStateRoot1) = 0; + Global.L1 * (B2 - :oldStateRoot2) = 0; + Global.L1 * (B3 - :oldStateRoot3) = 0; + Global.L1 * (B4 - :oldStateRoot4) = 0; + Global.L1 * (B5 - :oldStateRoot5) = 0; + Global.L1 * (B6 - :oldStateRoot6) = 0; + Global.L1 * (B7 - :oldStateRoot7) = 0; + + public oldAccInputHash0 = C0(0); + public oldAccInputHash1 = C1(0); + public oldAccInputHash2 = C2(0); + public oldAccInputHash3 = C3(0); + public oldAccInputHash4 = C4(0); + public oldAccInputHash5 = C5(0); + public oldAccInputHash6 = C6(0); + public oldAccInputHash7 = C7(0); + Global.L1 * (C0 - :oldAccInputHash0) = 0; + Global.L1 * (C1 - :oldAccInputHash1) = 0; + Global.L1 * (C2 - :oldAccInputHash2) = 0; + Global.L1 * (C3 - :oldAccInputHash3) = 0; + Global.L1 * (C4 - :oldAccInputHash4) = 0; + Global.L1 * (C5 - :oldAccInputHash5) = 0; + Global.L1 * (C6 - :oldAccInputHash6) = 0; + Global.L1 * (C7 - :oldAccInputHash7) = 0; + + public oldBatchNum = SP(0); + Global.L1 * (SP - :oldBatchNum) = 0; + + public chainId = GAS(0); + Global.L1 * (GAS - :chainId) = 0; + + public newStateRoot0 = SR0(%N-1); + public newStateRoot1 = SR1(%N-1); + public newStateRoot2 = SR2(%N-1); + public newStateRoot3 = SR3(%N-1); + public newStateRoot4 = SR4(%N-1); + public newStateRoot5 = SR5(%N-1); + public newStateRoot6 = SR6(%N-1); + public newStateRoot7 = SR7(%N-1); + Global.LLAST * (SR0 - :newStateRoot0) = 0; + Global.LLAST * (SR1 - :newStateRoot1) = 0; + Global.LLAST * (SR2 - :newStateRoot2) = 0; + Global.LLAST * (SR3 - :newStateRoot3) = 0; + Global.LLAST * (SR4 - :newStateRoot4) = 0; + Global.LLAST * (SR5 - :newStateRoot5) = 0; + Global.LLAST * (SR6 - :newStateRoot6) = 0; + Global.LLAST * (SR7 - :newStateRoot7) = 0; + + public newAccInputHash0 = D0(%N -1); + public newAccInputHash1 = D1(%N -1); + public newAccInputHash2 = D2(%N -1); + public newAccInputHash3 = D3(%N -1); + public newAccInputHash4 = D4(%N -1); + public newAccInputHash5 = D5(%N -1); + public newAccInputHash6 = D6(%N -1); + public newAccInputHash7 = D7(%N -1); + Global.LLAST * (D0 - :newAccInputHash0) = 0; + Global.LLAST * (D1 - :newAccInputHash1) = 0; + Global.LLAST * (D2 - :newAccInputHash2) = 0; + Global.LLAST * (D3 - :newAccInputHash3) = 0; + Global.LLAST * (D4 - :newAccInputHash4) = 0; + Global.LLAST * (D5 - :newAccInputHash5) = 0; + Global.LLAST * (D6 - :newAccInputHash6) = 0; + Global.LLAST * (D7 - :newAccInputHash7) = 0; + + public localExitRoot0 = E0(%N-1); + public localExitRoot1 = E1(%N-1); + public localExitRoot2 = E2(%N-1); + public localExitRoot3 = E3(%N-1); + public localExitRoot4 = E4(%N-1); + public localExitRoot5 = E5(%N-1); + public localExitRoot6 = E6(%N-1); + public localExitRoot7 = E7(%N-1); + Global.LLAST * (E0 - :localExitRoot0) = 0; + Global.LLAST * (E1 - :localExitRoot1) = 0; + Global.LLAST * (E2 - :localExitRoot2) = 0; + Global.LLAST * (E3 - :localExitRoot3) = 0; + Global.LLAST * (E4 - :localExitRoot4) = 0; + Global.LLAST * (E5 - :localExitRoot5) = 0; + Global.LLAST * (E6 - :localExitRoot6) = 0; + Global.LLAST * (E7 - :localExitRoot7) = 0; + + public newBatchNum = PC(%N-1); + Global.LLAST * (PC - :newBatchNum) = 0; pol commit sKeyI[4]; pol commit sKey[4]; diff --git a/pil/global.pil b/pil/global.pil index f3f25da5..963b0d34 100644 --- a/pil/global.pil +++ b/pil/global.pil @@ -1,4 +1,5 @@ namespace Global(%N); pol constant L1; // 1, 0, 0, 0, 0, + pol constant LLAST; // 0,0,0,0,0, ...., 0, 1 pol constant BYTE; pol constant BYTE2; diff --git a/pil/main.pil b/pil/main.pil index 53d5c05f..a187735a 100644 --- a/pil/main.pil +++ b/pil/main.pil @@ -308,23 +308,101 @@ namespace Main(%N); (A6-op6)*assert = 0; (A7-op7)*assert = 0; - public globalHash0 = FREE0(0); - public globalHash1 = FREE1(0); - public globalHash2 = FREE2(0); - public globalHash3 = FREE3(0); - public globalHash4 = FREE4(0); - public globalHash5 = FREE5(0); - public globalHash6 = FREE6(0); - public globalHash7 = FREE7(0); - - Global.L1 * (FREE0 - :globalHash0) = 0; - Global.L1 * (FREE1 - :globalHash1) = 0; - Global.L1 * (FREE2 - :globalHash2) = 0; - Global.L1 * (FREE3 - :globalHash3) = 0; - Global.L1 * (FREE4 - :globalHash4) = 0; - Global.L1 * (FREE5 - :globalHash5) = 0; - Global.L1 * (FREE6 - :globalHash6) = 0; - Global.L1 * (FREE7 - :globalHash7) = 0; + public oldStateRoot0 = B0(0); + public oldStateRoot1 = B1(0); + public oldStateRoot2 = B2(0); + public oldStateRoot3 = B3(0); + public oldStateRoot4 = B4(0); + public oldStateRoot5 = B5(0); + public oldStateRoot6 = B6(0); + public oldStateRoot7 = B7(0); + Global.L1 * (B0 - :oldStateRoot0) = 0; + Global.L1 * (B1 - :oldStateRoot1) = 0; + Global.L1 * (B2 - :oldStateRoot2) = 0; + Global.L1 * (B3 - :oldStateRoot3) = 0; + Global.L1 * (B4 - :oldStateRoot4) = 0; + Global.L1 * (B5 - :oldStateRoot5) = 0; + Global.L1 * (B6 - :oldStateRoot6) = 0; + Global.L1 * (B7 - :oldStateRoot7) = 0; + + public oldAccInputHash0 = C0(0); + public oldAccInputHash1 = C1(0); + public oldAccInputHash2 = C2(0); + public oldAccInputHash3 = C3(0); + public oldAccInputHash4 = C4(0); + public oldAccInputHash5 = C5(0); + public oldAccInputHash6 = C6(0); + public oldAccInputHash7 = C7(0); + Global.L1 * (C0 - :oldAccInputHash0) = 0; + Global.L1 * (C1 - :oldAccInputHash1) = 0; + Global.L1 * (C2 - :oldAccInputHash2) = 0; + Global.L1 * (C3 - :oldAccInputHash3) = 0; + Global.L1 * (C4 - :oldAccInputHash4) = 0; + Global.L1 * (C5 - :oldAccInputHash5) = 0; + Global.L1 * (C6 - :oldAccInputHash6) = 0; + Global.L1 * (C7 - :oldAccInputHash7) = 0; + + public oldBatchNum = SP(0); + Global.L1 * (SP - :oldBatchNum) = 0; + + public chainId = GAS(0); + Global.L1 * (GAS - :chainId) = 0; + + public newStateRoot0 = SR0(%N-1); + public newStateRoot1 = SR1(%N-1); + public newStateRoot2 = SR2(%N-1); + public newStateRoot3 = SR3(%N-1); + public newStateRoot4 = SR4(%N-1); + public newStateRoot5 = SR5(%N-1); + public newStateRoot6 = SR6(%N-1); + public newStateRoot7 = SR7(%N-1); + Global.LLAST * (SR0 - :newStateRoot0) = 0; + Global.LLAST * (SR1 - :newStateRoot1) = 0; + Global.LLAST * (SR2 - :newStateRoot2) = 0; + Global.LLAST * (SR3 - :newStateRoot3) = 0; + Global.LLAST * (SR4 - :newStateRoot4) = 0; + Global.LLAST * (SR5 - :newStateRoot5) = 0; + Global.LLAST * (SR6 - :newStateRoot6) = 0; + Global.LLAST * (SR7 - :newStateRoot7) = 0; + + public newAccInputHash0 = D0(%N -1); + public newAccInputHash1 = D1(%N -1); + public newAccInputHash2 = D2(%N -1); + public newAccInputHash3 = D3(%N -1); + public newAccInputHash4 = D4(%N -1); + public newAccInputHash5 = D5(%N -1); + public newAccInputHash6 = D6(%N -1); + public newAccInputHash7 = D7(%N -1); + Global.LLAST * (D0 - :newAccInputHash0) = 0; + Global.LLAST * (D1 - :newAccInputHash1) = 0; + Global.LLAST * (D2 - :newAccInputHash2) = 0; + Global.LLAST * (D3 - :newAccInputHash3) = 0; + Global.LLAST * (D4 - :newAccInputHash4) = 0; + Global.LLAST * (D5 - :newAccInputHash5) = 0; + Global.LLAST * (D6 - :newAccInputHash6) = 0; + Global.LLAST * (D7 - :newAccInputHash7) = 0; + + public localExitRoot0 = E0(%N-1); + public localExitRoot1 = E1(%N-1); + public localExitRoot2 = E2(%N-1); + public localExitRoot3 = E3(%N-1); + public localExitRoot4 = E4(%N-1); + public localExitRoot5 = E5(%N-1); + public localExitRoot6 = E6(%N-1); + public localExitRoot7 = E7(%N-1); + Global.LLAST * (E0 - :localExitRoot0) = 0; + Global.LLAST * (E1 - :localExitRoot1) = 0; + Global.LLAST * (E2 - :localExitRoot2) = 0; + Global.LLAST * (E3 - :localExitRoot3) = 0; + Global.LLAST * (E4 - :localExitRoot4) = 0; + Global.LLAST * (E5 - :localExitRoot5) = 0; + Global.LLAST * (E6 - :localExitRoot6) = 0; + Global.LLAST * (E7 - :localExitRoot7) = 0; + + public newBatchNum = PC(%N-1); + Global.LLAST * (PC - :newBatchNum) = 0; + + // Check that the calculated hash is well formed sWR + hashPDigest { diff --git a/pil/padding_kk.pil b/pil/padding_kk.pil index c67c3bb5..838ec3a7 100644 --- a/pil/padding_kk.pil +++ b/pil/padding_kk.pil @@ -130,7 +130,7 @@ namespace PaddingKK(%N); pol constant crValid; /* Read Data output - crLatch * crValid {addr, crOffset - crLen -1, crLen, crV0C, crV1C, crV2C, crV3C, crV4C, crV5C, crV6C, crV7C} + crLatch * crValid {addr, PaddingKK.len - PaddingKK.rem - PaddingKK.crLen + 1, crLen, crV0C, crV1C, crV2C, crV3C, crV4C, crV5C, crV6C, crV7C} */ /* Read Len output diff --git a/pre.sh b/pre.sh index 2087639f..ab7ae596 100644 --- a/pre.sh +++ b/pre.sh @@ -1,3 +1,40 @@ +checkMandatoryOptArg() { + argname=$3 + [ "$2" = "true" ] && echo "ERROR: --$1 without mandatory argument. usage: --$1=<${argname:=value}>" && exit 1 +} + +checkAllMandatoryOptArgs() { + checkMandatoryOptArg build $npm_config_build buildpath + checkMandatoryOptArg pil $npm_config_pil file.pil + checkMandatoryOptArg pilconfig $npm_config_pilconfig pilconfig.json + checkMandatoryOptArg bctree $npm_config_bctree constanttreebuilder + checkMandatoryOptArg nth $npm_config_nth + checkMandatoryOptArg starkstruct $npm_config_starkstruct debug + checkMandatoryOptArg input $npm_config_input input + checkMandatoryOptArg from $npm_config_from step + checkMandatoryOptArg to $npm_config_to step + checkMandatoryOptArg step $npm_config_step step +} + +usage() { + echo "options:" + echo " --build= folder were outputs was stored." + echo " --pil=" + echo " --pilconfig=" + echo " --bctree= alternative binary to generate constanttree (ex: ../zkevm-prover/build/bctree)" + echo " --nth= suffix used on commited files and derivated (ex: _0)" + echo " --starkstruct=debug auto-generate starkstruct, used in non-stardard pil as basic." + echo " --input= input used in execution/proof." + echo " --from= where start the process (ex: buildconstanttree)" + echo " --to= where fiuish the process (ex: pilverify)" + echo " --step= execute only one step of proccess (ex: exec)" + echo " --continue restart process from last step wellprocessed" +} + +checkAllMandatoryOptArgs + +[ ! -z $npm_config_help ] && usage && exit 1 + BDIR="${npm_config_build:=build/proof}" mkdir -p $BDIR # NODE="--trace-gc --trace-gc-ignore-scavenger --max-semi-space-size=1024 --max-old-space-size=524288" @@ -11,4 +48,6 @@ PILSTARK="node $NODE node_modules/pil-stark/src" PILCOM="node $NODE node_modules/pilcom/src" SNARKJS="node $NODE node_modules/snarkjs/cli.js" BCTREE="${npm_config_bctree:=$PILSTARK/main_buildconsttree.js}" +# [ ! -z $npm_config_nth ] && +NTH="${npm_config_nth}" true \ No newline at end of file diff --git a/recursive/final.circom b/recursive/final.circom new file mode 100644 index 00000000..5edcd1ed --- /dev/null +++ b/recursive/final.circom @@ -0,0 +1,185 @@ +pragma circom 2.1.0; + +/* +aggregatorAddr -> 160 -> 160 +oldStateRoot -> 256 -> 416 +oldAccInputHash -> 256 -> 672 +oldBathcNum -> 64 -> 736 +chainId -> 64 -> 800 +newStateRoot -> 256 -> 1056 +newAccInputHash -> 256 -> 1312 +newLocalExitRoot -> 256 -> 1568 +newBatchNum -> 64 -> 1632 + +Total: 1632 +*/ + +include "sha256/sha256.circom"; +include "bitify.circom"; +include "recursivef.verifier.circom"; + +template Main() { + signal output publicsHash; + + signal input aggregatorAddr; + + signal input publics[43]; + signal input root1; + signal input root2; + signal input root3; + signal input root4; + + signal input evals[82][3]; + + signal input s0_vals1[64][12]; + signal input s0_vals3[64][3]; + signal input s0_vals4[64][79]; + signal input s0_valsC[64][23]; + + signal input s0_siblings1[64][6][16]; + signal input s0_siblings3[64][6][16]; + signal input s0_siblings4[64][6][16]; + signal input s0_siblingsC[64][6][16]; + + signal input s1_root; + signal input s2_root; + signal input s3_root; + signal input s4_root; + signal input s5_root; + + signal input s1_vals[64][48]; + signal input s1_siblings[64][5][16]; + signal input s2_vals[64][48]; + signal input s2_siblings[64][4][16]; + signal input s3_vals[64][48]; + signal input s3_siblings[64][3][16]; + signal input s4_vals[64][48]; + signal input s4_siblings[64][2][16]; + signal input s5_vals[64][48]; + signal input s5_siblings[64][1][16]; + + signal input finalPol[16][3]; + + + component sv = StarkVerifier(); + sv.publics <== publics; + sv.root1 <== root1; + sv.root2 <== root2; + sv.root3 <== root3; + sv.root4 <== root4; + + sv.evals <== evals; + + sv.s0_vals1 <== s0_vals1; + sv.s0_vals3 <== s0_vals3; + sv.s0_vals4 <== s0_vals4; + sv.s0_valsC <== s0_valsC; + + sv.s0_siblings1 <== s0_siblings1; + sv.s0_siblings3 <== s0_siblings3; + sv.s0_siblings4 <== s0_siblings4; + sv.s0_siblingsC <== s0_siblingsC; + + sv.s1_root <== s1_root; + sv.s2_root <== s2_root; + sv.s3_root <== s3_root; + sv.s4_root <== s4_root; + sv.s5_root <== s5_root; + + sv.s1_vals <== s1_vals; + sv.s1_siblings <== s1_siblings; + sv.s2_vals <== s2_vals; + sv.s2_siblings <== s2_siblings; + sv.s3_vals <== s3_vals; + sv.s3_siblings <== s3_siblings; + sv.s4_vals <== s4_vals; + sv.s4_siblings <== s4_siblings; + sv.s5_vals <== s5_vals; + sv.s5_siblings <== s5_siblings; + + sv.finalPol <== finalPol; + + component publicsHasher = Sha256(1632); + + component n2bAggregatorAddr = Num2Bits(160); + n2bAggregatorAddr.in <== aggregatorAddr; + for (var i=0; i<160; i++) { + publicsHasher.in[0 + 160 - 1 -i] <== n2bAggregatorAddr.out[i]; + } + + component n2bOldStateRoot[8]; + for (var i=0; i<8; i++) { + n2bOldStateRoot[i] = Num2Bits(32); + n2bOldStateRoot[i].in <== publics[0 + i]; + for (var j=0; j<32; j++) { + publicsHasher.in[160 + 32*(i+1) - 1 -j] <== n2bOldStateRoot[i].out[j]; + } + } + + component n2bOldAccInputHash[8]; + for (var i=0; i<8; i++) { + n2bOldAccInputHash[i] = Num2Bits(32); + n2bOldAccInputHash[i].in <== publics[8 + i]; + for (var j=0; j<32; j++) { + publicsHasher.in[416 + 32*(i+1) - 1 -j] <== n2bOldAccInputHash[i].out[j]; + } + } + + // Do 63 bits to avoid aliasing + component n2bOldBatchNum = Num2Bits(63); + n2bOldBatchNum.in <== publics[16]; + for (var i=0; i<63; i++) { + publicsHasher.in[672 + 64 - 1 -i] <== n2bOldBatchNum.out[i]; + } + publicsHasher.in[672] <== 0; + + component n2bChainId = Num2Bits(63); + n2bChainId.in <== publics[17]; + for (var i=0; i<63; i++) { + publicsHasher.in[736 + 64 - 1 -i] <== n2bChainId.out[i]; + } + publicsHasher.in[736] <== 0; + + component n2bNewStateRoot[8]; + for (var i=0; i<8; i++) { + n2bNewStateRoot[i] = Num2Bits(32); + n2bNewStateRoot[i].in <== publics[18+i]; + for (var j=0; j<32; j++) { + publicsHasher.in[800 + 32*(i+1) - 1 -j] <== n2bNewStateRoot[i].out[j]; + } + } + + component n2bNewAccInputHash[8]; + for (var i=0; i<8; i++) { + n2bNewAccInputHash[i] = Num2Bits(32); + n2bNewAccInputHash[i].in <== publics[26+i]; + for (var j=0; j<32; j++) { + publicsHasher.in[1056 + 32*(i+1) - 1 -j] <== n2bNewAccInputHash[i].out[j]; + } + } + + component n2bNewLocalExitRoot[8]; + for (var i=0; i<8; i++) { + n2bNewLocalExitRoot[i] = Num2Bits(32); + n2bNewLocalExitRoot[i].in <== publics[34+i]; + for (var j=0; j<32; j++) { + publicsHasher.in[1312 + 32*(i+1) - 1 -j] <== n2bNewLocalExitRoot[i].out[j]; + } + } + + component n2bNewBatchNum = Num2Bits(63); + n2bNewBatchNum.in <== publics[42]; + for (var i=0; i<63; i++) { + publicsHasher.in[1568 + 64 - 1 -i] <== n2bNewBatchNum.out[i]; + } + publicsHasher.in[1568] <== 0; + + component b2nPublicsHash = Bits2Num(256); + for (var i = 0; i < 256; i++) { + b2nPublicsHash.in[i] <== publicsHasher.out[255-i]; + } + + publicsHash <== b2nPublicsHash.out; +} + +component main = Main(); diff --git a/recursive/recursive1.circom b/recursive/recursive1.circom new file mode 100644 index 00000000..197d7a25 --- /dev/null +++ b/recursive/recursive1.circom @@ -0,0 +1,76 @@ +pragma circom 2.1.0; +pragma custom_templates; + +include "zkevm.c12a.verifier.circom"; + +template Main() { + + signal input publics[43]; + signal input rootC[4]; + + signal input root1[4]; + signal input root2[4]; + signal input root3[4]; + signal input root4[4]; + signal input evals[82][3]; + + signal input s0_vals1[64][12]; + signal input s0_vals3[64][3]; + signal input s0_vals4[64][79]; + signal input s0_valsC[64][23]; + signal input s0_siblings1[64][26][4]; + signal input s0_siblings3[64][26][4]; + signal input s0_siblings4[64][26][4]; + signal input s0_siblingsC[64][26][4]; + + signal input s1_root[4]; + signal input s2_root[4]; + signal input s3_root[4]; + signal input s4_root[4]; + + signal input s1_vals[64][96]; + signal input s1_siblings[64][21][4]; + signal input s2_vals[64][96]; + signal input s2_siblings[64][16][4]; + signal input s3_vals[64][96]; + signal input s3_siblings[64][11][4]; + signal input s4_vals[64][96]; + signal input s4_siblings[64][6][4]; + + signal input finalPol[64][3]; + + + + component vA = StarkVerifier(); + + vA.publics <== publics; + vA.root1 <== root1; + vA.root2 <== root2; + vA.root3 <== root3; + vA.root4 <== root4; + vA.evals <== evals; + vA.s0_vals1 <== s0_vals1; + vA.s0_vals3 <== s0_vals3; + vA.s0_vals4 <== s0_vals4; + vA.s0_valsC <== s0_valsC; + vA.s0_siblings1 <== s0_siblings1; + vA.s0_siblings3 <== s0_siblings3; + vA.s0_siblings4 <== s0_siblings4; + vA.s0_siblingsC <== s0_siblingsC; + vA.s1_root <== s1_root; + vA.s2_root <== s2_root; + vA.s3_root <== s3_root; + vA.s4_root <== s4_root; + vA.s1_vals <== s1_vals; + vA.s1_siblings <== s1_siblings; + vA.s2_vals <== s2_vals; + vA.s2_siblings <== s2_siblings; + vA.s3_vals <== s3_vals; + vA.s3_siblings <== s3_siblings; + vA.s4_vals <== s4_vals; + vA.s4_siblings <== s4_siblings; + vA.finalPol <== finalPol; + +} + +component main {public [publics, rootC]}= Main(); \ No newline at end of file diff --git a/recursive/recursive2.circom.ejs b/recursive/recursive2.circom.ejs new file mode 100644 index 00000000..acff3c60 --- /dev/null +++ b/recursive/recursive2.circom.ejs @@ -0,0 +1,230 @@ +pragma circom 2.1.0; +pragma custom_templates; + +include "recursive1.verifier.circom"; +include "mux1.circom"; +include "iszero.circom"; + +template Main() { + + var rootCSingle[4]; + rootCSingle[0] = <%- constRoot[0] %>; + rootCSingle[1] = <%- constRoot[1] %>; + rootCSingle[2] = <%- constRoot[2] %>; + rootCSingle[3] = <%- constRoot[3] %>; + + signal input publics[43]; + signal input rootC[4]; + + signal input a_publics[43]; + + signal input a_root1[4]; + signal input a_root2[4]; + signal input a_root3[4]; + signal input a_root4[4]; + + signal input a_evals[82][3]; + + signal input a_s0_vals1[64][12]; + signal input a_s0_vals3[64][3]; + signal input a_s0_vals4[64][79]; + signal input a_s0_valsC[64][23]; + signal input a_s0_siblings1[64][25][4]; + signal input a_s0_siblings3[64][25][4]; + signal input a_s0_siblings4[64][25][4]; + signal input a_s0_siblingsC[64][25][4]; + + signal input a_s1_root[4]; + signal input a_s2_root[4]; + signal input a_s3_root[4]; + signal input a_s4_root[4]; + + signal input a_s1_vals[64][48]; + signal input a_s1_siblings[64][21][4]; + signal input a_s2_vals[64][96]; + signal input a_s2_siblings[64][16][4]; + signal input a_s3_vals[64][96]; + signal input a_s3_siblings[64][11][4]; + signal input a_s4_vals[64][96]; + signal input a_s4_siblings[64][6][4]; + + signal input a_finalPol[64][3]; + + + + signal input b_publics[43]; + + signal input b_root1[4]; + signal input b_root2[4]; + signal input b_root3[4]; + signal input b_root4[4]; + signal input b_evals[82][3]; + + signal input b_s0_vals1[64][12]; + signal input b_s0_vals3[64][3]; + signal input b_s0_vals4[64][79]; + signal input b_s0_valsC[64][23]; + signal input b_s0_siblings1[64][25][4]; + signal input b_s0_siblings3[64][25][4]; + signal input b_s0_siblings4[64][25][4]; + signal input b_s0_siblingsC[64][25][4]; + + signal input b_s1_root[4]; + signal input b_s2_root[4]; + signal input b_s3_root[4]; + signal input b_s4_root[4]; + + signal input b_s1_vals[64][48]; + signal input b_s1_siblings[64][21][4]; + signal input b_s2_vals[64][96]; + signal input b_s2_siblings[64][16][4]; + signal input b_s3_vals[64][96]; + signal input b_s3_siblings[64][11][4]; + signal input b_s4_vals[64][96]; + signal input b_s4_siblings[64][6][4]; + + signal input b_finalPol[64][3]; + + component vA = StarkVerifier(); + + for (var i=0; i<43; i++) { + vA.publics[i] <== a_publics[i]; + } + vA.root1 <== a_root1; + vA.root2 <== a_root2; + vA.root3 <== a_root3; + vA.root4 <== a_root4; + vA.evals <== a_evals; + vA.s0_vals1 <== a_s0_vals1; + vA.s0_vals3 <== a_s0_vals3; + vA.s0_vals4 <== a_s0_vals4; + vA.s0_valsC <== a_s0_valsC; + vA.s0_siblings1 <== a_s0_siblings1; + vA.s0_siblings3 <== a_s0_siblings3; + vA.s0_siblings4 <== a_s0_siblings4; + vA.s0_siblingsC <== a_s0_siblingsC; + vA.s1_root <== a_s1_root; + vA.s2_root <== a_s2_root; + vA.s3_root <== a_s3_root; + vA.s4_root <== a_s4_root; + vA.s1_vals <== a_s1_vals; + vA.s1_siblings <== a_s1_siblings; + vA.s2_vals <== a_s2_vals; + vA.s2_siblings <== a_s2_siblings; + vA.s3_vals <== a_s3_vals; + vA.s3_siblings <== a_s3_siblings; + vA.s4_vals <== a_s4_vals; + vA.s4_siblings <== a_s4_siblings; + vA.finalPol <== a_finalPol; + + component isOneBatchA = IsZero(); + isOneBatchA.in <== a_publics[42] - a_publics[16] - 1; + component a_muxRootC = MultiMux1(4); + a_muxRootC.c[0] <== rootC; + a_muxRootC.c[1] <== rootCSingle; + a_muxRootC.s <== isOneBatchA.out; + + for (var i=0; i<4; i++) { + vA.publics[43+i] <== rootC[i]; + } + vA.rootC <== a_muxRootC.out; + + component vB = StarkVerifier(); + + for (var i=0; i<43; i++) { + vB.publics[i] <== b_publics[i]; + } + vB.root1 <== b_root1; + vB.root2 <== b_root2; + vB.root3 <== b_root3; + vB.root4 <== b_root4; + vB.evals <== b_evals; + vB.s0_vals1 <== b_s0_vals1; + vB.s0_vals3 <== b_s0_vals3; + vB.s0_vals4 <== b_s0_vals4; + vB.s0_valsC <== b_s0_valsC; + vB.s0_siblings1 <== b_s0_siblings1; + vB.s0_siblings3 <== b_s0_siblings3; + vB.s0_siblings4 <== b_s0_siblings4; + vB.s0_siblingsC <== b_s0_siblingsC; + vB.s1_root <== b_s1_root; + vB.s2_root <== b_s2_root; + vB.s3_root <== b_s3_root; + vB.s4_root <== b_s4_root; + vB.s1_vals <== b_s1_vals; + vB.s1_siblings <== b_s1_siblings; + vB.s2_vals <== b_s2_vals; + vB.s2_siblings <== b_s2_siblings; + vB.s3_vals <== b_s3_vals; + vB.s3_siblings <== b_s3_siblings; + vB.s4_vals <== b_s4_vals; + vB.s4_siblings <== b_s4_siblings; + vB.finalPol <== b_finalPol; + + + component isOneBatchB = IsZero(); + isOneBatchB.in <== b_publics[42] - b_publics[16] - 1; + component b_muxRootC = MultiMux1(4); + b_muxRootC.c[0] <== rootC; + b_muxRootC.c[1] <== rootCSingle; + b_muxRootC.s <== isOneBatchB.out; + + for (var i=0; i<4; i++) { + vB.publics[43+i] <== rootC[i]; + } + vB.rootC <== b_muxRootC.out; + + // oldStateRoot + for (var i=0; i<8; i++) { + a_publics[i] === publics[i]; + } + + // oldAccInputHash + for (var i=8; i<16; i++) { + a_publics[i] === publics[i]; + } + + // oldBatchNum + a_publics[16] === publics[16]; + + // chainId + a_publics[17] === publics[17]; + + // midStateRoot + for (var i=0; i<8; i++) { + b_publics[i] === a_publics[18+i]; + } + + // midAccInputHash + for (var i=8; i<16; i++) { + b_publics[i] === a_publics[18+i]; + } + + // midBatchNum + b_publics[16] === a_publics[18+24]; + + // chainId + a_publics[17] === publics[17]; + + + // newStateRoot + for (var i=0; i<8; i++) { + publics[18+i] === b_publics[18+i]; + } + + // newAccInputHash + for (var i=8; i<16; i++) { + publics[18+i] === b_publics[18+i]; + } + + // localExitRoot + for (var i=16; i<24; i++) { + publics[18+i] === b_publics[18+i]; + } + + // newBatchNum + publics[18+24] === b_publics[18+24]; + +} + +component main {public [publics, rootC]}= Main(); \ No newline at end of file diff --git a/recursive/recursivef.circom.ejs b/recursive/recursivef.circom.ejs new file mode 100644 index 00000000..34378ad2 --- /dev/null +++ b/recursive/recursivef.circom.ejs @@ -0,0 +1,100 @@ +pragma circom 2.1.0; +pragma custom_templates; + +include "recursive2.verifier.circom"; +include "mux1.circom"; +include "iszero.circom"; + +template Main() { + signal input publics[43]; + + signal input root1[4]; + signal input root2[4]; + signal input root3[4]; + signal input root4[4]; + + signal input evals[82][3]; + + signal input s0_vals1[64][12]; + signal input s0_vals3[64][3]; + signal input s0_vals4[64][79]; + signal input s0_valsC[64][23]; + signal input s0_siblings1[64][25][4]; + signal input s0_siblings3[64][25][4]; + signal input s0_siblings4[64][25][4]; + signal input s0_siblingsC[64][25][4]; + + signal input s1_root[4]; + signal input s2_root[4]; + signal input s3_root[4]; + signal input s4_root[4]; + + signal input s1_vals[64][48]; + signal input s1_siblings[64][21][4]; + signal input s2_vals[64][96]; + signal input s2_siblings[64][16][4]; + signal input s3_vals[64][96]; + signal input s3_siblings[64][11][4]; + signal input s4_vals[64][96]; + signal input s4_siblings[64][6][4]; + + signal input finalPol[64][3]; + + component sv = StarkVerifier(); + + for (var i=0; i<43; i++) { + sv.publics[i] <== publics[i]; + } + sv.root1 <== root1; + sv.root2 <== root2; + sv.root3 <== root3; + sv.root4 <== root4; + sv.evals <== evals; + sv.s0_vals1 <== s0_vals1; + sv.s0_vals3 <== s0_vals3; + sv.s0_vals4 <== s0_vals4; + sv.s0_valsC <== s0_valsC; + sv.s0_siblings1 <== s0_siblings1; + sv.s0_siblings3 <== s0_siblings3; + sv.s0_siblings4 <== s0_siblings4; + sv.s0_siblingsC <== s0_siblingsC; + sv.s1_root <== s1_root; + sv.s2_root <== s2_root; + sv.s3_root <== s3_root; + sv.s4_root <== s4_root; + sv.s1_vals <== s1_vals; + sv.s1_siblings <== s1_siblings; + sv.s2_vals <== s2_vals; + sv.s2_siblings <== s2_siblings; + sv.s3_vals <== s3_vals; + sv.s3_siblings <== s3_siblings; + sv.s4_vals <== s4_vals; + sv.s4_siblings <== s4_siblings; + sv.finalPol <== finalPol; + + component isOne = IsZero(); + isOne.in <== publics[42] -publics[16] -1; + component muxKey = MultiMux1(4); + muxKey.s <== isOne.out; + muxKey.c[0][0] <== <%- constRoot2[0] %>; + muxKey.c[0][1] <== <%- constRoot2[1] %>; + muxKey.c[0][2] <== <%- constRoot2[2] %>; + muxKey.c[0][3] <== <%- constRoot2[3] %>; + muxKey.c[1][0] <== <%- constRoot1[0] %>; + muxKey.c[1][1] <== <%- constRoot1[1] %>; + muxKey.c[1][2] <== <%- constRoot1[2] %>; + muxKey.c[1][3] <== <%- constRoot1[3] %>; + + sv.publics[43] <== <%- constRoot2[0] %>; + sv.publics[44] <== <%- constRoot2[1] %>; + sv.publics[45] <== <%- constRoot2[2] %>; + sv.publics[46] <== <%- constRoot2[3] %>; + + sv.rootC[0] <== muxKey.out[0]; + sv.rootC[1] <== muxKey.out[1]; + sv.rootC[2] <== muxKey.out[2]; + sv.rootC[3] <== muxKey.out[3]; + +} + +component main {public [publics]}= Main(); \ No newline at end of file diff --git a/src/main_genrecursive.js b/src/main_genrecursive.js new file mode 100644 index 00000000..166ed087 --- /dev/null +++ b/src/main_genrecursive.js @@ -0,0 +1,42 @@ +const JSONbig = require('json-bigint')({ useNativeBigInt: true, alwaysParseAsBig: true }); +const fs = require("fs"); +const path = require("path"); +const ejs = require("ejs"); +const version = require("../package").version; + +const argv = require("yargs") + .version(version) + .usage("node main_genrecursive.js -v -o ") + .alias("v", "verkey") + .alias("o", "output") + .argv; + +async function run() { + + const verKeyFile = typeof(argv.verkey) === "string" ? argv.verkey.trim() : "mycircuit.verkey.json"; + const outputFile = typeof(argv.output) === "string" ? argv.output.trim() : "mycircuit.verifier.circom"; + + const verKey = JSONbig.parse(await fs.promises.readFile(verKeyFile, "utf8")); + const constRoot = verKey.constRoot; + + const template = await fs.promises.readFile(path.join(__dirname, "..", "recursive", "recursive2.circom.ejs"), "utf8"); + + const obj = { + constRoot: constRoot, + }; + + const verifier = ejs.render(template , obj); + + await fs.promises.writeFile(outputFile, verifier, "utf8"); + + console.log("file Generated Correctly"); + +} + +run().then(()=> { + process.exit(0); +}, (err) => { + console.log(err.message); + console.log(err.stack); + process.exit(1); +}); diff --git a/src/main_genrecursivef.js b/src/main_genrecursivef.js new file mode 100644 index 00000000..0117b99f --- /dev/null +++ b/src/main_genrecursivef.js @@ -0,0 +1,49 @@ +const JSONbig = require('json-bigint')({ useNativeBigInt: true, alwaysParseAsBig: true }); +const fs = require("fs"); +const path = require("path"); +const ejs = require("ejs"); +const version = require("../package").version; + +const argv = require("yargs") + .version(version) + .usage("node main_genrecursive.js --verkey1 --verkey2 -o ") + .alias("v1", "verkey1") + .alias("v2", "verkey2") + .alias("o", "output") + .argv; + +async function run() { + + const verKey1File = typeof(argv.verkey1) === "string" ? argv.verkey1.trim() : "recursive1.verkey.json"; + const verKey2File = typeof(argv.verkey2) === "string" ? argv.verkey2.trim() : "recursive2.verkey.json"; + const outputFile = typeof(argv.output) === "string" ? argv.output.trim() : "recursivef.circom"; + + const verKey1 = JSONbig.parse(await fs.promises.readFile(verKey1File, "utf8")); + const verKey2 = JSONbig.parse(await fs.promises.readFile(verKey2File, "utf8")); + const constRoot1 = verKey1.constRoot; + const constRoot2 = verKey2.constRoot; + + const template = await fs.promises.readFile(path.join(__dirname, "..", "recursive", "recursivef.circom.ejs"), "utf8"); + + const obj = { + constRoot1: constRoot1, + constRoot2: constRoot2, + }; + + console.log(obj) + + const verifier = ejs.render(template , obj); + + await fs.promises.writeFile(outputFile, verifier, "utf8"); + + console.log("file Generated Correctly"); + +} + +run().then(()=> { + process.exit(0); +}, (err) => { + console.log(err.message); + console.log(err.stack); + process.exit(1); +}); diff --git a/src/main_joinzkin.js b/src/main_joinzkin.js new file mode 100644 index 00000000..aea150dc --- /dev/null +++ b/src/main_joinzkin.js @@ -0,0 +1,129 @@ +const fs = require("fs"); +const path = require("path"); +const { polMulAxi } = require("pil-stark/src/polutils"); +const version = require("../package").version; +const JSONbig = require("json-bigint"); + +const argv = require("yargs") + .version(version) + .usage("node -v --zkin1 --zkin2 --zkinout ") + .argv; + +async function run() { + + const zkin1File = typeof(argv.zkin1) === "string" ? argv.zkin1.trim() : "zkin1.json"; + const zkin2File = typeof(argv.zkin2) === "string" ? argv.zkin2.trim() : "zkin2.json"; + const zkinOutFile = typeof(argv.zkinout) === "string" ? argv.zkinout : "zkinOut.json"; + const verKeyFile = typeof(argv.verkey) === "string" ? argv.verkey.trim() : "recursive2.verkey.json"; + + + const zkin1 = JSON.parse(await fs.promises.readFile(zkin1File, "utf8")); + const zkin2 = JSON.parse(await fs.promises.readFile(zkin2File, "utf8")); + const verKey = JSONbig.parse(await fs.promises.readFile(verKeyFile, "utf8")); + const constRoot = verKey.constRoot; + + + const zkinOut = {}; + + zkinOut.publics = []; + + for (let i=0; i<8; i++) zkinOut.publics[0+i] = zkin1.publics[0+i]; // oldStateRoot + + for (let i=0; i<8; i++) zkinOut.publics[8+i] = zkin1.publics[8+i]; // oldAccInputHash0 + + zkinOut.publics[16] = zkin1.publics[16]; // oldBatchNum + + zkinOut.publics[17] = zkin1.publics[17]; // chainId + + + if (zkin1.publics[17] != (zkin2.publics[17])) throw new Error("chainID doesn't match"); + // midStateRoot + for (let i=0; i<8; i++) { + if (zkin1.publics[18 + i] != (zkin2.publics[0 + i])) throw new Error("midStateRoot doesnt't match"); + } + // midAccInputHash0 + for (let i=0; i<8; i++) { + if (zkin1.publics[26 + i] != (zkin2.publics[8 + i])) throw new Error("midAccInputHash0 doesnt't match"); + } + if (zkin1.publics[42] != (zkin2.publics[16])) throw new Error("batchNum doesn't match"); + + for (let i=0; i<8; i++) zkinOut.publics[18+i] = zkin2.publics[18+i]; // newStateRoot + for (let i=0; i<8; i++) zkinOut.publics[26+i] = zkin2.publics[26+i]; // newAccInputHash0 + for (let i=0; i<8; i++) zkinOut.publics[34+i] = zkin2.publics[34+i]; // newLocalExitRoot + + zkinOut.publics[42] = zkin2.publics[42]; // oldBatchNum + + zkinOut.a_publics = zkin1.publics; + zkinOut.a_root1 = zkin1.root1; + zkinOut.a_root2 = zkin1.root2; + zkinOut.a_root3 = zkin1.root3; + zkinOut.a_root4 = zkin1.root4; + zkinOut.a_evals = zkin1.evals; + zkinOut.a_s0_vals1 = zkin1.s0_vals1; + zkinOut.a_s0_vals3 = zkin1.s0_vals3; + zkinOut.a_s0_vals4 = zkin1.s0_vals4; + zkinOut.a_s0_valsC = zkin1.s0_valsC; + zkinOut.a_s0_siblings1 = zkin1.s0_siblings1; + zkinOut.a_s0_siblings3 = zkin1.s0_siblings3; + zkinOut.a_s0_siblings4 = zkin1.s0_siblings4; + zkinOut.a_s0_siblingsC = zkin1.s0_siblingsC; + zkinOut.a_s1_root = zkin1.s1_root; + zkinOut.a_s2_root = zkin1.s2_root; + zkinOut.a_s3_root = zkin1.s3_root; + zkinOut.a_s4_root = zkin1.s4_root; + zkinOut.a_s1_siblings = zkin1.s1_siblings; + zkinOut.a_s2_siblings = zkin1.s2_siblings; + zkinOut.a_s3_siblings = zkin1.s3_siblings; + zkinOut.a_s4_siblings = zkin1.s4_siblings; + zkinOut.a_s1_vals = zkin1.s1_vals; + zkinOut.a_s2_vals = zkin1.s2_vals; + zkinOut.a_s3_vals = zkin1.s3_vals; + zkinOut.a_s4_vals = zkin1.s4_vals; + zkinOut.a_finalPol = zkin1.finalPol; + + zkinOut.b_publics = zkin2.publics; + zkinOut.b_root1 = zkin2.root1; + zkinOut.b_root2 = zkin2.root2; + zkinOut.b_root3 = zkin2.root3; + zkinOut.b_root4 = zkin2.root4; + zkinOut.b_evals = zkin2.evals; + zkinOut.b_s0_vals1 = zkin2.s0_vals1; + zkinOut.b_s0_vals3 = zkin2.s0_vals3; + zkinOut.b_s0_vals4 = zkin2.s0_vals4; + zkinOut.b_s0_valsC = zkin2.s0_valsC; + zkinOut.b_s0_siblings1 = zkin2.s0_siblings1; + zkinOut.b_s0_siblings3 = zkin2.s0_siblings3; + zkinOut.b_s0_siblings4 = zkin2.s0_siblings4; + zkinOut.b_s0_siblingsC = zkin2.s0_siblingsC; + zkinOut.b_s1_root = zkin2.s1_root; + zkinOut.b_s2_root = zkin2.s2_root; + zkinOut.b_s3_root = zkin2.s3_root; + zkinOut.b_s4_root = zkin2.s4_root; + zkinOut.b_s1_siblings = zkin2.s1_siblings; + zkinOut.b_s2_siblings = zkin2.s2_siblings; + zkinOut.b_s3_siblings = zkin2.s3_siblings; + zkinOut.b_s4_siblings = zkin2.s4_siblings; + zkinOut.b_s1_vals = zkin2.s1_vals; + zkinOut.b_s2_vals = zkin2.s2_vals; + zkinOut.b_s3_vals = zkin2.s3_vals; + zkinOut.b_s4_vals = zkin2.s4_vals; + zkinOut.b_finalPol = zkin2.finalPol; + + zkinOut.rootC = []; + for (let i=0; i<4; i++) { + zkinOut.rootC[i] = constRoot[i].toString(); + } + + await fs.promises.writeFile(zkinOutFile, JSON.stringify(zkinOut, null, 1), "utf8"); + + console.log("file Generated Correctly"); + +} + +run().then(()=> { + process.exit(0); +}, (err) => { + console.log(err.message); + console.log(err.stack); + process.exit(1); +}); diff --git a/src/recursive.starkstruct.json b/src/recursive.starkstruct.json new file mode 100644 index 00000000..992cc86b --- /dev/null +++ b/src/recursive.starkstruct.json @@ -0,0 +1,13 @@ +{ + "nBits": 23, + "nBitsExt": 25, + "nQueries": 64, + "verificationHashType": "GL", + "steps": [ + {"nBits": 25}, + {"nBits": 21}, + {"nBits": 16}, + {"nBits": 11}, + {"nBits": 6} + ] +} diff --git a/src/zkevm.c12b.starkstruct.json b/src/recursivef.starkstruct.json similarity index 74% rename from src/zkevm.c12b.starkstruct.json rename to src/recursivef.starkstruct.json index f1e58315..8247dc68 100644 --- a/src/zkevm.c12b.starkstruct.json +++ b/src/recursivef.starkstruct.json @@ -7,7 +7,8 @@ {"nBits": 24}, {"nBits": 20}, {"nBits": 16}, - {"nBits": 11}, - {"nBits": 6} + {"nBits": 12}, + {"nBits": 8}, + {"nBits": 4} ] } diff --git a/src/sm/sm_global.js b/src/sm/sm_global.js index 7fd2b338..0e1e88cf 100644 --- a/src/sm/sm_global.js +++ b/src/sm/sm_global.js @@ -10,7 +10,7 @@ module.exports.buildConstants = async function (pols) { buidBYTE(pols.BYTE, F, N); buidBYTE2(pols.BYTE2, F, N); buildL1(pols.L1, F, N); - + buildLLAST(pols.LLAST, F, N); }; function buidBYTE2(pol, F, N) { @@ -50,3 +50,8 @@ function buildL1(pol, F, N) { pol[0] = 1n; for ( let i=1; i ) - // TODO: fix nsr this.finalTrace.new_state_root = ethers.utils.hexlify(fea2scalar(ctx.Fr, ctx.SR)); + this.finalTrace.new_acc_input_hash = ethers.utils.hexlify(getVarFromCtx(ctx, true, "newAccInputHash")); this.finalTrace.new_local_exit_root = ethers.utils.hexlify(getVarFromCtx(ctx, true, "newLocalExitRoot")); + this.finalTrace.new_batch_num = ethers.utils.hexlify(getVarFromCtx(ctx, true, "newNumBatch")); // Create ouput files and dirs this.exportTrace(); } diff --git a/src/sm/sm_main/debug/opcodes.js b/src/sm/sm_main/debug/opcodes.js index 626bffb9..b57cd232 100644 --- a/src/sm/sm_main/debug/opcodes.js +++ b/src/sm/sm_main/debug/opcodes.js @@ -56,6 +56,7 @@ module.exports = { 0x45: "opGASLIMIT", 0x46: "opCHAINID", 0x47: "opSELFBALANCE", + 0x48: "opBASEFEE", 0x50: "opPOP", 0x51: "opMLOAD", @@ -152,5 +153,5 @@ module.exports = { 0xfa: "opSTATICCALL", 0xfd: "opREVERT", 0xfe: "opINVALID", - 0xff: "opSELFDESTRUCT" + 0xff: "opSENDALL" }; \ No newline at end of file diff --git a/src/sm/sm_main/sm_main_exec.js b/src/sm/sm_main/sm_main_exec.js index 5ac7849b..552451ee 100644 --- a/src/sm/sm_main/sm_main_exec.js +++ b/src/sm/sm_main/sm_main_exec.js @@ -62,7 +62,6 @@ module.exports = async function execute(pols, input, rom, config = {}) { const db = new MemDB(Fr, input.db); const smt = new SMT(db, poseidon, Fr); - initState(Fr, pols); let op7, op6, op5, op4, op3, op2, op1, op0; @@ -71,7 +70,7 @@ module.exports = async function execute(pols, input, rom, config = {}) { hashK: [], hashP: [], pols: pols, - input: input , + input: input, vars:[], Fr: Fr, Fec: Fec, @@ -83,7 +82,7 @@ module.exports = async function execute(pols, input, rom, config = {}) { stepsN } - preprocessTxs(ctx); + initState(Fr, pols, ctx); if (debug && flagTracer) { fullTracer = new FullTracer(config.debugInfo.inputName) @@ -92,7 +91,7 @@ module.exports = async function execute(pols, input, rom, config = {}) { const iPrint = new Prints(ctx, smt); let fastDebugExit = false; - for (step=0; step < stepsN; step++) { + for (let step = 0; step < stepsN; step++) { const i = step % N; ctx.ln = Fr.toObject(pols.zkPC[i]); ctx.step = step; @@ -123,6 +122,7 @@ module.exports = async function execute(pols, input, rom, config = {}) { ctx.line = l.line; // breaks the loop in debug mode in order to test and debug faster + // assert outputs if (debug && Number(ctx.zkPC) === rom.labels.finalizeExecution) { fastDebugExit = true; break; @@ -131,16 +131,7 @@ module.exports = async function execute(pols, input, rom, config = {}) { let incHashPos = 0; let incCounter = 0; - // if (step % 1000 ==0) { - // console.log(`Step: ${step}`); - // console.log("STEP: ", eval_getReg(ctx, { regName: "STEP" })); - // console.log("CNT_ARITH: ", eval_getReg(ctx, { regName: "CNT_ARITH" })); - // console.log("CNT_BINARY: ", eval_getReg(ctx, { regName: "CNT_BINARY" })); - // console.log("CNT_KECCAK_F: ", eval_getReg(ctx, { regName: "CNT_KECCAK_F" })); - // console.log("CNT_MEM_ALIGN: ", eval_getReg(ctx, { regName: "CNT_MEM_ALIGN" })); - // console.log("CNT_PADDING_PG: ", eval_getReg(ctx, { regName: "CNT_PADDING_PG" })); - // console.log("CNT_POSEIDON_G: ", eval_getReg(ctx, { regName: "CNT_POSEIDON_G" })); - // } + // if (step%100000==0) console.log(`Step: ${step}`); if (step==330) { // console.log("### > "+l.fileName + ':' + l.line); @@ -291,7 +282,7 @@ module.exports = async function execute(pols, input, rom, config = {}) { if (l.inSTEP) { if (skipCounters) { - op0 = Fr.one; + op0 = Fr.zero; pols.inSTEP[i] = Fr.e(l.inSTEP); } else { op0 = Fr.add(op0, Fr.mul( Fr.e(l.inSTEP), Fr.e(i))); @@ -1747,8 +1738,12 @@ module.exports = async function execute(pols, input, rom, config = {}) { } } - if (!debug || !config.stepsN || !fastDebugExit) { - checkFinalState(Fr, pols); + if (fastDebugExit){ + assertOutputs(ctx); + } + + if (!(fastDebugExit || typeof config.stepsN === 'undefined')) { + checkFinalState(Fr, pols, ctx); } for (let i=0; i { - const addressExists = mapTarget.get(addressString) - if (!addressExists) { - mapTarget.set(addressString, new Set()) - } - const storageSet = mapTarget.get(addressString) - slotSet.forEach((value) => { - storageSet.add(value) - }) - }) - } - } - return scalar2fea(ctx.Fr, Scalar.e(0)); -} - -/** - * Revert accessedStorage to last checkpoint - * @param {Object} ctx current rom context object - */ -function eval_revert(ctx) { - ctx.input.accessedStorage.pop() - return [ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero]; -} - -/** - * Checks if the address is warm or cold. In case of cold, the address is added as warm - * @param {Object} ctx current rom context object - * @param {Object} tag tag inputs in rom function - * @returns {FEA} returns 0 if address is warm, 1 if cold - */ -function eval_isWarmedAddress(ctx, tag) { - if (tag.params.length != 1) throw new Error(`Invalid number of parameters function ${tag.funcName}: ${ctx.ln}`) - const address = evalCommand(ctx, tag.params[0]); - const addr = address.toString(16) - // if address is precompiled smart contract considered warm access - if (Scalar.gt(address, 0) && Scalar.lt(address, 10)) { - return [ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero]; - } - - // if address is warm return 0 - for (let i = ctx.input.accessedStorage.length - 1; i >= 0; i--) { - const currentMap = ctx.input.accessedStorage[i] - if (currentMap.has(addr)) { - return [ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero]; - } - } - //if address is not warm, return 1 and add it as warm. We add an emtpy set because is a warmed address (not warmed slot) - const storageSet = ctx.input.accessedStorage[ctx.input.accessedStorage.length - 1].get(addr) - if (!storageSet) { - const emptyStorage = new Set() - ctx.input.accessedStorage[ctx.input.accessedStorage.length - 1].set(addr, emptyStorage) - } - return [ctx.Fr.e(1), ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero]; -} - -/** - * Checks if the storage slot of the account is warm or cold. In case of cold, the slot is added as warm - * @param {Object} ctx current rom context object - * @param {Object} tag tag inputs in rom function - * @returns {FEA} returns 0 if storage solt is warm, 1 if cold - */ -function eval_isWarmedStorage(ctx, tag) { - if (tag.params.length != 2) throw new Error(`Invalid number of parameters function ${tag.funcName}: ${ctx.ln}`) - let addr = evalCommand(ctx, tag.params[0]).toString(16); - let key = evalCommand(ctx, tag.params[1]) - // if address in acessStorage return 0 - for (let i = ctx.input.accessedStorage.length - 1; i >= 0; i--) { - const currentMap = ctx.input.accessedStorage[i] - if (currentMap.has(addr) && currentMap.get(addr).has(key)) { - return [ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero]; - } - } - // if address in acessStorage return 1 and add it as warm - let storageSet = ctx.input.accessedStorage[ctx.input.accessedStorage.length - 1].get(addr) - if (!storageSet) { - storageSet = new Set() - ctx.input.accessedStorage[ctx.input.accessedStorage.length - 1].set(addr, storageSet) - } - storageSet.add(key) - return [ctx.Fr.e(1), ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero]; -} - -/** - * Clears wamred storage array, ready to process a new tx - */ -function eval_clearWarmedStorage(ctx) { - ctx.input.accessedStorage = [new Map()] - return scalar2fea(ctx.Fr, Scalar.e(0)); -} function eval_exp(ctx, tag) { if (tag.params.length != 2) throw new Error(`Invalid number of parameters function ${tag.funcName}: ${ctx.ln} at ${ctx.fileName}:${ctx.line}`) @@ -2721,40 +2635,6 @@ function eval_AddPointEc(ctx, tag, dbl) return [x3, y3]; } -function preprocessTxs(ctx) { - - const { - numBatch, - sequencerAddr, - oldLocalExitRoot, - newLocalExitRoot, - oldStateRoot, - newStateRoot, - globalExitRoot, - timestamp, - chainID - } = ctx.input; - - ctx.input.batchHashData = calculateBatchHashData( - ctx.input.batchL2Data, - globalExitRoot, - sequencerAddr - ); - - ctx.globalHash = calculateStarkInput( - oldStateRoot, - oldLocalExitRoot, - newStateRoot, - newLocalExitRoot, - ctx.input.batchHashData, - numBatch, - timestamp, - chainID - ); - - ctx.input.accessedStorage = [new Map()] -} - function printRegs(Fr, ctx) { printReg8(Fr, "A", ctx.A); printReg8(Fr, "B", ctx.B); diff --git a/tools/build-genesis-recursive/aggregate-batches.json b/tools/build-genesis-recursive/aggregate-batches.json new file mode 100644 index 00000000..b19a514a --- /dev/null +++ b/tools/build-genesis-recursive/aggregate-batches.json @@ -0,0 +1,826 @@ +{ + "singleBatchData": [ + { + "oldStateRoot": "0x3ca39a7b5b419d1c50c89a8d15d1234f6cbc8baadb465efb609832bbc19f9026", + "newStateRoot": "0x51c20e019c6540ece73f7e17eeda9edab9040dcda033fdb9bdf692ab4b1ac8eb", + "oldAccInputHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "newAccInputHash": "0x070c0c1abe776249fe4011d71b63a0cce202069584af3801d5df2dccf64a2d9a", + "newLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "oldNumBatch": 0, + "newNumBatch": 1, + "chainID": 1000, + "batchL2Data": "0xef80843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff8901314fb37062980000808203e88080f9ea8e90ae323e360a22bd0b1a972d15cb33df6ccbfbada4a0d49792d1164ea56029d84d5093a7186fb5bf2f1b7258d57e9c09ac89c4cb8eb44a3c961c4dd89b1b", + "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", + "timestamp": 1944498031, + "sequencerAddr": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "batchHashData": "0x0e8a7e57fe270ab7780cb10ca4b4a39792432701268b0d3a64e6870729e506d1", + "contractsBytecode": {}, + "db": { + "0x3ca39a7b5b419d1c50c89a8d15d1234f6cbc8baadb465efb609832bbc19f9026": [ + "cddc57c0d0fdd4ed", + "d24df1950f2d8f15", + "4c2f3e938869b82d", + "649e63bfe1247ba4", + "b69b044f5e694795", + "f57d81efba5d4445", + "339438195426ad0a", + "3efad1dd58c2259d", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x3efad1dd58c2259d339438195426ad0af57d81efba5d4445b69b044f5e694795": [ + "00000000dea00000", + "0000000035c9adc5", + "0000000000000036", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ] + } + }, + { + "oldStateRoot": "0x51c20e019c6540ece73f7e17eeda9edab9040dcda033fdb9bdf692ab4b1ac8eb", + "newStateRoot": "0xd3dec90c6ff95f738c1d0ea25b0d4b6d9bca91ab37ef9d32a3a2c7411b0cf8c2", + "oldAccInputHash": "0x070c0c1abe776249fe4011d71b63a0cce202069584af3801d5df2dccf64a2d9a", + "newAccInputHash": "0x389bc63239f455750717b4efb5e9440d7b08751241b546e70ffe6075509d6c32", + "newLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "oldNumBatch": 1, + "newNumBatch": 2, + "chainID": 1000, + "batchL2Data": "0xee80843b9aca00830186a094617b3a3528f9cdd6630fd3301b9c8911f7bf063d881bc16d674ec80000808203e880804902102bdd9b91ae389102098dd7d8cb6e732410851223a1153cbe78b0c54d1e63bd7740451f2efcf88bbebdcc334ff3b3e3c332fbbf5703e4699124454663ba1b", + "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", + "timestamp": 1944498032, + "sequencerAddr": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", + "batchHashData": "0xe2058260b8a93dc906fd253c2af22d4cb6136e6833b110a2655f6e0637952e07", + "contractsBytecode": {}, + "db": { + "0x51c20e019c6540ece73f7e17eeda9edab9040dcda033fdb9bdf692ab4b1ac8eb": [ + "4edff1a2e2be3d33", + "2fdcb1c972d12d23", + "c440e7962b465d2c", + "d0472113fa77d32b", + "d021d06d5da7fb4f", + "f4fde3f4e3a2bade", + "9e946596b8ef7ab1", + "04397e281db6cfa4", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xd0472113fa77d32bc440e7962b465d2c2fdcb1c972d12d234edff1a2e2be3d33": [ + "969d4e16652f885c", + "813767f029539b2d", + "9fe495634b694dd2", + "eb4bc8feaf52a6a6", + "9511e6bd1c91bc5d", + "43d6d8c1d086ce96", + "2190a32c7989ef4f", + "14dcce37506968ff", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xeb4bc8feaf52a6a69fe495634b694dd2813767f029539b2d969d4e16652f885c": [ + "48a46a8e735c5308", + "13c524e0f8adc42e", + "4e2074fc48c70ae0", + "85bf62d5f65b9449", + "d074b8cee5dcf415", + "2346a1b4c0f390e8", + "47969c1f5a6a25b1", + "da62fdf84a21108e", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xda62fdf84a21108e47969c1f5a6a25b12346a1b4c0f390e8d074b8cee5dcf415": [ + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x14dcce37506968ff2190a32c7989ef4f43d6d8c1d086ce969511e6bd1c91bc5d": [ + "39a943c2fe744496", + "6b626398c962019e", + "f055e236ae57c543", + "7501dc794f0dfa2f", + "f8648c3a41a08f35", + "13bd9ffae10d8a64", + "276b4a2cc1fd0fb1", + "3a2cbe72639d4982", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x3a2cbe72639d4982276b4a2cc1fd0fb113bd9ffae10d8a64f8648c3a41a08f35": [ + "00000000c19f9026", + "00000000609832bb", + "00000000db465efb", + "000000006cbc8baa", + "0000000015d1234f", + "0000000050c89a8d", + "000000005b419d1c", + "000000003ca39a7b" + ], + "0x04397e281db6cfa49e946596b8ef7ab1f4fde3f4e3a2baded021d06d5da7fb4f": [ + "beb8884a4fc36e93", + "d614c927aa650a9a", + "7db5f1f6d1ba9ac3", + "faf460bb9ee44100", + "bd7c49e380253fa5", + "e372e59a3b60703c", + "a451273cbbb1e1e5", + "98918ae937e2cf3e", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xfaf460bb9ee441007db5f1f6d1ba9ac3d614c927aa650a9abeb8884a4fc36e93": [ + "16dde42596b907f0", + "49015d7e991a1528", + "94dd9dadd060910b", + "60b4d5e9af514018", + "85b8fc8024db5e5c", + "cb9fc9e8676fe5f9", + "900609fbcf391183", + "41e5632337836bc5", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x41e5632337836bc5900609fbcf391183cb9fc9e8676fe5f985b8fc8024db5e5c": [ + "0000000062980000", + "00000000314fb370", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x98918ae937e2cf3ea451273cbbb1e1e5e372e59a3b60703cbd7c49e380253fa5": [ + "d43f2781cecb9cea", + "a8ef821b2d1a19c4", + "8d39c881d94606f2", + "571c41938781a282", + "c4066ba8c32e8a54", + "99ccbd6826c25549", + "1bbff6a9558c13d8", + "5c34e8b7e09eb9d2", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x571c41938781a2828d39c881d94606f2a8ef821b2d1a19c4d43f2781cecb9cea": [ + "442f7573a4097cf2", + "3520bc74612a2ea9", + "143ce4e61bf52251", + "da69a3c4a8007a5a", + "d074b8cee5dcf415", + "2346a1b4c0f390e8", + "47969c1f5a6a25b1", + "da62fdf84a21108e", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x5c34e8b7e09eb9d21bbff6a9558c13d899ccbd6826c25549c4066ba8c32e8a54": [ + "66ee2be0687eea76", + "6926f8ca8796c78a", + "26179f49c434dc16", + "649e63bfe1247ba4", + "8d6f4bb1f77e3231", + "e8588d537a7fd215", + "06643ffe76ca3417", + "ac6fb937ba074e4f", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xac6fb937ba074e4f06643ffe76ca3417e8588d537a7fd2158d6f4bb1f77e3231": [ + "000000007c080000", + "000000000479fa55", + "0000000000000035", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ] + } + }, + { + "oldStateRoot": "0xd3dec90c6ff95f738c1d0ea25b0d4b6d9bca91ab37ef9d32a3a2c7411b0cf8c2", + "newStateRoot": "0x9ae91f93d37e12c383702620a516c032d7e49616904c5b4a400cc486916aaa63", + "oldAccInputHash": "0x389bc63239f455750717b4efb5e9440d7b08751241b546e70ffe6075509d6c32", + "newAccInputHash": "0xad1915669aaf61a83bbfad1f4360c1a32245e38ffb67b1afa68c825135890fc9", + "newLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "oldNumBatch": 2, + "newNumBatch": 3, + "chainID": 1000, + "batchL2Data": "0xee01843b9aca00830186a094617b3a3528f9cdd6630fd3301b9c8911f7bf063d880de0b6b3a7640000808203e88080d71f728226f6e692289eab9f2c9565036ffda72650c88e2b9c001b95a5f1a2e647612249728261ab90977a2c50b22b8fd486f88b356a921f4487327e5d2775651cee02843b9aca00830186a094617b3a3528f9cdd6630fd3301b9c8911f7bf063d880de0b6b3a7640000808203e880808ab4d93e176f0762b48dfd8382f97200e134eb1e8e6423951d70af8f99e53c805b61ee8721981423a592c0c1af55c482bed43a45e2e3c1ecc70d350e2083ebc11b", + "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", + "timestamp": 1944498032, + "sequencerAddr": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", + "batchHashData": "0xe0b9d084dae9d015aaf65bc9b013b37c12b3cc31ae4e9590296c50eda518d8a1", + "contractsBytecode": {}, + "db": { + "0xd3dec90c6ff95f738c1d0ea25b0d4b6d9bca91ab37ef9d32a3a2c7411b0cf8c2": [ + "2c40dd65bac5ec25", + "02c474fa2e498481", + "d99f8241e3b2aa21", + "b340806c58bc2458", + "a0296ae566f02a45", + "97f575f7774f7278", + "16059906d9e86a1e", + "b349983b89d629f5", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xb340806c58bc2458d99f8241e3b2aa2102c474fa2e4984812c40dd65bac5ec25": [ + "9370eff1061e6d5c", + "55882973d172f233", + "88cfc1f89a849899", + "df6bcc7e7c0d155a", + "65043e011f39d0a5", + "872c214b0e289985", + "7bd6870095f7ec06", + "f0a4077ae56c7e90", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xdf6bcc7e7c0d155a88cfc1f89a84989955882973d172f2339370eff1061e6d5c": [ + "48a46a8e735c5308", + "13c524e0f8adc42e", + "4e2074fc48c70ae0", + "85bf62d5f65b9449", + "7615b40971dc29f2", + "303a082109d64fe0", + "54f2216c0b37148d", + "adb5787a1f8676b5", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xadb5787a1f8676b554f2216c0b37148d303a082109d64fe07615b40971dc29f2": [ + "0000000000000002", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xf0a4077ae56c7e907bd6870095f7ec06872c214b0e28998565043e011f39d0a5": [ + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "08b52e58b7457f54", + "1304e01835afc3f0", + "3fd503f54236c476", + "e12a7ad6e06e80e1", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xe12a7ad6e06e80e13fd503f54236c4761304e01835afc3f008b52e58b7457f54": [ + "32402f4ef1eae380", + "4bf67690247b7218", + "8b1cf5722b22757d", + "13bf40d1f5ac2be9", + "ab1b9a26192a2153", + "1d4b94cd658e8474", + "3ec02b72c520c8b1", + "6e4beb40a404c6b2", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x13bf40d1f5ac2be98b1cf5722b22757d4bf67690247b721832402f4ef1eae380": [ + "6f0cd9b7cb0ef911", + "5ac4a699725dc2e0", + "6bf2c9fd6a3aa16c", + "325ba19f4ab866aa", + "d074b8cee5dcf415", + "2346a1b4c0f390e8", + "47969c1f5a6a25b1", + "da62fdf84a21108e", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xda62fdf84a21108e47969c1f5a6a25b12346a1b4c0f390e8d074b8cee5dcf415": [ + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x6e4beb40a404c6b23ec02b72c520c8b11d4b94cd658e8474ab1b9a26192a2153": [ + "39a943c2fe744496", + "6b626398c962019e", + "782af11b572be2a1", + "3a80ee3ca786fd17", + "f8648c3a41a08f35", + "13bd9ffae10d8a64", + "276b4a2cc1fd0fb1", + "3a2cbe72639d4982", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x3a2cbe72639d4982276b4a2cc1fd0fb113bd9ffae10d8a64f8648c3a41a08f35": [ + "00000000c19f9026", + "00000000609832bb", + "00000000db465efb", + "000000006cbc8baa", + "0000000015d1234f", + "0000000050c89a8d", + "000000005b419d1c", + "000000003ca39a7b" + ], + "0xb349983b89d629f516059906d9e86a1e97f575f7774f7278a0296ae566f02a45": [ + "163ba4e2ffbf8096", + "c49ba6adbea541e3", + "bf58be149cc6c661", + "040a2dd691fac259", + "735804849b2ec0c9", + "8dfadc4705db264e", + "dd98343d69e50cbe", + "5f8457df3238fa63", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x040a2dd691fac259bf58be149cc6c661c49ba6adbea541e3163ba4e2ffbf8096": [ + "dcbcc05dd4a6d7c8", + "28c4164ae91b1916", + "a979c951e632426b", + "b4a35f4caddf10e1", + "ffb37dd5c4944a0b", + "a3ac611061859955", + "a2ceb01d96062aef", + "efef601e34dca5d6", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xb4a35f4caddf10e1a979c951e632426b28c4164ae91b1916dcbcc05dd4a6d7c8": [ + "24824d7a7031773e", + "641c96e60deb8c3c", + "2bc52d16e9585d9e", + "34c0a58d3e8490f2", + "7ce38f72debe188a", + "21a55b8604c6e510", + "d4a5f6fdf13a18ab", + "46c6b8ce3d309fb9", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x46c6b8ce3d309fb9d4a5f6fdf13a18ab21a55b8604c6e5107ce38f72debe188a": [ + "000000004b1ac8eb", + "00000000bdf692ab", + "00000000a033fdb9", + "00000000b9040dcd", + "00000000eeda9eda", + "00000000e73f7e17", + "000000009c6540ec", + "0000000051c20e01" + ], + "0xefef601e34dca5d6a2ceb01d96062aefa3ac611061859955ffb37dd5c4944a0b": [ + "16dde42596b907f0", + "49015d7e991a1528", + "4a6eced6e8304885", + "60b4d5e9af514018", + "18c9513b1e7d9904", + "0b6835f79f991d71", + "a8751b2d01a9def9", + "5bc67a31279947d0", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x5bc67a31279947d0a8751b2d01a9def90b6835f79f991d7118c9513b1e7d9904": [ + "0000000013d00000", + "00000000158e4609", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x5f8457df3238fa63dd98343d69e50cbe8dfadc4705db264e735804849b2ec0c9": [ + "d43f2781cecb9cea", + "a8ef821b2d1a19c4", + "8d39c881d94606f2", + "571c41938781a282", + "88de93befbb5aaa4", + "0daef15f24ea3e20", + "02ef2f6176cbbf97", + "69d5f78b6a46aa1d", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x571c41938781a2828d39c881d94606f2a8ef821b2d1a19c4d43f2781cecb9cea": [ + "442f7573a4097cf2", + "3520bc74612a2ea9", + "143ce4e61bf52251", + "da69a3c4a8007a5a", + "d074b8cee5dcf415", + "2346a1b4c0f390e8", + "47969c1f5a6a25b1", + "da62fdf84a21108e", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x69d5f78b6a46aa1d02ef2f6176cbbf970daef15f24ea3e2088de93befbb5aaa4": [ + "66ee2be0687eea76", + "6926f8ca8796c78a", + "26179f49c434dc16", + "649e63bfe1247ba4", + "5e83cc15f9f05fa9", + "4098e44c091c5d81", + "1a9584e1365c3ec9", + "021fc6d3425cd2f6", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x021fc6d3425cd2f61a9584e1365c3ec94098e44c091c5d815e83cc15f9f05fa9": [ + "00000000cad00000", + "00000000203b67bc", + "0000000000000035", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ] + } + }, + { + "oldStateRoot": "0x9ae91f93d37e12c383702620a516c032d7e49616904c5b4a400cc486916aaa63", + "newStateRoot": "0xcce5d565437c33de2cb1154ecf7c2d949f1aee03d144d7eee717157c3ee0149e", + "oldAccInputHash": "0xad1915669aaf61a83bbfad1f4360c1a32245e38ffb67b1afa68c825135890fc9", + "newAccInputHash": "0xbd71644a8d0eff3d5ae771310c7f15c097dddffe7199e6db738479b01729abfe", + "newLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "oldNumBatch": 3, + "newNumBatch": 4, + "chainID": 1000, + "batchL2Data": "0xee01843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff883782dace9d900000808203e88080d7d8b23bdec805a0c758de3e2289077b1e4c8401ddff73c7e59e2f9351d14f5f6f04e7bbb69548737581cd5a6e3bac8695776bfd41dc1c8fc9921c4b08e008031bee02843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff8829a2241af62c0000808203e88080ee8448de88596fff6a98af2e603c9a10ccafa114815e844c8b7e8c52cb3fd1470d81101bb5a4a0aa5f459f29da0f6e95cd9e178774f0f3f1c48733618d7bd2231c", + "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", + "timestamp": 1944498032, + "sequencerAddr": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "batchHashData": "0x763d3272e66b10bef69106ea07750823c580d20802fb1141b69b5ec56790a449", + "contractsBytecode": {}, + "db": { + "0x9ae91f93d37e12c383702620a516c032d7e49616904c5b4a400cc486916aaa63": [ + "ac81a9066ee90c0d", + "657c4cf0471c465a", + "430171156248766d", + "0673c4dc9b268d54", + "7dc0c3d04f5a81c4", + "6bd8a8902ebc74bd", + "50201c606aa1c2da", + "6fc717a1999b86c8", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x0673c4dc9b268d54430171156248766d657c4cf0471c465aac81a9066ee90c0d": [ + "03eb4f3c35a91b3b", + "044d0f5794859875", + "9e577982bf760c7d", + "07fc4cd27e5f415e", + "970bdf29593fc15a", + "e6b1378a58ca7c8a", + "7252f83f498eaf89", + "c0563e997057e39a", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x07fc4cd27e5f415e9e577982bf760c7d044d0f579485987503eb4f3c35a91b3b": [ + "0febc099e7c5c454", + "924820b06dd797ec", + "fcf6522bcf657dcf", + "5ab455eaeecd090d", + "dff64fc66f6b1ba6", + "fd2c219d9b80dc18", + "9888feeb030d1bf9", + "f4f93955259cb0de", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x5ab455eaeecd090dfcf6522bcf657dcf924820b06dd797ec0febc099e7c5c454": [ + "48a46a8e735c5308", + "13c524e0f8adc42e", + "27103a7e24638570", + "85bf62d5f65b9449", + "cad6cdbfa198be91", + "cd0e941b466a39b4", + "a7e6b3f9d3f197d5", + "a2135065f1605059", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xa2135065f1605059a7e6b3f9d3f197d5cd0e941b466a39b4cad6cdbfa198be91": [ + "0000000000000003", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xf4f93955259cb0de9888feeb030d1bf9fd2c219d9b80dc18dff64fc66f6b1ba6": [ + "780709cc8c2462a2", + "3931e3690ee68019", + "185093e495fe78c5", + "67d3fbfba0e1bb5e", + "715108b4ad8fad63", + "20241246bd28c180", + "e7a0f3d56104a4d8", + "717570988acd6670", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x717570988acd6670e7a0f3d56104a4d820241246bd28c180715108b4ad8fad63": [ + "000000001b0cf8c2", + "00000000a3a2c741", + "0000000037ef9d32", + "000000009bca91ab", + "000000005b0d4b6d", + "000000008c1d0ea2", + "000000006ff95f73", + "00000000d3dec90c" + ], + "0xc0563e997057e39a7252f83f498eaf89e6b1378a58ca7c8a970bdf29593fc15a": [ + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "36fbd59753b7e63e", + "873daf7980590ee1", + "78cb98b9b7fe9e23", + "8c6d0251b958a83a", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x8c6d0251b958a83a78cb98b9b7fe9e23873daf7980590ee136fbd59753b7e63e": [ + "7a194b0c3917f8de", + "179ddf2d5e23e97e", + "e838cfb3d5459971", + "2bcd4a01e4e9ac1a", + "ab1b9a26192a2153", + "1d4b94cd658e8474", + "3ec02b72c520c8b1", + "6e4beb40a404c6b2", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x2bcd4a01e4e9ac1ae838cfb3d5459971179ddf2d5e23e97e7a194b0c3917f8de": [ + "6f0cd9b7cb0ef911", + "5ac4a699725dc2e0", + "6bf2c9fd6a3aa16c", + "325ba19f4ab866aa", + "cad6cdbfa198be91", + "cd0e941b466a39b4", + "a7e6b3f9d3f197d5", + "a2135065f1605059", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x6e4beb40a404c6b23ec02b72c520c8b11d4b94cd658e8474ab1b9a26192a2153": [ + "39a943c2fe744496", + "6b626398c962019e", + "782af11b572be2a1", + "3a80ee3ca786fd17", + "f8648c3a41a08f35", + "13bd9ffae10d8a64", + "276b4a2cc1fd0fb1", + "3a2cbe72639d4982", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x3a2cbe72639d4982276b4a2cc1fd0fb113bd9ffae10d8a64f8648c3a41a08f35": [ + "00000000c19f9026", + "00000000609832bb", + "00000000db465efb", + "000000006cbc8baa", + "0000000015d1234f", + "0000000050c89a8d", + "000000005b419d1c", + "000000003ca39a7b" + ], + "0x6fc717a1999b86c850201c606aa1c2da6bd8a8902ebc74bd7dc0c3d04f5a81c4": [ + "1523a65ab5f5b2bb", + "40e72f81b26308bf", + "86e8309a8e90844a", + "b19c9cb8444738d7", + "99d18649b58e3b76", + "32671ba72618ac58", + "0e57387f8f6dbe16", + "46a388c8ab7ab4a1", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xb19c9cb8444738d786e8309a8e90844a40e72f81b26308bf1523a65ab5f5b2bb": [ + "dcbcc05dd4a6d7c8", + "28c4164ae91b1916", + "a979c951e632426b", + "b4a35f4caddf10e1", + "14eada4858715e40", + "f980d1fedc728158", + "a9a1b04bf5cd5d6f", + "edcb391353295f0c", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xb4a35f4caddf10e1a979c951e632426b28c4164ae91b1916dcbcc05dd4a6d7c8": [ + "24824d7a7031773e", + "641c96e60deb8c3c", + "2bc52d16e9585d9e", + "34c0a58d3e8490f2", + "7ce38f72debe188a", + "21a55b8604c6e510", + "d4a5f6fdf13a18ab", + "46c6b8ce3d309fb9", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x46c6b8ce3d309fb9d4a5f6fdf13a18ab21a55b8604c6e5107ce38f72debe188a": [ + "000000004b1ac8eb", + "00000000bdf692ab", + "00000000a033fdb9", + "00000000b9040dcd", + "00000000eeda9eda", + "00000000e73f7e17", + "000000009c6540ec", + "0000000051c20e01" + ], + "0xedcb391353295f0ca9a1b04bf5cd5d6ff980d1fedc72815814eada4858715e40": [ + "16dde42596b907f0", + "49015d7e991a1528", + "4a6eced6e8304885", + "60b4d5e9af514018", + "90e98ea2a6fee2b3", + "09b4104e4b0f1f42", + "3c656749691cf3af", + "4b1d11a97ceff72f", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x4b1d11a97ceff72f3c656749691cf3af09b4104e4b0f1f4290e98ea2a6fee2b3": [ + "00000000c5080000", + "00000000f9ccd8a1", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x46a388c8ab7ab4a10e57387f8f6dbe1632671ba72618ac5899d18649b58e3b76": [ + "d43f2781cecb9cea", + "a8ef821b2d1a19c4", + "8d39c881d94606f2", + "571c41938781a282", + "2b6429747753e992", + "8de937d8391bc07c", + "0ba2467e6b2a03b8", + "43ce72d79779e851", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x571c41938781a2828d39c881d94606f2a8ef821b2d1a19c4d43f2781cecb9cea": [ + "442f7573a4097cf2", + "3520bc74612a2ea9", + "143ce4e61bf52251", + "da69a3c4a8007a5a", + "d074b8cee5dcf415", + "2346a1b4c0f390e8", + "47969c1f5a6a25b1", + "da62fdf84a21108e", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xda62fdf84a21108e47969c1f5a6a25b12346a1b4c0f390e8d074b8cee5dcf415": [ + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x43ce72d79779e8510ba2467e6b2a03b88de937d8391bc07c2b6429747753e992": [ + "66ee2be0687eea76", + "6926f8ca8796c78a", + "26179f49c434dc16", + "649e63bfe1247ba4", + "67bbfffd0982dfa4", + "93c661c88448b5ed", + "cec2687622ccc942", + "4e709c8e17913749", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x4e709c8e17913749cec2687622ccc94293c661c88448b5ed67bbfffd0982dfa4": [ + "0000000019980000", + "000000003bfcd524", + "0000000000000035", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ] + } + } + ], + "oldStateRoot": "0x3ca39a7b5b419d1c50c89a8d15d1234f6cbc8baadb465efb609832bbc19f9026", + "oldAccInputHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "oldNumBatch": 0, + "newStateRoot": "0xcce5d565437c33de2cb1154ecf7c2d949f1aee03d144d7eee717157c3ee0149e", + "newAccInputHash": "0xbd71644a8d0eff3d5ae771310c7f15c097dddffe7199e6db738479b01729abfe", + "newLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "newNumBatch": 4, + "chainID": 1000, + "aggregatorAddress": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", + "inputSnark": "0x1bbcf5c47394a140f4f00d9108785a9c4816f4a6a81ad832d732a214e9c3f57c" +} \ No newline at end of file diff --git a/tools/build-genesis-recursive/build_genesis_recursive.js b/tools/build-genesis-recursive/build_genesis_recursive.js new file mode 100644 index 00000000..e7186378 --- /dev/null +++ b/tools/build-genesis-recursive/build_genesis_recursive.js @@ -0,0 +1,120 @@ +const fs = require("fs"); +const path = require("path"); +const ethers = require("ethers"); +const { + MemDB, ZkEVMDB, processorUtils, smtUtils, getPoseidon, +} = require('@0xpolygonhermez/zkevm-commonjs'); + +// paths files +const pathInput = path.join(__dirname, "./input_gen_recursive.json"); +const pathOutput = path.join(__dirname, "./aggregate-batches.json"); + +async function main(){ + // build poseidon + const poseidon = await getPoseidon(); + const F = poseidon.F; + + // read generate input + const generateData = require(pathInput); + + // mapping wallets + const walletMap = {}; + + for (let i = 0; i < generateData.genesis.length; i++) { + const { + address, pvtKey + } = generateData.genesis[i]; + + const newWallet = new ethers.Wallet(pvtKey); + walletMap[address] = newWallet; + } + + // create a zkEVMDB and build a batch + const db = new MemDB(F); + const zkEVMDB = await ZkEVMDB.newZkEVM( + db, + poseidon, + [F.zero, F.zero, F.zero, F.zero], // empty smt + typeof generateData.oldAccInputHash === 'undefined' ? [F.zero, F.zero, F.zero, F.zero] : smtUtils.stringToH4(generateData.oldAccInputHash), + generateData.genesis, + null, + null, + generateData.chainID + ); + + // Build batches + let updatedAccounts = {}; + + for (let i = 0; i < generateData.batches.length; i++){ + const genBatchData = generateData.batches[i]; + + // start batch + const batch = await zkEVMDB.buildBatch( + genBatchData.timestamp, + genBatchData.sequencerAddr, + smtUtils.stringToH4(genBatchData.globalExitRoot) + ); + + for (let j = 0; j < genBatchData.txs.length; j++){ + const genTx = genBatchData.txs[j]; + + // build tx + const tx = { + to: genTx.to, + nonce: genTx.nonce, + value: ethers.utils.parseUnits(genTx.value, 'wei'), + gasLimit: genTx.gasLimit, + gasPrice: ethers.utils.parseUnits(genTx.gasPrice, 'wei'), + chainId: genTx.chainId, + data: genTx.data || '0x', + }; + + const rawTxEthers = await walletMap[genTx.from].signTransaction(tx); + const customRawTx = processorUtils.rawTxToCustomRawTx(rawTxEthers); + + // add tx to batch + batch.addRawTx(customRawTx); + } + + // build batch + await batch.executeTxs(); + updatedAccounts = { ...updatedAccounts, ...batch.getUpdatedAccountsBatch()}; + // consolidate state + await zkEVMDB.consolidate(batch); + // get stark input for each batch + const starkInput = await batch.getStarkInput(); + // write input executor for each batch + fs.writeFileSync(path.join(__dirname, `./input_executor_${i}.json`), JSON.stringify(starkInput, null, 2)); + } + + // print new states + const newLeafs = {}; + for (const item in updatedAccounts) { + const address = item; + const account = updatedAccounts[address]; + newLeafs[address] = {}; + + newLeafs[address].balance = account.balance.toString(); + newLeafs[address].nonce = account.nonce.toString(); + + const storage = await zkEVMDB.dumpStorage(address); + const hashBytecode = await zkEVMDB.getHashBytecode(address); + newLeafs[address].storage = storage; + newLeafs[address].hashBytecode = hashBytecode; + } + generateData.expectedLeafs = newLeafs; + + // write new leafs + fs.writeFileSync(pathInput, JSON.stringify(generateData, null, 2)); + + // write aggregate batches + const initialNumBatch = 1; + const finalNumBatch = zkEVMDB.lastBatch; + const aggregatorAddress = generateData.aggregatorAddress; + + const outVerifyRecursive = await zkEVMDB.verifyMultipleBatches(initialNumBatch, finalNumBatch, aggregatorAddress); + fs.writeFileSync(pathOutput, JSON.stringify(outVerifyRecursive, null, 2)); +} + + +main(); \ No newline at end of file diff --git a/tools/build-genesis-recursive/input_executor_0.json b/tools/build-genesis-recursive/input_executor_0.json new file mode 100644 index 00000000..2ba38612 --- /dev/null +++ b/tools/build-genesis-recursive/input_executor_0.json @@ -0,0 +1,42 @@ +{ + "oldStateRoot": "0x3ca39a7b5b419d1c50c89a8d15d1234f6cbc8baadb465efb609832bbc19f9026", + "newStateRoot": "0x51c20e019c6540ece73f7e17eeda9edab9040dcda033fdb9bdf692ab4b1ac8eb", + "oldAccInputHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "newAccInputHash": "0x070c0c1abe776249fe4011d71b63a0cce202069584af3801d5df2dccf64a2d9a", + "newLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "oldNumBatch": 0, + "newNumBatch": 1, + "chainID": 1000, + "batchL2Data": "0xef80843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff8901314fb37062980000808203e88080f9ea8e90ae323e360a22bd0b1a972d15cb33df6ccbfbada4a0d49792d1164ea56029d84d5093a7186fb5bf2f1b7258d57e9c09ac89c4cb8eb44a3c961c4dd89b1b", + "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", + "timestamp": 1944498031, + "sequencerAddr": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "batchHashData": "0x0e8a7e57fe270ab7780cb10ca4b4a39792432701268b0d3a64e6870729e506d1", + "contractsBytecode": {}, + "db": { + "0x3ca39a7b5b419d1c50c89a8d15d1234f6cbc8baadb465efb609832bbc19f9026": [ + "cddc57c0d0fdd4ed", + "d24df1950f2d8f15", + "4c2f3e938869b82d", + "649e63bfe1247ba4", + "b69b044f5e694795", + "f57d81efba5d4445", + "339438195426ad0a", + "3efad1dd58c2259d", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x3efad1dd58c2259d339438195426ad0af57d81efba5d4445b69b044f5e694795": [ + "00000000dea00000", + "0000000035c9adc5", + "0000000000000036", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ] + } +} \ No newline at end of file diff --git a/tools/build-genesis-recursive/input_executor_1.json b/tools/build-genesis-recursive/input_executor_1.json new file mode 100644 index 00000000..9422890b --- /dev/null +++ b/tools/build-genesis-recursive/input_executor_1.json @@ -0,0 +1,184 @@ +{ + "oldStateRoot": "0x51c20e019c6540ece73f7e17eeda9edab9040dcda033fdb9bdf692ab4b1ac8eb", + "newStateRoot": "0xd3dec90c6ff95f738c1d0ea25b0d4b6d9bca91ab37ef9d32a3a2c7411b0cf8c2", + "oldAccInputHash": "0x070c0c1abe776249fe4011d71b63a0cce202069584af3801d5df2dccf64a2d9a", + "newAccInputHash": "0x389bc63239f455750717b4efb5e9440d7b08751241b546e70ffe6075509d6c32", + "newLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "oldNumBatch": 1, + "newNumBatch": 2, + "chainID": 1000, + "batchL2Data": "0xee80843b9aca00830186a094617b3a3528f9cdd6630fd3301b9c8911f7bf063d881bc16d674ec80000808203e880804902102bdd9b91ae389102098dd7d8cb6e732410851223a1153cbe78b0c54d1e63bd7740451f2efcf88bbebdcc334ff3b3e3c332fbbf5703e4699124454663ba1b", + "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", + "timestamp": 1944498032, + "sequencerAddr": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", + "batchHashData": "0xe2058260b8a93dc906fd253c2af22d4cb6136e6833b110a2655f6e0637952e07", + "contractsBytecode": {}, + "db": { + "0x51c20e019c6540ece73f7e17eeda9edab9040dcda033fdb9bdf692ab4b1ac8eb": [ + "4edff1a2e2be3d33", + "2fdcb1c972d12d23", + "c440e7962b465d2c", + "d0472113fa77d32b", + "d021d06d5da7fb4f", + "f4fde3f4e3a2bade", + "9e946596b8ef7ab1", + "04397e281db6cfa4", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xd0472113fa77d32bc440e7962b465d2c2fdcb1c972d12d234edff1a2e2be3d33": [ + "969d4e16652f885c", + "813767f029539b2d", + "9fe495634b694dd2", + "eb4bc8feaf52a6a6", + "9511e6bd1c91bc5d", + "43d6d8c1d086ce96", + "2190a32c7989ef4f", + "14dcce37506968ff", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xeb4bc8feaf52a6a69fe495634b694dd2813767f029539b2d969d4e16652f885c": [ + "48a46a8e735c5308", + "13c524e0f8adc42e", + "4e2074fc48c70ae0", + "85bf62d5f65b9449", + "d074b8cee5dcf415", + "2346a1b4c0f390e8", + "47969c1f5a6a25b1", + "da62fdf84a21108e", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xda62fdf84a21108e47969c1f5a6a25b12346a1b4c0f390e8d074b8cee5dcf415": [ + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x14dcce37506968ff2190a32c7989ef4f43d6d8c1d086ce969511e6bd1c91bc5d": [ + "39a943c2fe744496", + "6b626398c962019e", + "f055e236ae57c543", + "7501dc794f0dfa2f", + "f8648c3a41a08f35", + "13bd9ffae10d8a64", + "276b4a2cc1fd0fb1", + "3a2cbe72639d4982", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x3a2cbe72639d4982276b4a2cc1fd0fb113bd9ffae10d8a64f8648c3a41a08f35": [ + "00000000c19f9026", + "00000000609832bb", + "00000000db465efb", + "000000006cbc8baa", + "0000000015d1234f", + "0000000050c89a8d", + "000000005b419d1c", + "000000003ca39a7b" + ], + "0x04397e281db6cfa49e946596b8ef7ab1f4fde3f4e3a2baded021d06d5da7fb4f": [ + "beb8884a4fc36e93", + "d614c927aa650a9a", + "7db5f1f6d1ba9ac3", + "faf460bb9ee44100", + "bd7c49e380253fa5", + "e372e59a3b60703c", + "a451273cbbb1e1e5", + "98918ae937e2cf3e", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xfaf460bb9ee441007db5f1f6d1ba9ac3d614c927aa650a9abeb8884a4fc36e93": [ + "16dde42596b907f0", + "49015d7e991a1528", + "94dd9dadd060910b", + "60b4d5e9af514018", + "85b8fc8024db5e5c", + "cb9fc9e8676fe5f9", + "900609fbcf391183", + "41e5632337836bc5", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x41e5632337836bc5900609fbcf391183cb9fc9e8676fe5f985b8fc8024db5e5c": [ + "0000000062980000", + "00000000314fb370", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x98918ae937e2cf3ea451273cbbb1e1e5e372e59a3b60703cbd7c49e380253fa5": [ + "d43f2781cecb9cea", + "a8ef821b2d1a19c4", + "8d39c881d94606f2", + "571c41938781a282", + "c4066ba8c32e8a54", + "99ccbd6826c25549", + "1bbff6a9558c13d8", + "5c34e8b7e09eb9d2", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x571c41938781a2828d39c881d94606f2a8ef821b2d1a19c4d43f2781cecb9cea": [ + "442f7573a4097cf2", + "3520bc74612a2ea9", + "143ce4e61bf52251", + "da69a3c4a8007a5a", + "d074b8cee5dcf415", + "2346a1b4c0f390e8", + "47969c1f5a6a25b1", + "da62fdf84a21108e", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x5c34e8b7e09eb9d21bbff6a9558c13d899ccbd6826c25549c4066ba8c32e8a54": [ + "66ee2be0687eea76", + "6926f8ca8796c78a", + "26179f49c434dc16", + "649e63bfe1247ba4", + "8d6f4bb1f77e3231", + "e8588d537a7fd215", + "06643ffe76ca3417", + "ac6fb937ba074e4f", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xac6fb937ba074e4f06643ffe76ca3417e8588d537a7fd2158d6f4bb1f77e3231": [ + "000000007c080000", + "000000000479fa55", + "0000000000000035", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ] + } +} \ No newline at end of file diff --git a/tools/build-genesis-recursive/input_executor_2.json b/tools/build-genesis-recursive/input_executor_2.json new file mode 100644 index 00000000..853e3ddf --- /dev/null +++ b/tools/build-genesis-recursive/input_executor_2.json @@ -0,0 +1,274 @@ +{ + "oldStateRoot": "0xd3dec90c6ff95f738c1d0ea25b0d4b6d9bca91ab37ef9d32a3a2c7411b0cf8c2", + "newStateRoot": "0x9ae91f93d37e12c383702620a516c032d7e49616904c5b4a400cc486916aaa63", + "oldAccInputHash": "0x389bc63239f455750717b4efb5e9440d7b08751241b546e70ffe6075509d6c32", + "newAccInputHash": "0xad1915669aaf61a83bbfad1f4360c1a32245e38ffb67b1afa68c825135890fc9", + "newLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "oldNumBatch": 2, + "newNumBatch": 3, + "chainID": 1000, + "batchL2Data": "0xee01843b9aca00830186a094617b3a3528f9cdd6630fd3301b9c8911f7bf063d880de0b6b3a7640000808203e88080d71f728226f6e692289eab9f2c9565036ffda72650c88e2b9c001b95a5f1a2e647612249728261ab90977a2c50b22b8fd486f88b356a921f4487327e5d2775651cee02843b9aca00830186a094617b3a3528f9cdd6630fd3301b9c8911f7bf063d880de0b6b3a7640000808203e880808ab4d93e176f0762b48dfd8382f97200e134eb1e8e6423951d70af8f99e53c805b61ee8721981423a592c0c1af55c482bed43a45e2e3c1ecc70d350e2083ebc11b", + "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", + "timestamp": 1944498032, + "sequencerAddr": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", + "batchHashData": "0xe0b9d084dae9d015aaf65bc9b013b37c12b3cc31ae4e9590296c50eda518d8a1", + "contractsBytecode": {}, + "db": { + "0xd3dec90c6ff95f738c1d0ea25b0d4b6d9bca91ab37ef9d32a3a2c7411b0cf8c2": [ + "2c40dd65bac5ec25", + "02c474fa2e498481", + "d99f8241e3b2aa21", + "b340806c58bc2458", + "a0296ae566f02a45", + "97f575f7774f7278", + "16059906d9e86a1e", + "b349983b89d629f5", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xb340806c58bc2458d99f8241e3b2aa2102c474fa2e4984812c40dd65bac5ec25": [ + "9370eff1061e6d5c", + "55882973d172f233", + "88cfc1f89a849899", + "df6bcc7e7c0d155a", + "65043e011f39d0a5", + "872c214b0e289985", + "7bd6870095f7ec06", + "f0a4077ae56c7e90", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xdf6bcc7e7c0d155a88cfc1f89a84989955882973d172f2339370eff1061e6d5c": [ + "48a46a8e735c5308", + "13c524e0f8adc42e", + "4e2074fc48c70ae0", + "85bf62d5f65b9449", + "7615b40971dc29f2", + "303a082109d64fe0", + "54f2216c0b37148d", + "adb5787a1f8676b5", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xadb5787a1f8676b554f2216c0b37148d303a082109d64fe07615b40971dc29f2": [ + "0000000000000002", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xf0a4077ae56c7e907bd6870095f7ec06872c214b0e28998565043e011f39d0a5": [ + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "08b52e58b7457f54", + "1304e01835afc3f0", + "3fd503f54236c476", + "e12a7ad6e06e80e1", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xe12a7ad6e06e80e13fd503f54236c4761304e01835afc3f008b52e58b7457f54": [ + "32402f4ef1eae380", + "4bf67690247b7218", + "8b1cf5722b22757d", + "13bf40d1f5ac2be9", + "ab1b9a26192a2153", + "1d4b94cd658e8474", + "3ec02b72c520c8b1", + "6e4beb40a404c6b2", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x13bf40d1f5ac2be98b1cf5722b22757d4bf67690247b721832402f4ef1eae380": [ + "6f0cd9b7cb0ef911", + "5ac4a699725dc2e0", + "6bf2c9fd6a3aa16c", + "325ba19f4ab866aa", + "d074b8cee5dcf415", + "2346a1b4c0f390e8", + "47969c1f5a6a25b1", + "da62fdf84a21108e", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xda62fdf84a21108e47969c1f5a6a25b12346a1b4c0f390e8d074b8cee5dcf415": [ + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x6e4beb40a404c6b23ec02b72c520c8b11d4b94cd658e8474ab1b9a26192a2153": [ + "39a943c2fe744496", + "6b626398c962019e", + "782af11b572be2a1", + "3a80ee3ca786fd17", + "f8648c3a41a08f35", + "13bd9ffae10d8a64", + "276b4a2cc1fd0fb1", + "3a2cbe72639d4982", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x3a2cbe72639d4982276b4a2cc1fd0fb113bd9ffae10d8a64f8648c3a41a08f35": [ + "00000000c19f9026", + "00000000609832bb", + "00000000db465efb", + "000000006cbc8baa", + "0000000015d1234f", + "0000000050c89a8d", + "000000005b419d1c", + "000000003ca39a7b" + ], + "0xb349983b89d629f516059906d9e86a1e97f575f7774f7278a0296ae566f02a45": [ + "163ba4e2ffbf8096", + "c49ba6adbea541e3", + "bf58be149cc6c661", + "040a2dd691fac259", + "735804849b2ec0c9", + "8dfadc4705db264e", + "dd98343d69e50cbe", + "5f8457df3238fa63", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x040a2dd691fac259bf58be149cc6c661c49ba6adbea541e3163ba4e2ffbf8096": [ + "dcbcc05dd4a6d7c8", + "28c4164ae91b1916", + "a979c951e632426b", + "b4a35f4caddf10e1", + "ffb37dd5c4944a0b", + "a3ac611061859955", + "a2ceb01d96062aef", + "efef601e34dca5d6", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xb4a35f4caddf10e1a979c951e632426b28c4164ae91b1916dcbcc05dd4a6d7c8": [ + "24824d7a7031773e", + "641c96e60deb8c3c", + "2bc52d16e9585d9e", + "34c0a58d3e8490f2", + "7ce38f72debe188a", + "21a55b8604c6e510", + "d4a5f6fdf13a18ab", + "46c6b8ce3d309fb9", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x46c6b8ce3d309fb9d4a5f6fdf13a18ab21a55b8604c6e5107ce38f72debe188a": [ + "000000004b1ac8eb", + "00000000bdf692ab", + "00000000a033fdb9", + "00000000b9040dcd", + "00000000eeda9eda", + "00000000e73f7e17", + "000000009c6540ec", + "0000000051c20e01" + ], + "0xefef601e34dca5d6a2ceb01d96062aefa3ac611061859955ffb37dd5c4944a0b": [ + "16dde42596b907f0", + "49015d7e991a1528", + "4a6eced6e8304885", + "60b4d5e9af514018", + "18c9513b1e7d9904", + "0b6835f79f991d71", + "a8751b2d01a9def9", + "5bc67a31279947d0", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x5bc67a31279947d0a8751b2d01a9def90b6835f79f991d7118c9513b1e7d9904": [ + "0000000013d00000", + "00000000158e4609", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x5f8457df3238fa63dd98343d69e50cbe8dfadc4705db264e735804849b2ec0c9": [ + "d43f2781cecb9cea", + "a8ef821b2d1a19c4", + "8d39c881d94606f2", + "571c41938781a282", + "88de93befbb5aaa4", + "0daef15f24ea3e20", + "02ef2f6176cbbf97", + "69d5f78b6a46aa1d", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x571c41938781a2828d39c881d94606f2a8ef821b2d1a19c4d43f2781cecb9cea": [ + "442f7573a4097cf2", + "3520bc74612a2ea9", + "143ce4e61bf52251", + "da69a3c4a8007a5a", + "d074b8cee5dcf415", + "2346a1b4c0f390e8", + "47969c1f5a6a25b1", + "da62fdf84a21108e", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x69d5f78b6a46aa1d02ef2f6176cbbf970daef15f24ea3e2088de93befbb5aaa4": [ + "66ee2be0687eea76", + "6926f8ca8796c78a", + "26179f49c434dc16", + "649e63bfe1247ba4", + "5e83cc15f9f05fa9", + "4098e44c091c5d81", + "1a9584e1365c3ec9", + "021fc6d3425cd2f6", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x021fc6d3425cd2f61a9584e1365c3ec94098e44c091c5d815e83cc15f9f05fa9": [ + "00000000cad00000", + "00000000203b67bc", + "0000000000000035", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ] + } +} \ No newline at end of file diff --git a/tools/build-genesis-recursive/input_executor_3.json b/tools/build-genesis-recursive/input_executor_3.json new file mode 100644 index 00000000..3f60842b --- /dev/null +++ b/tools/build-genesis-recursive/input_executor_3.json @@ -0,0 +1,312 @@ +{ + "oldStateRoot": "0x9ae91f93d37e12c383702620a516c032d7e49616904c5b4a400cc486916aaa63", + "newStateRoot": "0xcce5d565437c33de2cb1154ecf7c2d949f1aee03d144d7eee717157c3ee0149e", + "oldAccInputHash": "0xad1915669aaf61a83bbfad1f4360c1a32245e38ffb67b1afa68c825135890fc9", + "newAccInputHash": "0xbd71644a8d0eff3d5ae771310c7f15c097dddffe7199e6db738479b01729abfe", + "newLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "oldNumBatch": 3, + "newNumBatch": 4, + "chainID": 1000, + "batchL2Data": "0xee01843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff883782dace9d900000808203e88080d7d8b23bdec805a0c758de3e2289077b1e4c8401ddff73c7e59e2f9351d14f5f6f04e7bbb69548737581cd5a6e3bac8695776bfd41dc1c8fc9921c4b08e008031bee02843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff8829a2241af62c0000808203e88080ee8448de88596fff6a98af2e603c9a10ccafa114815e844c8b7e8c52cb3fd1470d81101bb5a4a0aa5f459f29da0f6e95cd9e178774f0f3f1c48733618d7bd2231c", + "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", + "timestamp": 1944498032, + "sequencerAddr": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "batchHashData": "0x763d3272e66b10bef69106ea07750823c580d20802fb1141b69b5ec56790a449", + "contractsBytecode": {}, + "db": { + "0x9ae91f93d37e12c383702620a516c032d7e49616904c5b4a400cc486916aaa63": [ + "ac81a9066ee90c0d", + "657c4cf0471c465a", + "430171156248766d", + "0673c4dc9b268d54", + "7dc0c3d04f5a81c4", + "6bd8a8902ebc74bd", + "50201c606aa1c2da", + "6fc717a1999b86c8", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x0673c4dc9b268d54430171156248766d657c4cf0471c465aac81a9066ee90c0d": [ + "03eb4f3c35a91b3b", + "044d0f5794859875", + "9e577982bf760c7d", + "07fc4cd27e5f415e", + "970bdf29593fc15a", + "e6b1378a58ca7c8a", + "7252f83f498eaf89", + "c0563e997057e39a", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x07fc4cd27e5f415e9e577982bf760c7d044d0f579485987503eb4f3c35a91b3b": [ + "0febc099e7c5c454", + "924820b06dd797ec", + "fcf6522bcf657dcf", + "5ab455eaeecd090d", + "dff64fc66f6b1ba6", + "fd2c219d9b80dc18", + "9888feeb030d1bf9", + "f4f93955259cb0de", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x5ab455eaeecd090dfcf6522bcf657dcf924820b06dd797ec0febc099e7c5c454": [ + "48a46a8e735c5308", + "13c524e0f8adc42e", + "27103a7e24638570", + "85bf62d5f65b9449", + "cad6cdbfa198be91", + "cd0e941b466a39b4", + "a7e6b3f9d3f197d5", + "a2135065f1605059", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xa2135065f1605059a7e6b3f9d3f197d5cd0e941b466a39b4cad6cdbfa198be91": [ + "0000000000000003", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xf4f93955259cb0de9888feeb030d1bf9fd2c219d9b80dc18dff64fc66f6b1ba6": [ + "780709cc8c2462a2", + "3931e3690ee68019", + "185093e495fe78c5", + "67d3fbfba0e1bb5e", + "715108b4ad8fad63", + "20241246bd28c180", + "e7a0f3d56104a4d8", + "717570988acd6670", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x717570988acd6670e7a0f3d56104a4d820241246bd28c180715108b4ad8fad63": [ + "000000001b0cf8c2", + "00000000a3a2c741", + "0000000037ef9d32", + "000000009bca91ab", + "000000005b0d4b6d", + "000000008c1d0ea2", + "000000006ff95f73", + "00000000d3dec90c" + ], + "0xc0563e997057e39a7252f83f498eaf89e6b1378a58ca7c8a970bdf29593fc15a": [ + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "36fbd59753b7e63e", + "873daf7980590ee1", + "78cb98b9b7fe9e23", + "8c6d0251b958a83a", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x8c6d0251b958a83a78cb98b9b7fe9e23873daf7980590ee136fbd59753b7e63e": [ + "7a194b0c3917f8de", + "179ddf2d5e23e97e", + "e838cfb3d5459971", + "2bcd4a01e4e9ac1a", + "ab1b9a26192a2153", + "1d4b94cd658e8474", + "3ec02b72c520c8b1", + "6e4beb40a404c6b2", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x2bcd4a01e4e9ac1ae838cfb3d5459971179ddf2d5e23e97e7a194b0c3917f8de": [ + "6f0cd9b7cb0ef911", + "5ac4a699725dc2e0", + "6bf2c9fd6a3aa16c", + "325ba19f4ab866aa", + "cad6cdbfa198be91", + "cd0e941b466a39b4", + "a7e6b3f9d3f197d5", + "a2135065f1605059", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x6e4beb40a404c6b23ec02b72c520c8b11d4b94cd658e8474ab1b9a26192a2153": [ + "39a943c2fe744496", + "6b626398c962019e", + "782af11b572be2a1", + "3a80ee3ca786fd17", + "f8648c3a41a08f35", + "13bd9ffae10d8a64", + "276b4a2cc1fd0fb1", + "3a2cbe72639d4982", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x3a2cbe72639d4982276b4a2cc1fd0fb113bd9ffae10d8a64f8648c3a41a08f35": [ + "00000000c19f9026", + "00000000609832bb", + "00000000db465efb", + "000000006cbc8baa", + "0000000015d1234f", + "0000000050c89a8d", + "000000005b419d1c", + "000000003ca39a7b" + ], + "0x6fc717a1999b86c850201c606aa1c2da6bd8a8902ebc74bd7dc0c3d04f5a81c4": [ + "1523a65ab5f5b2bb", + "40e72f81b26308bf", + "86e8309a8e90844a", + "b19c9cb8444738d7", + "99d18649b58e3b76", + "32671ba72618ac58", + "0e57387f8f6dbe16", + "46a388c8ab7ab4a1", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xb19c9cb8444738d786e8309a8e90844a40e72f81b26308bf1523a65ab5f5b2bb": [ + "dcbcc05dd4a6d7c8", + "28c4164ae91b1916", + "a979c951e632426b", + "b4a35f4caddf10e1", + "14eada4858715e40", + "f980d1fedc728158", + "a9a1b04bf5cd5d6f", + "edcb391353295f0c", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xb4a35f4caddf10e1a979c951e632426b28c4164ae91b1916dcbcc05dd4a6d7c8": [ + "24824d7a7031773e", + "641c96e60deb8c3c", + "2bc52d16e9585d9e", + "34c0a58d3e8490f2", + "7ce38f72debe188a", + "21a55b8604c6e510", + "d4a5f6fdf13a18ab", + "46c6b8ce3d309fb9", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x46c6b8ce3d309fb9d4a5f6fdf13a18ab21a55b8604c6e5107ce38f72debe188a": [ + "000000004b1ac8eb", + "00000000bdf692ab", + "00000000a033fdb9", + "00000000b9040dcd", + "00000000eeda9eda", + "00000000e73f7e17", + "000000009c6540ec", + "0000000051c20e01" + ], + "0xedcb391353295f0ca9a1b04bf5cd5d6ff980d1fedc72815814eada4858715e40": [ + "16dde42596b907f0", + "49015d7e991a1528", + "4a6eced6e8304885", + "60b4d5e9af514018", + "90e98ea2a6fee2b3", + "09b4104e4b0f1f42", + "3c656749691cf3af", + "4b1d11a97ceff72f", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x4b1d11a97ceff72f3c656749691cf3af09b4104e4b0f1f4290e98ea2a6fee2b3": [ + "00000000c5080000", + "00000000f9ccd8a1", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x46a388c8ab7ab4a10e57387f8f6dbe1632671ba72618ac5899d18649b58e3b76": [ + "d43f2781cecb9cea", + "a8ef821b2d1a19c4", + "8d39c881d94606f2", + "571c41938781a282", + "2b6429747753e992", + "8de937d8391bc07c", + "0ba2467e6b2a03b8", + "43ce72d79779e851", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x571c41938781a2828d39c881d94606f2a8ef821b2d1a19c4d43f2781cecb9cea": [ + "442f7573a4097cf2", + "3520bc74612a2ea9", + "143ce4e61bf52251", + "da69a3c4a8007a5a", + "d074b8cee5dcf415", + "2346a1b4c0f390e8", + "47969c1f5a6a25b1", + "da62fdf84a21108e", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0xda62fdf84a21108e47969c1f5a6a25b12346a1b4c0f390e8d074b8cee5dcf415": [ + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x43ce72d79779e8510ba2467e6b2a03b88de937d8391bc07c2b6429747753e992": [ + "66ee2be0687eea76", + "6926f8ca8796c78a", + "26179f49c434dc16", + "649e63bfe1247ba4", + "67bbfffd0982dfa4", + "93c661c88448b5ed", + "cec2687622ccc942", + "4e709c8e17913749", + "0000000000000001", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ], + "0x4e709c8e17913749cec2687622ccc94293c661c88448b5ed67bbfffd0982dfa4": [ + "0000000019980000", + "000000003bfcd524", + "0000000000000035", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000", + "0000000000000000" + ] + } +} \ No newline at end of file diff --git a/tools/build-genesis-recursive/input_gen_recursive.json b/tools/build-genesis-recursive/input_gen_recursive.json new file mode 100644 index 00000000..6ebe009e --- /dev/null +++ b/tools/build-genesis-recursive/input_gen_recursive.json @@ -0,0 +1,139 @@ +{ + "genesis": [ + { + "address": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "nonce": "0", + "balance": "1000000000000000000000", + "pvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e" + }, + { + "address": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", + "nonce": "0", + "balance": "0", + "pvtKey": "0x4d27a600dce8c29b7bd080e29a26972377dbb04d7a27d919adbb602bf13cfd23" + } + ], + "chainID": 1000, + "aggregatorAddress": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", + "batches": [ + { + "sequencerAddr": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", + "timestamp": 1944498031, + "contractsBytecode": {}, + "txs": [ + { + "from": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "to": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", + "nonce": 0, + "value": "22000000000000000000", + "gasLimit": 100000, + "gasPrice": "1000000000", + "chainId": 1000 + } + ] + }, + { + "sequencerAddr": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", + "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", + "timestamp": 1944498032, + "contractsBytecode": {}, + "txs": [ + { + "from": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", + "to": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "nonce": 0, + "value": "2000000000000000000", + "gasLimit": 100000, + "gasPrice": "1000000000", + "chainId": 1000 + } + ] + }, + { + "sequencerAddr": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", + "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", + "timestamp": 1944498032, + "contractsBytecode": {}, + "txs": [ + { + "from": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", + "to": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "nonce": 1, + "value": "1000000000000000000", + "gasLimit": 100000, + "gasPrice": "1000000000", + "chainId": 1000 + }, + { + "from": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", + "to": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "nonce": 2, + "value": "1000000000000000000", + "gasLimit": 100000, + "gasPrice": "1000000000", + "chainId": 1000 + } + ] + }, + { + "sequencerAddr": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", + "timestamp": 1944498032, + "contractsBytecode": {}, + "txs": [ + { + "from": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "to": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", + "nonce": 1, + "value": "4000000000000000000", + "gasLimit": 100000, + "gasPrice": "1000000000", + "chainId": 1000 + }, + { + "from": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "to": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", + "nonce": 2, + "value": "3000000000000000000", + "gasLimit": 100000, + "gasPrice": "1000000000", + "chainId": 1000 + } + ] + } + ], + "expectedLeafs": { + "0x0000000000000000000000000000000000000000": { + "balance": "0", + "nonce": "0", + "storage": { + "0x101e368776582e57ab3d116ffe2517c0a585cd5b23174b01e275c2d8329c3d83": "0x9ae91f93d37e12c383702620a516c032d7e49616904c5b4a400cc486916aaa63", + "0xabbb5caa7dda850e60932de0934eb1f9d0f59695050f761dc64e443e5030a569": "0xd3dec90c6ff95f738c1d0ea25b0d4b6d9bca91ab37ef9d32a3a2c7411b0cf8c2", + "0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5": "0x3ca39a7b5b419d1c50c89a8d15d1234f6cbc8baadb465efb609832bbc19f9026", + "0xada5013122d395ba3c54772283fb069b10426056ef8ca54750cb9bb552a59e7d": "0x51c20e019c6540ece73f7e17eeda9edab9040dcda033fdb9bdf692ab4b1ac8eb" + }, + "hashBytecode": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + "0xae4bb80be56b819606589de61d5ec3b522eeb032": { + "balance": "0", + "nonce": "0", + "storage": { + "0x53d3f126103a7f7d6245751d2392e0245bf71479d10a3c27a5b501ace6dde1b7": "0x04" + }, + "hashBytecode": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + "0x617b3a3528f9cdd6630fd3301b9c8911f7bf063d": { + "balance": "975000000000000000000", + "nonce": "3", + "storage": null, + "hashBytecode": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + "0x4d5cf5032b2a844602278b01199ed191a86c93ff": { + "balance": "25000000000000000000", + "nonce": "3", + "storage": null, + "hashBytecode": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + } +} \ No newline at end of file diff --git a/tools/build-genesis/build_genesis.js b/tools/build-genesis/build_genesis.js index 61877ebf..d2abcc69 100644 --- a/tools/build-genesis/build_genesis.js +++ b/tools/build-genesis/build_genesis.js @@ -45,12 +45,11 @@ async function main(){ // create a zkEVMDB and build a batch const db = new MemDB(F); - const zkEVMDB = await ZkEVMDB.newZkEVM( db, poseidon, [F.zero, F.zero, F.zero, F.zero], // empty smt - smtUtils.stringToH4(generateData.oldLocalExitRoot), + smtUtils.stringToH4(generateData.oldAccInputHash), generateData.genesis, null, null, @@ -74,8 +73,6 @@ async function main(){ // get stark input const starkInput = await batch.getStarkInput(); - delete starkInput.inputHash; - delete starkInput.batchHashData; // print new states const updatedAccounts = batch.getUpdatedAccountsBatch(); diff --git a/tools/build-genesis/input_executor.json b/tools/build-genesis/input_executor.json index 84d00038..7efefa39 100644 --- a/tools/build-genesis/input_executor.json +++ b/tools/build-genesis/input_executor.json @@ -1,40 +1,24 @@ { - "oldStateRoot": "0x2dc4db4293af236cb329700be43f08ace740a05088f8c7654736871709687e90", - "chainId": 1001, + "oldStateRoot": "0x3ca39a7b5b419d1c50c89a8d15d1234f6cbc8baadb465efb609832bbc19f9026", + "newStateRoot": "0x892742ae37044a99aeae16d98e54d788b8114aaa073c46b685bcc3e21e6b5921", + "oldAccInputHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "newAccInputHash": "0x21db0483a0ff157e55b26413da95a77328e68de50f0314e9148277272002051b", + "newLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "oldNumBatch": 0, + "newNumBatch": 1, + "chainID": 1000, + "batchL2Data": "0xee80843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff8829a2241af62c0000808203e8808030b042c001e60b5e93c5d20786896d6ee49161492162f0f2a06fbaa4e74e94d779539c219adbb6bacf96dd0d10a44b1e30cade645363216f77b7938c2437ed391c", + "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", + "timestamp": 1944498031, + "sequencerAddr": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", + "batchHashData": "0xd66c1d128f14f032913ef2f21a06ec02ff389fc47c5b80f0acfb1262e80eadd7", + "contractsBytecode": {}, "db": { - "0x2dc4db4293af236cb329700be43f08ace740a05088f8c7654736871709687e90": [ - "0000000000000000", - "0000000000000000", - "0000000000000000", - "0000000000000000", - "0d1f0da5a7b620c8", - "43fd1e18e59fd724", - "d428d25da0cb1888", - "e31f5542ac227c06", - "0000000000000000", - "0000000000000000", - "0000000000000000", - "0000000000000000" - ], - "0xe31f5542ac227c06d428d25da0cb188843fd1e18e59fd7240d1f0da5a7b620c8": [ - "ed22ec7734d89ff2", - "b2e639153607b7c5", - "42b2bd6ec2788851", - "b781932941084783", - "3e63658ee0db910d", - "0b3e34316e81aa10", - "e0dc203d93f4e3e5", - "e10053d0ebc64602", - "0000000000000000", - "0000000000000000", - "0000000000000000", - "0000000000000000" - ], - "0xb78193294108478342b2bd6ec2788851b2e639153607b7c5ed22ec7734d89ff2": [ - "16dde42596b907f0", - "49015d7e991a1528", - "94dd9dadd060910b", - "60b4d5e9af514018", + "0x3ca39a7b5b419d1c50c89a8d15d1234f6cbc8baadb465efb609832bbc19f9026": [ + "cddc57c0d0fdd4ed", + "d24df1950f2d8f15", + "4c2f3e938869b82d", + "649e63bfe1247ba4", "b69b044f5e694795", "f57d81efba5d4445", "339438195426ad0a", @@ -53,30 +37,6 @@ "0000000000000000", "0000000000000000", "0000000000000000" - ], - "0xe10053d0ebc64602e0dc203d93f4e3e50b3e34316e81aa103e63658ee0db910d": [ - "66ee2be0687eea76", - "6926f8ca8796c78a", - "4c2f3e938869b82d", - "649e63bfe1247ba4", - "b69b044f5e694795", - "f57d81efba5d4445", - "339438195426ad0a", - "3efad1dd58c2259d", - "0000000000000001", - "0000000000000000", - "0000000000000000", - "0000000000000000" ] - }, - "sequencerAddr": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", - "batchL2Data": "0xee80843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff88016345785d8a0000808203e880801cee7e01dc62f69a12c3510c6d64de04ee6346d84b6a017f3e786c7d87f963e75d8cc91fa983cd6d9cf55fff80d73bd26cd333b0f098acc1e58edb1fd484ad731b", - "newStateRoot": "0xbff23fc2c168c033aaac77503ce18f958e9689d5cdaebb88c5524ce5c0319de3", - "oldLocalExitRoot": "0x17c04c3760510b48c6012742c540a81aba4bca2f78b9d14bfd2f123e2e53ea3e", - "newLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", - "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", - "numBatch": 1, - "timestamp": 1944498031, - "chainID": 1000, - "contractsBytecode": {} + } } \ No newline at end of file diff --git a/tools/build-genesis/input_gen.json b/tools/build-genesis/input_gen.json index ecd31629..a7b6ca62 100644 --- a/tools/build-genesis/input_gen.json +++ b/tools/build-genesis/input_gen.json @@ -9,7 +9,7 @@ { "address": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", "nonce": "0", - "balance": "1000000000000000000000", + "balance": "0", "pvtKey": "0x4d27a600dce8c29b7bd080e29a26972377dbb04d7a27d919adbb602bf13cfd23" } ], @@ -17,14 +17,15 @@ "from": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "to": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", "nonce": 0, - "value": "100000000000000000", + "value": "3000000000000000000", "gasLimit": 100000, "gasPrice": "1000000000", "chainId": 1000 }, "sequencerAddr": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "newStateRoot": "0x233b53c98ba14bd95f362ceaace6bde63ee22920ff2ab0638f66472037186420", - "oldLocalExitRoot": "0x17c04c3760510b48c6012742c540a81aba4bca2f78b9d14bfd2f123e2e53ea3e", + "oldAccInputHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "newAccInputHash": "0x17c04c3760510b48c6012742c540a81aba4bca2f78b9d14bfd2f123e2e53ea3e", "globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", "numBatch": 1, "timestamp": 1944498031, @@ -35,7 +36,7 @@ "balance": "0", "nonce": "0", "storage": { - "0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5": "0x2dc4db4293af236cb329700be43f08ace740a05088f8c7654736871709687e90" + "0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5": "0x3ca39a7b5b419d1c50c89a8d15d1234f6cbc8baadb465efb609832bbc19f9026" }, "hashBytecode": "0x0000000000000000000000000000000000000000000000000000000000000000" }, @@ -48,13 +49,13 @@ "hashBytecode": "0x0000000000000000000000000000000000000000000000000000000000000000" }, "0x617b3a3528f9cdd6630fd3301b9c8911f7bf063d": { - "balance": "999900000000000000000", + "balance": "997000000000000000000", "nonce": "1", "storage": null, "hashBytecode": "0x0000000000000000000000000000000000000000000000000000000000000000" }, "0x4d5cf5032b2a844602278b01199ed191a86c93ff": { - "balance": "1000100000000000000000", + "balance": "3000000000000000000", "nonce": "0", "storage": null, "hashBytecode": "0x0000000000000000000000000000000000000000000000000000000000000000" diff --git a/tools/build_all.sh b/tools/build_all.sh index 83b8b43e..9acf0e0e 100755 --- a/tools/build_all.sh +++ b/tools/build_all.sh @@ -1,6 +1,8 @@ . $PWD/pre.sh +[ ! -z $npm_config_steps ] && while [ $# -gt 0 ]; do echo $1; shift; done && exit 1; + SKIP=0 -START_OPTIONS=`env|grep -wE '(npm_config_pil|npm_config_pil|npm_config_continue|npm_config_from|npm_config_build|npm_config_starkstruct)'|sed 's/npm_config_//g'|xargs` +START_OPTIONS=`env|grep -wE 'npm_config_(pil|pilconfig|continue|from|build|starkstruct)'|sed 's/npm_config_//g'|xargs` echo "####### START $(date +'%Y-%m-%d %H:%M:%S') $START_OPTIONS ########" >> $BDIR/steps.log LAST_STEP_FILE=$BDIR/last_step.txt [ ! -z $npm_config_from ] && SKIP=1