From 13d303fb9e80a206e9418340b4fd88e4809779e9 Mon Sep 17 00:00:00 2001 From: Stephen <81497928+eigmax@users.noreply.github.com> Date: Thu, 25 Apr 2024 01:36:28 +0800 Subject: [PATCH] fix: missing witness (#247) --- zkvm/src/lib.rs | 41 ++++++++-- zkvm/test-vectors/reth.block.json | 125 ++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+), 6 deletions(-) create mode 100644 zkvm/test-vectors/reth.block.json diff --git a/zkvm/src/lib.rs b/zkvm/src/lib.rs index dc84f527..3882352a 100644 --- a/zkvm/src/lib.rs +++ b/zkvm/src/lib.rs @@ -212,6 +212,7 @@ pub fn zkvm_prove_only( task: &str, suite_json: &String, bootloader_input: Vec, + start_of_shutdown_routine: u64, i: usize, output_path: &str, ) -> Result<()> { @@ -232,6 +233,7 @@ pub fn zkvm_prove_only( pipeline.clone(), generate_witness_and_prove, bootloader_input, + start_of_shutdown_routine, i, ) .unwrap(); @@ -257,6 +259,7 @@ pub fn rust_continuation( mut pipeline: Pipeline, pipeline_callback: PipelineCallback, bootloader_inputs: Vec, + start_of_shutdown_routine: u64, i: usize, ) -> Result<(), E> where @@ -266,13 +269,24 @@ where // in which case this will be a no-op. pipeline.compute_fixed_cols().unwrap(); + // we can assume optimized_pil has been computed + let length = pipeline.compute_optimized_pil().unwrap().degree(); + log::info!("\nRunning chunk {}...", i + 1); let name = format!("{}_chunk_{}", pipeline.name(), i); let pipeline = pipeline.with_name(name); - let pipeline = pipeline.add_external_witness_values(vec![( - "main.bootloader_input_value".to_string(), - bootloader_inputs, - )]); + + let jump_to_shutdown_routine = (0..length) + .map(|i| (i == start_of_shutdown_routine - 1).into()) + .collect(); + + let pipeline = pipeline.add_external_witness_values(vec![ + ("main.bootloader_input_value".to_string(), bootloader_inputs), + ( + "main.jump_to_shutdown_routine".to_string(), + jump_to_shutdown_routine, + ), + ]); pipeline_callback(pipeline)?; Ok(()) } @@ -289,7 +303,7 @@ mod tests { fn test_zkvm_prove() { env_logger::try_init().unwrap_or_default(); //let test_file = "test-vectors/blockInfo.json"; - let test_file = "test-vectors/solidityExample.json"; + let test_file = "test-vectors/reth.block.json"; let suite_json = fs::read_to_string(test_file).unwrap(); zkvm_execute_and_prove("evm", suite_json, "/tmp/test_evm").unwrap(); @@ -328,6 +342,8 @@ mod tests { .zip(&bi_files) .for_each(|(data, filename)| { let mut f = fs::File::create(filename).unwrap(); + // write the start_of_shutdown_routine + f.write_all(&data.1.to_le_bytes()).unwrap(); for d in &data.0 { f.write_all(&d.to_bytes_le()[0..8]).unwrap(); } @@ -339,6 +355,11 @@ mod tests { let metadata = fs::metadata(filename).unwrap(); let file_size = metadata.len() as usize; assert!(file_size % 8 == 0); + // read the start_of_shutdown_routine + let mut buffer = [0u8; 8]; + f.read_exact(&mut buffer).unwrap(); + let start_of_shutdown_routine: u64 = u64::from_le_bytes(buffer); + let mut buffer = vec![0; file_size]; f.read_exact(&mut buffer).unwrap(); let mut bi = vec![GoldilocksField::zero(); file_size / 8]; @@ -346,7 +367,15 @@ mod tests { *out = GoldilocksField::from_bytes_le(bin); }); - zkvm_prove_only(task, &suite_json, bi, i, output_path).unwrap(); + zkvm_prove_only( + task, + &suite_json, + bi, + start_of_shutdown_routine, + i, + output_path, + ) + .unwrap(); }); } } diff --git a/zkvm/test-vectors/reth.block.json b/zkvm/test-vectors/reth.block.json new file mode 100644 index 00000000..19801f77 --- /dev/null +++ b/zkvm/test-vectors/reth.block.json @@ -0,0 +1,125 @@ +{ + "_info" : { + "comment" : "An example test for using solidity contracts in the test", + "filling-rpc-server" : "evm version 1.13.5-unstable-cd295356-20231019", + "filling-tool-version" : "retesteth-0.3.1-cancun+commit.1e18e0b3.Linux.g++", + "generatedTestHash" : "0399c9dfe5ca653c12acc8d456c0f2269c2729d58f33a57de51c91e0c00369b0", + "lllcversion" : "Version: 0.5.14-develop.2023.7.11+commit.c58ab2c6.mod.Linux.g++", + "solidity" : "Version: 0.8.21+commit.d9974bed.Linux.g++", + "source" : "src/GeneralStateTestsFiller/stExample/solidityExampleFiller.yml", + "sourceHash" : "60e5392c4099d5c8c579ba3ce3f05c8faffeead41925f79de6ed1d387f66cf2a" + }, + "env" : { + "currentBaseFee" : "0x0a", + "currentBeaconRoot" : "0x0000000000000000000000000000000000000000000000000000000000000000", + "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "0x020000", + "currentGasLimit" : "0x05f5e100", + "currentNumber" : "0x01", + "currentRandom" : "0x0000000000000000000000000000000000000000000000000000000000020000", + "currentTimestamp" : "0x03e8", + "currentWithdrawalsRoot" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "previousHash" : "0x5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "post" : { + "Berlin" : [ + { + "hash" : "0xc26f19544c8e93490662b809f638843807eaef1d0fce8c241a8f4f6b8d28f4a6", + "indexes" : { + "data" : 0, + "gas" : 0, + "value" : 0 + }, + "logs" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "txbytes" : "0xf8a6800a8404c4b40094095e7baea6a6c7c4c2dfeb977efac326af552d8780b844b66176a7000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000451ca0557b882a6f4c398e1dc30731cc0490f9743d2df3a13b9e465a87198920d34877a071659dc2b9ff195215e075315734b937a7773e470d47d33cdca183b1bc4093a7" + } + ], + "Cancun" : [ + { + "hash" : "0x5f8676a3ac2d43a2172a5b8871148b55031c73fbb058788e862b5844db5b9fe2", + "indexes" : { + "data" : 0, + "gas" : 0, + "value" : 0 + }, + "logs" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "txbytes" : "0xf8a6800a8404c4b40094095e7baea6a6c7c4c2dfeb977efac326af552d8780b844b66176a7000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000451ca0557b882a6f4c398e1dc30731cc0490f9743d2df3a13b9e465a87198920d34877a071659dc2b9ff195215e075315734b937a7773e470d47d33cdca183b1bc4093a7" + } + ], + "London" : [ + { + "hash" : "0x0b200a8b3d0369aab33ab2e9407352efd5e4db581ea31c2dae4cae6dc4780b6b", + "indexes" : { + "data" : 0, + "gas" : 0, + "value" : 0 + }, + "logs" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "txbytes" : "0xf8a6800a8404c4b40094095e7baea6a6c7c4c2dfeb977efac326af552d8780b844b66176a7000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000451ca0557b882a6f4c398e1dc30731cc0490f9743d2df3a13b9e465a87198920d34877a071659dc2b9ff195215e075315734b937a7773e470d47d33cdca183b1bc4093a7" + } + ], + "Merge" : [ + { + "hash" : "0x0b200a8b3d0369aab33ab2e9407352efd5e4db581ea31c2dae4cae6dc4780b6b", + "indexes" : { + "data" : 0, + "gas" : 0, + "value" : 0 + }, + "logs" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "txbytes" : "0xf8a6800a8404c4b40094095e7baea6a6c7c4c2dfeb977efac326af552d8780b844b66176a7000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000451ca0557b882a6f4c398e1dc30731cc0490f9743d2df3a13b9e465a87198920d34877a071659dc2b9ff195215e075315734b937a7773e470d47d33cdca183b1bc4093a7" + } + ], + "Shanghai" : [ + { + "hash" : "0x5f8676a3ac2d43a2172a5b8871148b55031c73fbb058788e862b5844db5b9fe2", + "indexes" : { + "data" : 0, + "gas" : 0, + "value" : 0 + }, + "logs" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "txbytes" : "0xf8a6800a8404c4b40094095e7baea6a6c7c4c2dfeb977efac326af552d8780b844b66176a7000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000451ca0557b882a6f4c398e1dc30731cc0490f9743d2df3a13b9e465a87198920d34877a071659dc2b9ff195215e075315734b937a7773e470d47d33cdca183b1bc4093a7" + } + ] + }, + "pre" : { + "0x095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "0x0ba1a9ce0ba1a9ce", + "code" : "0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063b66176a714610030575b600080fd5b61004a6004803603810190610045919061018d565b61004c565b005b60405161005890610145565b604051809103906000f080158015610074573d6000803e3d6000fd5b506000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663b66176a783836040518363ffffffff1660e01b815260040161010f9291906101dc565b600060405180830381600087803b15801561012957600080fd5b505af115801561013d573d6000803e3d6000fd5b505050505050565b6101238061020683390190565b600080fd5b6000819050919050565b61016a81610157565b811461017557600080fd5b50565b60008135905061018781610161565b92915050565b600080604083850312156101a4576101a3610152565b5b60006101b285828601610178565b92505060206101c385828601610178565b9150509250929050565b6101d681610157565b82525050565b60006040820190506101f160008301856101cd565b6101fe60208301846101cd565b939250505056fe608060405267ff00ff00ff00ff0060005534801561001c57600080fd5b5060f88061002b6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063b66176a714602d575b600080fd5b60436004803603810190603f91906089565b6045565b005b806000819055508082555050565b600080fd5b6000819050919050565b6069816058565b8114607357600080fd5b50565b6000813590506083816062565b92915050565b60008060408385031215609d57609c6053565b5b600060a9858286016076565b925050602060b8858286016076565b915050925092905056fea26469706673582212207ef6639e6ef1a4fcfafe5795cba00e5014f2c3dcce14fcb66c82160e8ceb425264736f6c63430008150033a2646970667358221220ef8e499a007975fa5ce38c54c764357529d8e48b99f30e4dd47bd3047efef65d64736f6c63430008150033", + "nonce" : "0x00", + "storage" : { + } + }, + "0x195e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "0x0ba1a9ce0ba1a9ce", + "code" : "0x6080604052348015600e575f80fd5b50600436106026575f3560e01c8063b66176a714602a575b5f80fd5b60406004803603810190603c91906081565b6042565b005b805f819055508082555050565b5f80fd5b5f819050919050565b6063816053565b8114606c575f80fd5b50565b5f81359050607b81605c565b92915050565b5f80604083850312156094576093604f565b5b5f609f85828601606f565b925050602060ae85828601606f565b915050925092905056fea26469706673582212205852a937f3e72e48c0a57651869e7bf80b6d074df8ba6e6a6cefbeada0c290ae64736f6c63430008150033", + "nonce" : "0x00", + "storage" : { + } + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0x0ba1a9ce0ba1a9ce", + "code" : "0x", + "nonce" : "0x00", + "storage" : { + } + } + }, + "transaction" : { + "data" : [ + "0xb66176a700000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000045" + ], + "gasLimit" : [ + "0x04c4b400" + ], + "gasPrice" : "0x0a", + "nonce" : "0x00", + "secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "sender" : "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "to" : "0x095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : [ + "0x00" + ] + } +}