Skip to content

Commit

Permalink
EVM Simulator code hash in witness data (#249)
Browse files Browse the repository at this point in the history
* Add evm simulator bytecode hash to the witness input data

* Add evm simulator code hash to the test harness run

* Fix error message for evm simulator not present in witness data
  • Loading branch information
IAvecilla authored Aug 30, 2024
1 parent 4c11c21 commit f927c26
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/lib/prover_interface/src/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub struct VMRunWitnessInputData {
pub protocol_version: ProtocolVersionId,
pub bootloader_code: Vec<[u8; 32]>,
pub default_account_code_hash: U256,
pub evm_simulator_code_hash: U256,
pub storage_refunds: Vec<u32>,
pub pubdata_costs: Vec<i32>,
pub witness_block_state: WitnessStorageState,
Expand Down
18 changes: 18 additions & 0 deletions core/node/vm_runner/src/impls/bwip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ async fn get_updates_manager_witness_input_data(
let initial_heap_content = finished_batch.final_bootloader_memory.unwrap(); // might be just empty
let default_aa = updates_manager.base_system_contract_hashes().default_aa;
let bootloader = updates_manager.base_system_contract_hashes().bootloader;
let evm_simulator = updates_manager.base_system_contract_hashes().evm_simulator;
let bootloader_code_bytes = connection
.factory_deps_dal()
.get_sealed_factory_dep(bootloader)
Expand All @@ -220,6 +221,14 @@ async fn get_updates_manager_witness_input_data(
.ok_or_else(|| anyhow!("Default account bytecode should exist"))?;
let account_bytecode = bytes_to_chunks(&account_bytecode_bytes);

let evm_simulator_code_hash = h256_to_u256(evm_simulator);
let simulator_bytecode_bytes = connection
.factory_deps_dal()
.get_sealed_factory_dep(evm_simulator)
.await?
.ok_or_else(|| anyhow!("EVM Simulator bytecode should exist"))?;
let evm_simulator_bytecode = bytes_to_chunks(&simulator_bytecode_bytes);

let hashes: HashSet<H256> = finished_batch
.final_execution_state
.used_contract_hashes
Expand All @@ -240,6 +249,14 @@ async fn get_updates_manager_witness_input_data(
used_bytecodes.insert(account_code_hash, account_bytecode);
}

if finished_batch
.final_execution_state
.used_contract_hashes
.contains(&evm_simulator_code_hash)
{
used_bytecodes.insert(evm_simulator_code_hash, evm_simulator_bytecode);
}

let storage_refunds = finished_batch.final_execution_state.storage_refunds;
let pubdata_costs = finished_batch.final_execution_state.pubdata_costs;

Expand All @@ -261,6 +278,7 @@ async fn get_updates_manager_witness_input_data(

bootloader_code,
default_account_code_hash: account_code_hash,
evm_simulator_code_hash: evm_simulator_code_hash,
storage_refunds,
pubdata_costs,
witness_block_state,
Expand Down
3 changes: 1 addition & 2 deletions prover/crates/bin/witness_generator/src/basic_circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,7 @@ async fn generate_witness(
bootloader_contents,
false,
input.vm_run_data.default_account_code_hash,
// NOTE: this will be evm_simulator_code_hash in future releases
input.vm_run_data.default_account_code_hash,
input.vm_run_data.evm_simulator_code_hash,
input.vm_run_data.used_bytecodes,
Vec::default(),
MAX_CYCLES_FOR_TX as usize,
Expand Down

0 comments on commit f927c26

Please sign in to comment.