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..6492cde7 --- /dev/null +++ b/zkvm/test-vectors/reth.block.json @@ -0,0 +1,97 @@ +{ + "_info": null, + "chain_id": 12345, + "env": { + "currentCoinbase": "0x0000000000000000000000000000000000000000", + "currentDifficulty": "0x2", + "currentGasLimit": "0x1c9c380", + "currentNumber": "0x1", + "currentTimestamp": "0x6611201e", + "currentBaseFee": "0x342770c0", + "previousHash": "0x342c4358e0b7a7e5f040a3bdda3a51d21416c4a6cdff209379e1454d22b72faf", + "currentRandom": "0x0000000000000000000000000000000000000000000000000000000000000000", + "currentBeaconRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "currentWithdrawalsRoot": null, + "parentBlobGasUsed": "0x5208", + "parentExcessBlobGas": "0x5208" + }, + "pre": { + "0x540ea708597d8e46cb33be43139452d8c9583686": { + "balance": "0x4a47e3c12448f4ad000000", + "code": "0x", + "nonce": "0x0", + "storage": {} + }, + "0x6831fb06762332dca543c0f2b5795692d896e3d4": { + "balance": "0x4a47e3c12448f4ad000000", + "code": "0x", + "nonce": "0x0", + "storage": {} + }, + "0x0000000000000000000000000000000000000000": { + "balance": "0x0", + "code": "0x", + "nonce": "0x0", + "storage": {} + } + }, + "post": { + "Shanghai": [ + { + "expectException": null, + "indexes": { + "data": 0, + "gas": 0, + "value": 0 + }, + "hash": "0xebd0f311f8f057157864244e8e7ec6e8d5b29b2c5e8f07a93d456535e49897cb", + "postState": { + "0x540ea708597d8e46cb33be43139452d8c9583686": { + "balance": "0x4a47e3bfc0b979b77e0a00", + "code": "0x", + "nonce": "0x1", + "storage": {} + }, + "0x6831fb06762332dca543c0f2b5795692d896e3d4": { + "balance": "0x4a47e3c2878e6d0a8a0000", + "code": "0x", + "nonce": "0x0", + "storage": {} + }, + "0x0000000000000000000000000000000000000000": { + "balance": "0x394c549ef000", + "code": "0x00", + "nonce": "0x0", + "storage": {} + } + }, + "logs": "0x0000000000000000000000000000000000000000000000000000000000000000", + "txbytes": "0x7b2263616c6c6572223a22307835343065613730383539376438653436636233336265343331333934353264386339353833363836222c226761735f6c696d6974223a32313030302c226761735f7072696365223a2230786536663763656330222c227472616e736163745f746f223a7b2243616c6c223a22307836383331666230363736323333326463613534336330663262353739353639326438393665336434227d2c2276616c7565223a223078313633343537383564386130303030222c2264617461223a223078222c226e6f6e6365223a302c22636861696e5f6964223a31323334352c226163636573735f6c697374223a5b5d2c226761735f7072696f726974795f666565223a2230786232643035653030222c22626c6f625f686173686573223a5b5d2c226d61785f6665655f7065725f626c6f625f676173223a6e756c6c7d" + } + ] + }, + "transaction": { + "data": [ + "0x" + ], + "gasLimit": [ + "0x1c9c380" + ], + "gasPrice": "0xe6f7cec0", + "nonce": "0x0", + "secretKey": "0x0000000000000000000000000000000000000000000000000000000000000000", + "sender": "0x540ea708597d8e46cb33be43139452d8c9583686", + "to": "0x6831fb06762332dca543c0f2b5795692d896e3d4", + "value": [ + "0x16345785d8a0000" + ], + "maxFeePerGas": "0x12a05f200", + "maxPriorityFeePerGas": "0xb2d05e00", + "accessLists": [ + [] + ], + "blobVersionedHashes": [], + "maxFeePerBlobGas": null + }, + "out": null +}