From 4e72154f4f634f3932d9821daafc958dec2b4ecb Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Mon, 23 Sep 2024 10:14:35 +0000 Subject: [PATCH 1/9] feat(avm)!: GETENVVAR + ISSTATICCALL --- avm-transpiler/src/opcodes.rs | 31 +--- avm-transpiler/src/transpile.rs | 56 ++++-- .../src/barretenberg/vm/aztec_constants.hpp | 27 +-- .../context/inputs/public_context_inputs.nr | 1 + .../aztec/src/context/public_context.nr | 9 + .../crates/types/src/constants.nr | 27 +-- .../aztec_macros/src/transforms/functions.rs | 4 +- yarn-project/circuits.js/src/constants.gen.ts | 27 +-- yarn-project/simulator/src/avm/avm_gas.ts | 28 +-- .../src/avm/opcodes/context_getters.test.ts | 31 ---- .../src/avm/opcodes/context_getters.ts | 23 --- .../avm/opcodes/environment_getters.test.ts | 86 ++++----- .../src/avm/opcodes/environment_getters.ts | 171 ++++++++---------- .../src/avm/opcodes/external_calls.test.ts | 7 +- .../simulator/src/avm/opcodes/index.ts | 3 + .../src/avm/opcodes/instruction_impl.ts | 27 --- .../bytecode_serialization.test.ts | 12 +- .../serialization/bytecode_serialization.ts | 42 +---- .../instruction_serialization.ts | 15 +- 19 files changed, 191 insertions(+), 436 deletions(-) delete mode 100644 yarn-project/simulator/src/avm/opcodes/context_getters.test.ts delete mode 100644 yarn-project/simulator/src/avm/opcodes/context_getters.ts diff --git a/avm-transpiler/src/opcodes.rs b/avm-transpiler/src/opcodes.rs index 80defd4a393..e20a993702f 100644 --- a/avm-transpiler/src/opcodes.rs +++ b/avm-transpiler/src/opcodes.rs @@ -35,21 +35,8 @@ pub enum AvmOpcode { CAST_8, CAST_16, // Execution environment - ADDRESS, - STORAGEADDRESS, - SENDER, - FUNCTIONSELECTOR, - TRANSACTIONFEE, - CHAINID, - VERSION, - BLOCKNUMBER, - TIMESTAMP, - FEEPERL2GAS, - FEEPERDAGAS, + GETENVVAR_16, CALLDATACOPY, - // Gas - L2GASLEFT, - DAGASLEFT, // Control flow JUMP_16, JUMPI_16, @@ -138,25 +125,11 @@ impl AvmOpcode { AvmOpcode::CAST_16 => "CAST_16", // Execution Environment - AvmOpcode::ADDRESS => "ADDRESS", - AvmOpcode::STORAGEADDRESS => "STORAGEADDRESS", - AvmOpcode::SENDER => "SENDER", - AvmOpcode::FUNCTIONSELECTOR => "FUNCTIONSELECTOR", - AvmOpcode::TRANSACTIONFEE => "TRANSACTIONFEE", - // Execution Environment - Globals - AvmOpcode::CHAINID => "CHAINID", - AvmOpcode::VERSION => "VERSION", - AvmOpcode::BLOCKNUMBER => "BLOCKNUMBER", - AvmOpcode::TIMESTAMP => "TIMESTAMP", - AvmOpcode::FEEPERL2GAS => "FEEPERL2GAS", - AvmOpcode::FEEPERDAGAS => "FEEPERDAGAS", + AvmOpcode::GETENVVAR_16 => "GETENVVAR_16", // Execution Environment - Calldata AvmOpcode::CALLDATACOPY => "CALLDATACOPY", // Machine State - // Machine State - Gas - AvmOpcode::L2GASLEFT => "L2GASLEFT", - AvmOpcode::DAGASLEFT => "DAGASLEFT", // Machine State - Internal Control Flow AvmOpcode::JUMP_16 => "JUMP_16", AvmOpcode::JUMPI_16 => "JUMPI_16", diff --git a/avm-transpiler/src/transpile.rs b/avm-transpiler/src/transpile.rs index 0b0fff16bae..77a98d21945 100644 --- a/avm-transpiler/src/transpile.rs +++ b/avm-transpiler/src/transpile.rs @@ -732,6 +732,23 @@ fn handle_getter_instruction( destinations: &Vec, inputs: &Vec, ) { + enum EnvironmentVariable { + ADDRESS, + STORAGEADDRESS, + SENDER, + FUNCTIONSELECTOR, + TRANSACTIONFEE, + CHAINID, + VERSION, + BLOCKNUMBER, + TIMESTAMP, + FEEPERL2GAS, + FEEPERDAGAS, + ISSTATICCALL, + L2GASLEFT, + DAGASLEFT, + } + // For the foreign calls we want to handle, we do not want inputs, as they are getters assert!(inputs.is_empty()); assert!(destinations.len() == 1); @@ -742,28 +759,31 @@ fn handle_getter_instruction( _ => panic!("ForeignCall address destination should be a single value"), }; - let opcode = match function { - "avmOpcodeAddress" => AvmOpcode::ADDRESS, - "avmOpcodeStorageAddress" => AvmOpcode::STORAGEADDRESS, - "avmOpcodeSender" => AvmOpcode::SENDER, - "avmOpcodeFeePerL2Gas" => AvmOpcode::FEEPERL2GAS, - "avmOpcodeFeePerDaGas" => AvmOpcode::FEEPERDAGAS, - "avmOpcodeTransactionFee" => AvmOpcode::TRANSACTIONFEE, - "avmOpcodeChainId" => AvmOpcode::CHAINID, - "avmOpcodeVersion" => AvmOpcode::VERSION, - "avmOpcodeBlockNumber" => AvmOpcode::BLOCKNUMBER, - "avmOpcodeTimestamp" => AvmOpcode::TIMESTAMP, - "avmOpcodeL2GasLeft" => AvmOpcode::L2GASLEFT, - "avmOpcodeDaGasLeft" => AvmOpcode::DAGASLEFT, - "avmOpcodeFunctionSelector" => AvmOpcode::FUNCTIONSELECTOR, - // "callStackDepth" => AvmOpcode::CallStackDepth, - _ => panic!("Transpiler doesn't know how to process ForeignCall function {:?}", function), + let var_idx = match function { + "avmOpcodeAddress" => EnvironmentVariable::ADDRESS, + "avmOpcodeStorageAddress" => EnvironmentVariable::STORAGEADDRESS, + "avmOpcodeSender" => EnvironmentVariable::SENDER, + "avmOpcodeFeePerL2Gas" => EnvironmentVariable::FEEPERL2GAS, + "avmOpcodeFeePerDaGas" => EnvironmentVariable::FEEPERDAGAS, + "avmOpcodeTransactionFee" => EnvironmentVariable::TRANSACTIONFEE, + "avmOpcodeChainId" => EnvironmentVariable::CHAINID, + "avmOpcodeVersion" => EnvironmentVariable::VERSION, + "avmOpcodeBlockNumber" => EnvironmentVariable::BLOCKNUMBER, + "avmOpcodeTimestamp" => EnvironmentVariable::TIMESTAMP, + "avmOpcodeL2GasLeft" => EnvironmentVariable::L2GASLEFT, + "avmOpcodeDaGasLeft" => EnvironmentVariable::DAGASLEFT, + "avmOpcodeFunctionSelector" => EnvironmentVariable::FUNCTIONSELECTOR, + "avmOpcodeIsStaticCall" => EnvironmentVariable::ISSTATICCALL, + _ => panic!("Transpiler doesn't know how to process getter {:?}", function), }; avm_instrs.push(AvmInstruction { - opcode, + opcode: AvmOpcode::GETENVVAR_16, indirect: Some(ALL_DIRECT), - operands: vec![AvmOperand::U32 { value: dest_offset as u32 }], + operands: vec![ + AvmOperand::U8 { value: var_idx as u8 }, + AvmOperand::U16 { value: dest_offset as u16 }, + ], ..Default::default() }); } diff --git a/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp b/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp index 44fe879b634..2ea4a0fc96f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp @@ -84,20 +84,8 @@ #define AVM_SHL_BASE_L2_GAS 320 #define AVM_SHR_BASE_L2_GAS 320 #define AVM_CAST_BASE_L2_GAS 300 -#define AVM_ADDRESS_BASE_L2_GAS 200 -#define AVM_STORAGEADDRESS_BASE_L2_GAS 200 -#define AVM_SENDER_BASE_L2_GAS 200 -#define AVM_FUNCTIONSELECTOR_BASE_L2_GAS 200 -#define AVM_TRANSACTIONFEE_BASE_L2_GAS 200 -#define AVM_CHAINID_BASE_L2_GAS 200 -#define AVM_VERSION_BASE_L2_GAS 200 -#define AVM_BLOCKNUMBER_BASE_L2_GAS 200 -#define AVM_TIMESTAMP_BASE_L2_GAS 200 -#define AVM_FEEPERL2GAS_BASE_L2_GAS 200 -#define AVM_FEEPERDAGAS_BASE_L2_GAS 200 +#define AVM_GETENVVAR_BASE_L2_GAS 200 #define AVM_CALLDATACOPY_BASE_L2_GAS 290 -#define AVM_L2GASLEFT_BASE_L2_GAS 180 -#define AVM_DAGASLEFT_BASE_L2_GAS 180 #define AVM_JUMP_BASE_L2_GAS 120 #define AVM_JUMPI_BASE_L2_GAS 180 #define AVM_INTERNALCALL_BASE_L2_GAS 180 @@ -146,20 +134,7 @@ #define AVM_SHL_DYN_L2_GAS 0 #define AVM_SHR_DYN_L2_GAS 0 #define AVM_CAST_DYN_L2_GAS 0 -#define AVM_ADDRESS_DYN_L2_GAS 0 -#define AVM_STORAGEADDRESS_DYN_L2_GAS 0 -#define AVM_SENDER_DYN_L2_GAS 0 -#define AVM_FUNCTIONSELECTOR_DYN_L2_GAS 0 -#define AVM_TRANSACTIONFEE_DYN_L2_GAS 0 -#define AVM_CHAINID_DYN_L2_GAS 0 -#define AVM_VERSION_DYN_L2_GAS 0 -#define AVM_BLOCKNUMBER_DYN_L2_GAS 0 -#define AVM_TIMESTAMP_DYN_L2_GAS 0 -#define AVM_FEEPERL2GAS_DYN_L2_GAS 0 -#define AVM_FEEPERDAGAS_DYN_L2_GAS 0 #define AVM_CALLDATACOPY_DYN_L2_GAS 50 -#define AVM_L2GASLEFT_DYN_L2_GAS 0 -#define AVM_DAGASLEFT_DYN_L2_GAS 0 #define AVM_JUMP_DYN_L2_GAS 0 #define AVM_JUMPI_DYN_L2_GAS 0 #define AVM_INTERNALCALL_DYN_L2_GAS 0 diff --git a/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr b/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr index 68dbb85b80b..80b3456918b 100644 --- a/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr +++ b/noir-projects/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr @@ -4,6 +4,7 @@ use dep::protocol_types::traits::Empty; struct PublicContextInputs { // TODO: Remove this structure and get calldata size at compile time. calldata_length: Field, + // This is currently unused but it's here to avoid changing serialization. is_static_call: bool } diff --git a/noir-projects/aztec-nr/aztec/src/context/public_context.nr b/noir-projects/aztec-nr/aztec/src/context/public_context.nr index 47efe0be38f..eaff2e10fcb 100644 --- a/noir-projects/aztec-nr/aztec/src/context/public_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/public_context.nr @@ -176,6 +176,9 @@ impl PublicContext { fn da_gas_left(_self: Self) -> Field { da_gas_left() } + fn is_static_call(_self: Self) -> bool { + is_static_call() == 1 + } fn raw_storage_read(_self: Self, storage_slot: Field) -> [Field; N] { let mut out = [0; N]; @@ -254,6 +257,9 @@ unconstrained fn l2_gas_left() -> Field { unconstrained fn da_gas_left() -> Field { da_gas_left_opcode() } +unconstrained fn is_static_call() -> Field { + is_static_call_opcode() +} unconstrained fn note_hash_exists(note_hash: Field, leaf_index: Field) -> u8 { note_hash_exists_opcode(note_hash, leaf_index) } @@ -357,6 +363,9 @@ unconstrained fn l2_gas_left_opcode() -> Field {} #[oracle(avmOpcodeDaGasLeft)] unconstrained fn da_gas_left_opcode() -> Field {} +#[oracle(avmOpcodeIsStaticCall)] +unconstrained fn is_static_call_opcode() -> Field {} + #[oracle(avmOpcodeNoteHashExists)] unconstrained fn note_hash_exists_opcode(note_hash: Field, leaf_index: Field) -> u8 {} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 47e90b384eb..16482b83c9c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -429,20 +429,8 @@ global AVM_NOT_BASE_L2_GAS: u16 = 270; global AVM_SHL_BASE_L2_GAS: u16 = 320; global AVM_SHR_BASE_L2_GAS: u16 = 320; global AVM_CAST_BASE_L2_GAS: u16 = 300; -global AVM_ADDRESS_BASE_L2_GAS: u16 = 200; -global AVM_STORAGEADDRESS_BASE_L2_GAS: u16 = 200; -global AVM_SENDER_BASE_L2_GAS: u16 = 200; -global AVM_FUNCTIONSELECTOR_BASE_L2_GAS: u16 = 200; -global AVM_TRANSACTIONFEE_BASE_L2_GAS: u16 = 200; -global AVM_CHAINID_BASE_L2_GAS: u16 = 200; -global AVM_VERSION_BASE_L2_GAS: u16 = 200; -global AVM_BLOCKNUMBER_BASE_L2_GAS: u16 = 200; -global AVM_TIMESTAMP_BASE_L2_GAS: u16 = 200; -global AVM_FEEPERL2GAS_BASE_L2_GAS: u16 = 200; -global AVM_FEEPERDAGAS_BASE_L2_GAS: u16 = 200; +global AVM_GETENVVAR_BASE_L2_GAS: u16 = 200; global AVM_CALLDATACOPY_BASE_L2_GAS: u16 = 290; -global AVM_L2GASLEFT_BASE_L2_GAS: u16 = 180; -global AVM_DAGASLEFT_BASE_L2_GAS: u16 = 180; global AVM_JUMP_BASE_L2_GAS: u16 = 120; global AVM_JUMPI_BASE_L2_GAS: u16 = 180; global AVM_INTERNALCALL_BASE_L2_GAS: u16 = 180; @@ -492,20 +480,7 @@ global AVM_NOT_DYN_L2_GAS: u16 = 0; global AVM_SHL_DYN_L2_GAS: u16 = 0; global AVM_SHR_DYN_L2_GAS: u16 = 0; global AVM_CAST_DYN_L2_GAS: u16 = 0; -global AVM_ADDRESS_DYN_L2_GAS: u16 = 0; -global AVM_STORAGEADDRESS_DYN_L2_GAS: u16 = 0; -global AVM_SENDER_DYN_L2_GAS: u16 = 0; -global AVM_FUNCTIONSELECTOR_DYN_L2_GAS: u16 = 0; -global AVM_TRANSACTIONFEE_DYN_L2_GAS: u16 = 0; -global AVM_CHAINID_DYN_L2_GAS: u16 = 0; -global AVM_VERSION_DYN_L2_GAS: u16 = 0; -global AVM_BLOCKNUMBER_DYN_L2_GAS: u16 = 0; -global AVM_TIMESTAMP_DYN_L2_GAS: u16 = 0; -global AVM_FEEPERL2GAS_DYN_L2_GAS: u16 = 0; -global AVM_FEEPERDAGAS_DYN_L2_GAS: u16 = 0; global AVM_CALLDATACOPY_DYN_L2_GAS: u16 = 50; -global AVM_L2GASLEFT_DYN_L2_GAS: u16 = 0; -global AVM_DAGASLEFT_DYN_L2_GAS: u16 = 0; global AVM_JUMP_DYN_L2_GAS: u16 = 0; global AVM_JUMPI_DYN_L2_GAS: u16 = 0; global AVM_INTERNALCALL_DYN_L2_GAS: u16 = 0; diff --git a/noir/noir-repo/aztec_macros/src/transforms/functions.rs b/noir/noir-repo/aztec_macros/src/transforms/functions.rs index 6c8af308a52..d2091f6f98d 100644 --- a/noir/noir-repo/aztec_macros/src/transforms/functions.rs +++ b/noir/noir-repo/aztec_macros/src/transforms/functions.rs @@ -312,9 +312,7 @@ fn create_static_check(fname: &str, is_private: bool) -> Statement { .iter() .fold(variable("context"), |acc, member| member_access(acc, member)) } else { - ["inputs", "is_static_call"] - .iter() - .fold(variable("context"), |acc, member| member_access(acc, member)) + method_call(variable("context"), "is_static_call", vec![]) }; make_statement(StatementKind::Constrain(ConstrainStatement { kind: ConstrainKind::Assert, diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index e55438cf753..484513c7d17 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -253,20 +253,8 @@ export const AVM_NOT_BASE_L2_GAS = 270; export const AVM_SHL_BASE_L2_GAS = 320; export const AVM_SHR_BASE_L2_GAS = 320; export const AVM_CAST_BASE_L2_GAS = 300; -export const AVM_ADDRESS_BASE_L2_GAS = 200; -export const AVM_STORAGEADDRESS_BASE_L2_GAS = 200; -export const AVM_SENDER_BASE_L2_GAS = 200; -export const AVM_FUNCTIONSELECTOR_BASE_L2_GAS = 200; -export const AVM_TRANSACTIONFEE_BASE_L2_GAS = 200; -export const AVM_CHAINID_BASE_L2_GAS = 200; -export const AVM_VERSION_BASE_L2_GAS = 200; -export const AVM_BLOCKNUMBER_BASE_L2_GAS = 200; -export const AVM_TIMESTAMP_BASE_L2_GAS = 200; -export const AVM_FEEPERL2GAS_BASE_L2_GAS = 200; -export const AVM_FEEPERDAGAS_BASE_L2_GAS = 200; +export const AVM_GETENVVAR_BASE_L2_GAS = 200; export const AVM_CALLDATACOPY_BASE_L2_GAS = 290; -export const AVM_L2GASLEFT_BASE_L2_GAS = 180; -export const AVM_DAGASLEFT_BASE_L2_GAS = 180; export const AVM_JUMP_BASE_L2_GAS = 120; export const AVM_JUMPI_BASE_L2_GAS = 180; export const AVM_INTERNALCALL_BASE_L2_GAS = 180; @@ -315,20 +303,7 @@ export const AVM_NOT_DYN_L2_GAS = 0; export const AVM_SHL_DYN_L2_GAS = 0; export const AVM_SHR_DYN_L2_GAS = 0; export const AVM_CAST_DYN_L2_GAS = 0; -export const AVM_ADDRESS_DYN_L2_GAS = 0; -export const AVM_STORAGEADDRESS_DYN_L2_GAS = 0; -export const AVM_SENDER_DYN_L2_GAS = 0; -export const AVM_FUNCTIONSELECTOR_DYN_L2_GAS = 0; -export const AVM_TRANSACTIONFEE_DYN_L2_GAS = 0; -export const AVM_CHAINID_DYN_L2_GAS = 0; -export const AVM_VERSION_DYN_L2_GAS = 0; -export const AVM_BLOCKNUMBER_DYN_L2_GAS = 0; -export const AVM_TIMESTAMP_DYN_L2_GAS = 0; -export const AVM_FEEPERL2GAS_DYN_L2_GAS = 0; -export const AVM_FEEPERDAGAS_DYN_L2_GAS = 0; export const AVM_CALLDATACOPY_DYN_L2_GAS = 50; -export const AVM_L2GASLEFT_DYN_L2_GAS = 0; -export const AVM_DAGASLEFT_DYN_L2_GAS = 0; export const AVM_JUMP_DYN_L2_GAS = 0; export const AVM_JUMPI_DYN_L2_GAS = 0; export const AVM_INTERNALCALL_DYN_L2_GAS = 0; diff --git a/yarn-project/simulator/src/avm/avm_gas.ts b/yarn-project/simulator/src/avm/avm_gas.ts index 7a4eb8e3db2..a2627d3ed23 100644 --- a/yarn-project/simulator/src/avm/avm_gas.ts +++ b/yarn-project/simulator/src/avm/avm_gas.ts @@ -87,20 +87,8 @@ const BaseGasCosts: Record = { [Opcode.SHR_16]: makeCost(c.AVM_SHR_BASE_L2_GAS, 0), [Opcode.CAST_8]: makeCost(c.AVM_CAST_BASE_L2_GAS, 0), [Opcode.CAST_16]: makeCost(c.AVM_CAST_BASE_L2_GAS, 0), - [Opcode.ADDRESS]: makeCost(c.AVM_ADDRESS_BASE_L2_GAS, 0), - [Opcode.STORAGEADDRESS]: makeCost(c.AVM_STORAGEADDRESS_BASE_L2_GAS, 0), - [Opcode.SENDER]: makeCost(c.AVM_SENDER_BASE_L2_GAS, 0), - [Opcode.FEEPERL2GAS]: makeCost(c.AVM_FEEPERL2GAS_BASE_L2_GAS, 0), - [Opcode.FEEPERDAGAS]: makeCost(c.AVM_FEEPERDAGAS_BASE_L2_GAS, 0), - [Opcode.TRANSACTIONFEE]: makeCost(c.AVM_TRANSACTIONFEE_BASE_L2_GAS, 0), - [Opcode.FUNCTIONSELECTOR]: makeCost(c.AVM_FUNCTIONSELECTOR_BASE_L2_GAS, 0), - [Opcode.CHAINID]: makeCost(c.AVM_CHAINID_BASE_L2_GAS, 0), - [Opcode.VERSION]: makeCost(c.AVM_VERSION_BASE_L2_GAS, 0), - [Opcode.BLOCKNUMBER]: makeCost(c.AVM_BLOCKNUMBER_BASE_L2_GAS, 0), - [Opcode.TIMESTAMP]: makeCost(c.AVM_TIMESTAMP_BASE_L2_GAS, 0), + [Opcode.GETENVVAR_16]: makeCost(c.AVM_GETENVVAR_BASE_L2_GAS, 0), [Opcode.CALLDATACOPY]: makeCost(c.AVM_CALLDATACOPY_BASE_L2_GAS, 0), - [Opcode.L2GASLEFT]: makeCost(c.AVM_L2GASLEFT_BASE_L2_GAS, 0), - [Opcode.DAGASLEFT]: makeCost(c.AVM_DAGASLEFT_BASE_L2_GAS, 0), [Opcode.JUMP_16]: makeCost(c.AVM_JUMP_BASE_L2_GAS, 0), [Opcode.JUMPI_16]: makeCost(c.AVM_JUMPI_BASE_L2_GAS, 0), [Opcode.INTERNALCALL]: makeCost(c.AVM_INTERNALCALL_BASE_L2_GAS, 0), @@ -173,20 +161,8 @@ const DynamicGasCosts: Record = { [Opcode.SHR_16]: makeCost(c.AVM_SHR_DYN_L2_GAS, 0), [Opcode.CAST_8]: makeCost(c.AVM_CAST_DYN_L2_GAS, 0), [Opcode.CAST_16]: makeCost(c.AVM_CAST_DYN_L2_GAS, 0), - [Opcode.ADDRESS]: makeCost(c.AVM_ADDRESS_DYN_L2_GAS, 0), - [Opcode.STORAGEADDRESS]: makeCost(c.AVM_STORAGEADDRESS_DYN_L2_GAS, 0), - [Opcode.SENDER]: makeCost(c.AVM_SENDER_DYN_L2_GAS, 0), - [Opcode.FEEPERL2GAS]: makeCost(c.AVM_FEEPERL2GAS_DYN_L2_GAS, 0), - [Opcode.FEEPERDAGAS]: makeCost(c.AVM_FEEPERDAGAS_DYN_L2_GAS, 0), - [Opcode.TRANSACTIONFEE]: makeCost(c.AVM_TRANSACTIONFEE_DYN_L2_GAS, 0), - [Opcode.FUNCTIONSELECTOR]: makeCost(c.AVM_FUNCTIONSELECTOR_DYN_L2_GAS, 0), - [Opcode.CHAINID]: makeCost(c.AVM_CHAINID_DYN_L2_GAS, 0), - [Opcode.VERSION]: makeCost(c.AVM_VERSION_DYN_L2_GAS, 0), - [Opcode.BLOCKNUMBER]: makeCost(c.AVM_BLOCKNUMBER_DYN_L2_GAS, 0), - [Opcode.TIMESTAMP]: makeCost(c.AVM_TIMESTAMP_DYN_L2_GAS, 0), + [Opcode.GETENVVAR_16]: makeCost(0, 0), [Opcode.CALLDATACOPY]: makeCost(c.AVM_CALLDATACOPY_DYN_L2_GAS, 0), - [Opcode.L2GASLEFT]: makeCost(c.AVM_L2GASLEFT_DYN_L2_GAS, 0), - [Opcode.DAGASLEFT]: makeCost(c.AVM_DAGASLEFT_DYN_L2_GAS, 0), [Opcode.JUMP_16]: makeCost(c.AVM_JUMP_DYN_L2_GAS, 0), [Opcode.JUMPI_16]: makeCost(c.AVM_JUMPI_DYN_L2_GAS, 0), [Opcode.INTERNALCALL]: makeCost(c.AVM_INTERNALCALL_DYN_L2_GAS, 0), diff --git a/yarn-project/simulator/src/avm/opcodes/context_getters.test.ts b/yarn-project/simulator/src/avm/opcodes/context_getters.test.ts deleted file mode 100644 index b865d30de2b..00000000000 --- a/yarn-project/simulator/src/avm/opcodes/context_getters.test.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { initContext, initMachineState } from '../fixtures/index.js'; -import { DAGasLeft, L2GasLeft } from './context_getters.js'; - -describe.each([ - [L2GasLeft, 'l2GasLeft'], - [DAGasLeft, 'daGasLeft'], -] as const)('Context getter instructions for machine state', (clsValue, key) => { - it(`${clsValue.name} should (de)serialize correctly`, () => { - const buf = Buffer.from([ - clsValue.opcode, // opcode - 0x01, // indirect - ...Buffer.from('12345678', 'hex'), // dstOffset - ]); - const inst = new clsValue(/*indirect=*/ 0x01, /*dstOffset=*/ 0x12345678); - - expect(clsValue.deserialize(buf)).toEqual(inst); - expect(inst.serialize()).toEqual(buf); - }); - - it(`${clsValue.name} should read '${key}' correctly`, async () => { - const value = 123456; - const instruction = new clsValue(/*indirect=*/ 0, /*dstOffset=*/ 0); - const context = initContext({ machineState: initMachineState({ [key]: value }) }); - - await instruction.execute(context); - - const actual = context.machineState.memory.get(0).toNumber(); - const expected = key === 'l2GasLeft' ? 123276 : value; // l2gascost decreases when it's executed - expect(actual).toEqual(expected); - }); -}); diff --git a/yarn-project/simulator/src/avm/opcodes/context_getters.ts b/yarn-project/simulator/src/avm/opcodes/context_getters.ts deleted file mode 100644 index 22bd501f59d..00000000000 --- a/yarn-project/simulator/src/avm/opcodes/context_getters.ts +++ /dev/null @@ -1,23 +0,0 @@ -import type { AvmContext } from '../avm_context.js'; -import { Field, type MemoryValue } from '../avm_memory_types.js'; -import { Opcode } from '../serialization/instruction_serialization.js'; -import { GetterInstruction } from './instruction_impl.js'; - -export class L2GasLeft extends GetterInstruction { - static type: string = 'L2GASLEFT'; - static readonly opcode: Opcode = Opcode.L2GASLEFT; - - // TODO(@spalladino) Protocol specs specifies that the value should be an Uint32, not a Field. - protected getValue(context: AvmContext): MemoryValue { - return new Field(context.machineState.l2GasLeft); - } -} - -export class DAGasLeft extends GetterInstruction { - static type: string = 'DAGASLEFT'; - static readonly opcode: Opcode = Opcode.DAGASLEFT; - - protected getValue(context: AvmContext): MemoryValue { - return new Field(context.machineState.daGasLeft); - } -} diff --git a/yarn-project/simulator/src/avm/opcodes/environment_getters.test.ts b/yarn-project/simulator/src/avm/opcodes/environment_getters.test.ts index abf0b7e3936..8f68d272b9d 100644 --- a/yarn-project/simulator/src/avm/opcodes/environment_getters.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/environment_getters.test.ts @@ -8,32 +8,8 @@ import { randomInt } from 'crypto'; import { type AvmContext } from '../avm_context.js'; import { TypeTag } from '../avm_memory_types.js'; import { initContext, initExecutionEnvironment, initGlobalVariables } from '../fixtures/index.js'; -import { - Address, - BlockNumber, - ChainId, - FeePerDAGas, - FeePerL2Gas, - FunctionSelector, - Sender, - StorageAddress, - Timestamp, - TransactionFee, - Version, -} from './environment_getters.js'; - -type GetterInstruction = - | typeof Sender - | typeof StorageAddress - | typeof Address - | typeof FunctionSelector - | typeof TransactionFee - | typeof ChainId - | typeof Version - | typeof BlockNumber - | typeof Timestamp - | typeof FeePerDAGas - | typeof FeePerL2Gas; +import { Opcode } from '../serialization/instruction_serialization.js'; +import { EnvironmentVariable, GetEnvVar } from './environment_getters.js'; describe('Environment getters', () => { const address = AztecAddress.random(); @@ -47,6 +23,7 @@ describe('Environment getters', () => { const timestamp = new Fr(randomInt(100000)); // cap timestamp since must fit in u64 const feePerDaGas = Fr.random(); const feePerL2Gas = Fr.random(); + const isStaticCall = true; const gasFees = new GasFees(feePerDaGas, feePerL2Gas); const globals = initGlobalVariables({ chainId, @@ -62,38 +39,45 @@ describe('Environment getters', () => { functionSelector, transactionFee, globals, + isStaticCall, }); let context: AvmContext; beforeEach(() => { context = initContext({ env }); }); - describe.each([ - [Address, address.toField()], - [StorageAddress, storageAddress.toField()], - [Sender, sender.toField()], - [FunctionSelector, functionSelector.toField(), TypeTag.UINT32], - [TransactionFee, transactionFee.toField()], - [ChainId, chainId.toField()], - [Version, version.toField()], - [BlockNumber, blockNumber.toField()], - [Timestamp, timestamp.toField(), TypeTag.UINT64], - [FeePerDAGas, feePerDaGas.toField()], - [FeePerL2Gas, feePerL2Gas.toField()], - ])('Environment getters instructions', (instrClass: GetterInstruction, value: Fr, tag: TypeTag = TypeTag.FIELD) => { - it(`${instrClass.name} should (de)serialize correctly`, () => { - const buf = Buffer.from([ - instrClass.opcode, // opcode - 0x01, // indirect - ...Buffer.from('12345678', 'hex'), // dstOffset - ]); - const instr = new instrClass(/*indirect=*/ 0x01, /*dstOffset=*/ 0x12345678); + it(`Should (de)serialize correctly`, () => { + const buf = Buffer.from([ + Opcode.GETENVVAR_16, // opcode + 0x01, // indirect + 0x05, // var idx + ...Buffer.from('1234', 'hex'), // dstOffset + ]); + const instr = new GetEnvVar(/*indirect=*/ 0x01, 5, /*dstOffset=*/ 0x1234).as( + Opcode.GETENVVAR_16, + GetEnvVar.wireFormat16, + ); - expect(instrClass.deserialize(buf)).toEqual(instr); - expect(instr.serialize()).toEqual(buf); - }); - it(`${instrClass.name} should read '${instrClass.type}' correctly`, async () => { - const instruction = new instrClass(/*indirect=*/ 0, /*dstOffset=*/ 0); + expect(GetEnvVar.as(GetEnvVar.wireFormat16).deserialize(buf)).toEqual(instr); + expect(instr.serialize()).toEqual(buf); + }); + + describe.each([ + [EnvironmentVariable.ADDRESS, address.toField()], + [EnvironmentVariable.STORAGEADDRESS, storageAddress.toField()], + [EnvironmentVariable.SENDER, sender.toField()], + [EnvironmentVariable.FUNCTIONSELECTOR, functionSelector.toField(), TypeTag.UINT32], + [EnvironmentVariable.TRANSACTIONFEE, transactionFee.toField()], + [EnvironmentVariable.CHAINID, chainId.toField()], + [EnvironmentVariable.VERSION, version.toField()], + [EnvironmentVariable.BLOCKNUMBER, blockNumber.toField()], + [EnvironmentVariable.TIMESTAMP, timestamp.toField(), TypeTag.UINT64], + [EnvironmentVariable.FEEPERDAGAS, feePerDaGas.toField()], + [EnvironmentVariable.FEEPERL2GAS, feePerL2Gas.toField()], + [EnvironmentVariable.ISSTATICCALL, new Fr(isStaticCall ? 1 : 0)], + ])('Environment getter instructions', (envVar: EnvironmentVariable, value: Fr, tag: TypeTag = TypeTag.FIELD) => { + it(`Should read '${EnvironmentVariable[envVar]}' correctly`, async () => { + const instruction = new GetEnvVar(/*indirect=*/ 0, envVar, /*dstOffset=*/ 0); await instruction.execute(context); diff --git a/yarn-project/simulator/src/avm/opcodes/environment_getters.ts b/yarn-project/simulator/src/avm/opcodes/environment_getters.ts index 6373382acf6..e93139fb378 100644 --- a/yarn-project/simulator/src/avm/opcodes/environment_getters.ts +++ b/yarn-project/simulator/src/avm/opcodes/environment_getters.ts @@ -1,112 +1,85 @@ import type { AvmContext } from '../avm_context.js'; -import type { AvmExecutionEnvironment } from '../avm_execution_environment.js'; -import { Field, type MemoryValue, Uint32, Uint64 } from '../avm_memory_types.js'; -import { Opcode } from '../serialization/instruction_serialization.js'; -import { GetterInstruction } from './instruction_impl.js'; - -abstract class EnvironmentGetterInstruction extends GetterInstruction { - protected getValue(context: AvmContext): MemoryValue { - return this.getEnvironmentValue(context.environment); - } - - protected abstract getEnvironmentValue(env: AvmExecutionEnvironment): MemoryValue; -} - -export class Address extends EnvironmentGetterInstruction { - static type: string = 'ADDRESS'; - static readonly opcode: Opcode = Opcode.ADDRESS; - - protected getEnvironmentValue(env: AvmExecutionEnvironment) { - return new Field(env.address.toField()); - } -} - -export class StorageAddress extends EnvironmentGetterInstruction { - static type: string = 'STORAGEADDRESS'; - static readonly opcode: Opcode = Opcode.STORAGEADDRESS; - - protected getEnvironmentValue(env: AvmExecutionEnvironment) { - return new Field(env.storageAddress.toField()); - } -} - -export class Sender extends EnvironmentGetterInstruction { - static type: string = 'SENDER'; - static readonly opcode: Opcode = Opcode.SENDER; - - protected getEnvironmentValue(env: AvmExecutionEnvironment) { - return new Field(env.sender.toField()); - } -} - -export class FunctionSelector extends EnvironmentGetterInstruction { - static type: string = 'FUNCTIONSELECTOR'; - static readonly opcode: Opcode = Opcode.FUNCTIONSELECTOR; - - protected getEnvironmentValue(env: AvmExecutionEnvironment) { - return new Uint32(env.functionSelector.value); - } -} - -export class TransactionFee extends EnvironmentGetterInstruction { - static type: string = 'TRANSACTIONFEE'; - static readonly opcode: Opcode = Opcode.TRANSACTIONFEE; - - protected getEnvironmentValue(env: AvmExecutionEnvironment) { - return new Field(env.transactionFee); - } -} - -export class ChainId extends EnvironmentGetterInstruction { - static type: string = 'CHAINID'; - static readonly opcode: Opcode = Opcode.CHAINID; - - protected getEnvironmentValue(env: AvmExecutionEnvironment) { - return new Field(env.globals.chainId); - } +import { Field, Uint32, Uint64 } from '../avm_memory_types.js'; +import { Opcode, OperandType } from '../serialization/instruction_serialization.js'; +import { Addressing } from './addressing_mode.js'; +import { Instruction } from './instruction.js'; + +export enum EnvironmentVariable { + ADDRESS, + STORAGEADDRESS, + SENDER, + FUNCTIONSELECTOR, + TRANSACTIONFEE, + CHAINID, + VERSION, + BLOCKNUMBER, + TIMESTAMP, + FEEPERL2GAS, + FEEPERDAGAS, + ISSTATICCALL, + L2GASLEFT, + DAGASLEFT, } -export class Version extends EnvironmentGetterInstruction { - static type: string = 'VERSION'; - static readonly opcode: Opcode = Opcode.VERSION; - - protected getEnvironmentValue(env: AvmExecutionEnvironment) { - return new Field(env.globals.version); +function getValue(e: EnvironmentVariable, ctx: AvmContext) { + switch (e) { + case EnvironmentVariable.ADDRESS: + return new Field(ctx.environment.address.toField()); + case EnvironmentVariable.STORAGEADDRESS: + return new Field(ctx.environment.storageAddress.toField()); + case EnvironmentVariable.SENDER: + return new Field(ctx.environment.sender.toField()); + case EnvironmentVariable.FUNCTIONSELECTOR: + return new Uint32(ctx.environment.functionSelector.value); + case EnvironmentVariable.TRANSACTIONFEE: + return new Field(ctx.environment.transactionFee); + case EnvironmentVariable.CHAINID: + return new Field(ctx.environment.globals.chainId); + case EnvironmentVariable.VERSION: + return new Field(ctx.environment.globals.version); + case EnvironmentVariable.BLOCKNUMBER: + return new Field(ctx.environment.globals.blockNumber); + case EnvironmentVariable.TIMESTAMP: + return new Uint64(ctx.environment.globals.timestamp.toBigInt()); + case EnvironmentVariable.FEEPERL2GAS: + return new Field(ctx.environment.globals.gasFees.feePerL2Gas); + case EnvironmentVariable.FEEPERDAGAS: + return new Field(ctx.environment.globals.gasFees.feePerDaGas); + case EnvironmentVariable.ISSTATICCALL: + return new Field(ctx.environment.isStaticCall ? 1 : 0); + case EnvironmentVariable.L2GASLEFT: + return new Field(ctx.machineState.l2GasLeft); + case EnvironmentVariable.DAGASLEFT: + return new Field(ctx.machineState.daGasLeft); + default: + throw new Error(`Unknown environment variable ${e}`); } } -export class BlockNumber extends EnvironmentGetterInstruction { - static type: string = 'BLOCKNUMBER'; - static readonly opcode: Opcode = Opcode.BLOCKNUMBER; - - protected getEnvironmentValue(env: AvmExecutionEnvironment) { - return new Field(env.globals.blockNumber); +export class GetEnvVar extends Instruction { + public static readonly type: string = 'GETENVVAR'; + public static readonly opcode: Opcode = Opcode.GETENVVAR_16; + static readonly wireFormat16: OperandType[] = [ + OperandType.UINT8, // opcode + OperandType.UINT8, // indirect + OperandType.UINT8, // variable enum (immediate) + OperandType.UINT16, // dstOffset + ]; + + constructor(private indirect: number, private varEnum: EnvironmentVariable, private dstOffset: number) { + super(); } -} -export class Timestamp extends EnvironmentGetterInstruction { - static type: string = 'TIMESTAMP'; - static readonly opcode: Opcode = Opcode.TIMESTAMP; + public async execute(context: AvmContext): Promise { + const memoryOperations = { writes: 1, indirect: this.indirect }; + const memory = context.machineState.memory.track(this.type); + context.machineState.consumeGas(this.gasCost(memoryOperations)); - protected getEnvironmentValue(env: AvmExecutionEnvironment) { - return new Uint64(env.globals.timestamp.toBigInt()); - } -} - -export class FeePerL2Gas extends EnvironmentGetterInstruction { - static type: string = 'FEEPERL2GAS'; - static readonly opcode: Opcode = Opcode.FEEPERL2GAS; - - protected getEnvironmentValue(env: AvmExecutionEnvironment) { - return new Field(env.globals.gasFees.feePerL2Gas); - } -} + const [dstOffset] = Addressing.fromWire(this.indirect).resolve([this.dstOffset], memory); -export class FeePerDAGas extends EnvironmentGetterInstruction { - static type: string = 'FEEPERDAGAS'; - static readonly opcode: Opcode = Opcode.FEEPERDAGAS; + memory.set(dstOffset, getValue(this.varEnum, context)); - protected getEnvironmentValue(env: AvmExecutionEnvironment) { - return new Field(env.globals.gasFees.feePerDaGas); + memory.assert(memoryOperations); + context.machineState.incrementPc(); } } diff --git a/yarn-project/simulator/src/avm/opcodes/external_calls.test.ts b/yarn-project/simulator/src/avm/opcodes/external_calls.test.ts index 638e7913d45..003a01a8aa0 100644 --- a/yarn-project/simulator/src/avm/opcodes/external_calls.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/external_calls.test.ts @@ -12,7 +12,7 @@ import { type AvmPersistableStateManager } from '../journal/journal.js'; import { encodeToBytecode } from '../serialization/bytecode_serialization.js'; import { Opcode } from '../serialization/instruction_serialization.js'; import { mockGetBytecode, mockTraceFork } from '../test_utils.js'; -import { L2GasLeft } from './context_getters.js'; +import { EnvironmentVariable, GetEnvVar } from './environment_getters.js'; import { Call, Return, Revert, StaticCall } from './external_calls.js'; import { type Instruction } from './instruction.js'; import { CalldataCopy, Set } from './memory.js'; @@ -144,7 +144,10 @@ describe('External Calls', () => { const otherContextInstructionsBytecode = markBytecodeAsAvm( encodeToBytecode([ - new L2GasLeft(/*indirect=*/ 0, /*dstOffset=*/ 0), + new GetEnvVar(/*indirect=*/ 0, /*envVar=*/ EnvironmentVariable.L2GASLEFT, /*dstOffset=*/ 0).as( + Opcode.GETENVVAR_16, + GetEnvVar.wireFormat16, + ), new Return(/*indirect=*/ 0, /*retOffset=*/ 0, /*size=*/ 1), ]), ); diff --git a/yarn-project/simulator/src/avm/opcodes/index.ts b/yarn-project/simulator/src/avm/opcodes/index.ts index d0614bb169a..9ae06bd08c0 100644 --- a/yarn-project/simulator/src/avm/opcodes/index.ts +++ b/yarn-project/simulator/src/avm/opcodes/index.ts @@ -11,3 +11,6 @@ export * from './storage.js'; export * from './external_calls.js'; export * from './environment_getters.js'; export * from './accrued_substate.js'; +export * from './hashing.js'; +export * from './ec_add.js'; +export * from './commitment.js'; diff --git a/yarn-project/simulator/src/avm/opcodes/instruction_impl.ts b/yarn-project/simulator/src/avm/opcodes/instruction_impl.ts index 3544f07b0df..8d2a6f86d69 100644 --- a/yarn-project/simulator/src/avm/opcodes/instruction_impl.ts +++ b/yarn-project/simulator/src/avm/opcodes/instruction_impl.ts @@ -1,7 +1,4 @@ -import { type AvmContext } from '../avm_context.js'; -import { type MemoryValue } from '../avm_memory_types.js'; import { OperandType } from '../serialization/instruction_serialization.js'; -import { Addressing } from './addressing_mode.js'; import { Instruction } from './instruction.js'; /** Wire format that informs deserialization for instructions with three operands. */ @@ -40,27 +37,3 @@ export abstract class ThreeOperandInstruction extends Instruction { super(); } } - -export abstract class GetterInstruction extends Instruction { - // Informs (de)serialization. See Instruction.deserialize. - static readonly wireFormat: OperandType[] = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT32]; - - constructor(protected indirect: number, protected dstOffset: number) { - super(); - } - - public async execute(context: AvmContext): Promise { - const memoryOperations = { writes: 1, indirect: this.indirect }; - const memory = context.machineState.memory.track(this.type); - context.machineState.consumeGas(this.gasCost(memoryOperations)); - - const [dstOffset] = Addressing.fromWire(this.indirect).resolve([this.dstOffset], memory); - - memory.set(dstOffset, this.getValue(context)); - - memory.assert(memoryOperations); - context.machineState.incrementPc(); - } - - protected abstract getValue(env: AvmContext): MemoryValue; -} diff --git a/yarn-project/simulator/src/avm/serialization/bytecode_serialization.test.ts b/yarn-project/simulator/src/avm/serialization/bytecode_serialization.test.ts index 10354bcc410..ccc5fa2f951 100644 --- a/yarn-project/simulator/src/avm/serialization/bytecode_serialization.test.ts +++ b/yarn-project/simulator/src/avm/serialization/bytecode_serialization.test.ts @@ -1,6 +1,6 @@ import { strict as assert } from 'assert'; -import { Add, Address, Call, StaticCall, Sub } from '../opcodes/index.js'; +import { Add, Call, EnvironmentVariable, GetEnvVar, StaticCall, Sub } from '../opcodes/index.js'; import { type BufferCursor } from './buffer_cursor.js'; import { type InstructionSet, decodeFromBytecode, encodeToBytecode } from './bytecode_serialization.js'; import { Opcode } from './instruction_serialization.js'; @@ -80,7 +80,10 @@ describe('Bytecode Serialization', () => { Opcode.SUB_8, Sub.wireFormat8, ), - new Address(/*indirect=*/ 0, /*dstOffset=*/ 1), + new GetEnvVar(/*indirect=*/ 0, EnvironmentVariable.ADDRESS, /*dstOffset=*/ 1).as( + Opcode.GETENVVAR_16, + GetEnvVar.wireFormat16, + ), new Call( /*indirect=*/ 0x01, /*gasOffset=*/ 0x12345678, @@ -121,7 +124,10 @@ describe('Bytecode Serialization', () => { Opcode.SUB_8, Sub.wireFormat8, ), - new Address(/*indirect=*/ 0, /*dstOffset=*/ 1), + new GetEnvVar(/*indirect=*/ 0, EnvironmentVariable.ADDRESS, /*dstOffset=*/ 1).as( + Opcode.GETENVVAR_16, + GetEnvVar.wireFormat16, + ), new Call( /*indirect=*/ 0x01, /*gasOffset=*/ 0x12345678, diff --git a/yarn-project/simulator/src/avm/serialization/bytecode_serialization.ts b/yarn-project/simulator/src/avm/serialization/bytecode_serialization.ts index 6f5fae94394..75f656fa181 100644 --- a/yarn-project/simulator/src/avm/serialization/bytecode_serialization.ts +++ b/yarn-project/simulator/src/avm/serialization/bytecode_serialization.ts @@ -1,33 +1,27 @@ -import { PedersenCommitment } from '../opcodes/commitment.js'; -import { DAGasLeft, L2GasLeft } from '../opcodes/context_getters.js'; -import { EcAdd } from '../opcodes/ec_add.js'; -import { Keccak, KeccakF1600, Pedersen, Poseidon2, Sha256Compression } from '../opcodes/hashing.js'; import { Add, - Address, And, - BlockNumber, CMov, Call, CalldataCopy, Cast, - ChainId, DebugLog, Div, + EcAdd, EmitNoteHash, EmitNullifier, EmitUnencryptedLog, Eq, - FeePerDAGas, - FeePerL2Gas, FieldDiv, - FunctionSelector, GetContractInstance, + GetEnvVar, Instruction, InternalCall, InternalReturn, Jump, JumpI, + Keccak, + KeccakF1600, L1ToL2MessageExists, Lt, Lte, @@ -37,22 +31,21 @@ import { NoteHashExists, NullifierExists, Or, + Pedersen, + PedersenCommitment, + Poseidon2, Return, Revert, SLoad, SStore, SendL2ToL1Message, - Sender, Set, + Sha256Compression, Shl, Shr, StaticCall, - StorageAddress, Sub, - Timestamp, ToRadixLE, - TransactionFee, - Version, Xor, } from '../opcodes/index.js'; import { MultiScalarMul } from '../opcodes/multi_scalar_mul.js'; @@ -104,25 +97,10 @@ const INSTRUCTION_SET = () => [Opcode.SHR_16, Shr.as(Shr.wireFormat16).deserialize], [Opcode.CAST_8, Cast.as(Cast.wireFormat8).deserialize], [Opcode.CAST_16, Cast.as(Cast.wireFormat16).deserialize], - [Address.opcode, Instruction.deserialize.bind(Address)], - [StorageAddress.opcode, Instruction.deserialize.bind(StorageAddress)], - [Sender.opcode, Instruction.deserialize.bind(Sender)], - [FunctionSelector.opcode, Instruction.deserialize.bind(FunctionSelector)], - [TransactionFee.opcode, Instruction.deserialize.bind(TransactionFee)], - // Execution Environment - Globals - [ChainId.opcode, Instruction.deserialize.bind(ChainId)], - [Version.opcode, Instruction.deserialize.bind(Version)], - [BlockNumber.opcode, Instruction.deserialize.bind(BlockNumber)], - [Timestamp.opcode, Instruction.deserialize.bind(Timestamp)], - [FeePerL2Gas.opcode, Instruction.deserialize.bind(FeePerL2Gas)], - [FeePerDAGas.opcode, Instruction.deserialize.bind(FeePerDAGas)], - // Execution Environment - Calldata + // Execution Environment + [Opcode.GETENVVAR_16, GetEnvVar.as(GetEnvVar.wireFormat16).deserialize], [CalldataCopy.opcode, Instruction.deserialize.bind(CalldataCopy)], - // Machine State - // Machine State - Gas - [L2GasLeft.opcode, Instruction.deserialize.bind(L2GasLeft)], - [DAGasLeft.opcode, Instruction.deserialize.bind(DAGasLeft)], // Machine State - Internal Control Flow [Jump.opcode, Instruction.deserialize.bind(Jump)], [JumpI.opcode, Instruction.deserialize.bind(JumpI)], diff --git a/yarn-project/simulator/src/avm/serialization/instruction_serialization.ts b/yarn-project/simulator/src/avm/serialization/instruction_serialization.ts index 9a458b2dfcf..182dc14c51d 100644 --- a/yarn-project/simulator/src/avm/serialization/instruction_serialization.ts +++ b/yarn-project/simulator/src/avm/serialization/instruction_serialization.ts @@ -39,21 +39,8 @@ export enum Opcode { CAST_8, CAST_16, // Execution environment - ADDRESS, - STORAGEADDRESS, - SENDER, - FUNCTIONSELECTOR, - TRANSACTIONFEE, - CHAINID, - VERSION, - BLOCKNUMBER, - TIMESTAMP, - FEEPERL2GAS, - FEEPERDAGAS, + GETENVVAR_16, CALLDATACOPY, - // Gas - L2GASLEFT, - DAGASLEFT, // Control flow JUMP_16, JUMPI_16, From 8606349e3ab2c0aa0731abbad50a6090acb00071 Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Mon, 23 Sep 2024 10:43:25 +0000 Subject: [PATCH 2/9] cpp compiling with todo --- .../vm/avm/trace/deserialization.cpp | 28 +---- .../barretenberg/vm/avm/trace/execution.cpp | 52 +-------- .../barretenberg/vm/avm/trace/fixed_gas.cpp | 14 +-- .../src/barretenberg/vm/avm/trace/opcode.cpp | 30 +---- .../src/barretenberg/vm/avm/trace/opcode.hpp | 16 +-- .../src/barretenberg/vm/avm/trace/trace.cpp | 106 ++++++++++++++---- .../src/barretenberg/vm/avm/trace/trace.hpp | 22 +++- 7 files changed, 122 insertions(+), 146 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/deserialization.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/deserialization.cpp index bede0c625a8..4bbea346ab1 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/deserialization.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/deserialization.cpp @@ -23,11 +23,6 @@ const std::vector three_operand_format16 = { }; const std::vector kernel_input_operand_format = { OperandType::INDIRECT, OperandType::UINT32 }; -const std::vector getter_format = { - OperandType::INDIRECT, - OperandType::UINT32, -}; - const std::vector external_call_format = { OperandType::INDIRECT, /*gasOffset=*/OperandType::UINT32, /*addrOffset=*/OperandType::UINT32, @@ -78,27 +73,16 @@ const std::unordered_map> OPCODE_WIRE_FORMAT = { OpCode::CAST_16, { OperandType::INDIRECT, OperandType::TAG, OperandType::UINT16, OperandType::UINT16 } }, // Execution Environment - Globals - { OpCode::ADDRESS, getter_format }, - { OpCode::STORAGEADDRESS, getter_format }, - { OpCode::SENDER, getter_format }, - { OpCode::FUNCTIONSELECTOR, getter_format }, - { OpCode::TRANSACTIONFEE, getter_format }, - // Execution Environment - Globals - { OpCode::CHAINID, getter_format }, - { OpCode::VERSION, getter_format }, - { OpCode::BLOCKNUMBER, getter_format }, - { OpCode::TIMESTAMP, getter_format }, - // Execution Environment - Globals - Gas - { OpCode::FEEPERL2GAS, getter_format }, - { OpCode::FEEPERDAGAS, getter_format }, + { OpCode::GETENVVAR_16, + { + OperandType::INDIRECT, + OperandType::UINT8, // var idx + OperandType::UINT16, + } }, // Execution Environment - Calldata { OpCode::CALLDATACOPY, { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, - // Machine State - Gas - { OpCode::L2GASLEFT, getter_format }, - { OpCode::DAGASLEFT, getter_format }, - // Machine State - Internal Control Flow { OpCode::JUMP_16, { OperandType::UINT16 } }, { OpCode::JUMPI_16, { OperandType::INDIRECT, OperandType::UINT16, OperandType::UINT16 } }, diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp index ba62c7d0cc0..7ce66021c96 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp @@ -670,46 +670,10 @@ std::vector Execution::gen_trace(std::vector const& instructio // Execution Environment // TODO(https://github.com/AztecProtocol/aztec-packages/issues/6284): support indirect for below - case OpCode::ADDRESS: - trace_builder.op_address(std::get(inst.operands.at(0)), std::get(inst.operands.at(1))); - break; - case OpCode::STORAGEADDRESS: - trace_builder.op_storage_address(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1))); - break; - case OpCode::SENDER: - trace_builder.op_sender(std::get(inst.operands.at(0)), std::get(inst.operands.at(1))); - break; - case OpCode::FUNCTIONSELECTOR: - trace_builder.op_function_selector(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1))); - break; - case OpCode::TRANSACTIONFEE: - trace_builder.op_transaction_fee(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1))); - break; - - // Execution Environment - Globals - case OpCode::CHAINID: - trace_builder.op_chain_id(std::get(inst.operands.at(0)), std::get(inst.operands.at(1))); - break; - case OpCode::VERSION: - trace_builder.op_version(std::get(inst.operands.at(0)), std::get(inst.operands.at(1))); - break; - case OpCode::BLOCKNUMBER: - trace_builder.op_block_number(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1))); - break; - case OpCode::TIMESTAMP: - trace_builder.op_timestamp(std::get(inst.operands.at(0)), std::get(inst.operands.at(1))); - break; - case OpCode::FEEPERL2GAS: - trace_builder.op_fee_per_l2_gas(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1))); - break; - case OpCode::FEEPERDAGAS: - trace_builder.op_fee_per_da_gas(std::get(inst.operands.at(0)), - std::get(inst.operands.at(1))); + case OpCode::GETENVVAR_16: + trace_builder.op_get_env_var(std::get(inst.operands.at(0)), + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2))); break; // Execution Environment - Calldata @@ -720,14 +684,6 @@ std::vector Execution::gen_trace(std::vector const& instructio std::get(inst.operands.at(3))); break; - // Machine State - Gas - case OpCode::L2GASLEFT: - trace_builder.op_l2gasleft(std::get(inst.operands.at(0)), std::get(inst.operands.at(1))); - break; - case OpCode::DAGASLEFT: - trace_builder.op_dagasleft(std::get(inst.operands.at(0)), std::get(inst.operands.at(1))); - break; - // Machine State - Internal Control Flow case OpCode::JUMP_16: trace_builder.op_jump(std::get(inst.operands.at(0))); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/fixed_gas.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/fixed_gas.cpp index e2c949b1031..018e8ad620d 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/fixed_gas.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/fixed_gas.cpp @@ -48,20 +48,8 @@ const std::unordered_map GAS_COST_TABLE = { { OpCode::SHR_16, make_cost(AVM_SHR_BASE_L2_GAS, 0, AVM_SHR_DYN_L2_GAS, 0) }, { OpCode::CAST_8, make_cost(AVM_CAST_BASE_L2_GAS, 0, AVM_CAST_DYN_L2_GAS, 0) }, { OpCode::CAST_16, make_cost(AVM_CAST_BASE_L2_GAS, 0, AVM_CAST_DYN_L2_GAS, 0) }, - { OpCode::ADDRESS, make_cost(AVM_ADDRESS_BASE_L2_GAS, 0, AVM_ADDRESS_DYN_L2_GAS, 0) }, - { OpCode::STORAGEADDRESS, make_cost(AVM_STORAGEADDRESS_BASE_L2_GAS, 0, AVM_STORAGEADDRESS_DYN_L2_GAS, 0) }, - { OpCode::SENDER, make_cost(AVM_SENDER_BASE_L2_GAS, 0, AVM_SENDER_DYN_L2_GAS, 0) }, - { OpCode::FUNCTIONSELECTOR, make_cost(AVM_FUNCTIONSELECTOR_BASE_L2_GAS, 0, AVM_FUNCTIONSELECTOR_DYN_L2_GAS, 0) }, - { OpCode::TRANSACTIONFEE, make_cost(AVM_TRANSACTIONFEE_BASE_L2_GAS, 0, AVM_TRANSACTIONFEE_DYN_L2_GAS, 0) }, - { OpCode::CHAINID, make_cost(AVM_CHAINID_BASE_L2_GAS, 0, AVM_CHAINID_DYN_L2_GAS, 0) }, - { OpCode::VERSION, make_cost(AVM_VERSION_BASE_L2_GAS, 0, AVM_VERSION_DYN_L2_GAS, 0) }, - { OpCode::BLOCKNUMBER, make_cost(AVM_BLOCKNUMBER_BASE_L2_GAS, 0, AVM_BLOCKNUMBER_DYN_L2_GAS, 0) }, - { OpCode::TIMESTAMP, make_cost(AVM_TIMESTAMP_BASE_L2_GAS, 0, AVM_TIMESTAMP_DYN_L2_GAS, 0) }, - { OpCode::FEEPERL2GAS, make_cost(AVM_FEEPERL2GAS_BASE_L2_GAS, 0, AVM_FEEPERL2GAS_DYN_L2_GAS, 0) }, - { OpCode::FEEPERDAGAS, make_cost(AVM_FEEPERDAGAS_BASE_L2_GAS, 0, AVM_FEEPERDAGAS_DYN_L2_GAS, 0) }, + { OpCode::GETENVVAR_16, make_cost(AVM_GETENVVAR_BASE_L2_GAS, 0, 0, 0) }, { OpCode::CALLDATACOPY, make_cost(AVM_CALLDATACOPY_BASE_L2_GAS, 0, AVM_CALLDATACOPY_DYN_L2_GAS, 0) }, - { OpCode::L2GASLEFT, make_cost(AVM_L2GASLEFT_BASE_L2_GAS, 0, AVM_L2GASLEFT_DYN_L2_GAS, 0) }, - { OpCode::DAGASLEFT, make_cost(AVM_DAGASLEFT_BASE_L2_GAS, 0, AVM_DAGASLEFT_DYN_L2_GAS, 0) }, { OpCode::JUMP_16, make_cost(AVM_JUMP_BASE_L2_GAS, 0, AVM_JUMP_DYN_L2_GAS, 0) }, { OpCode::JUMPI_16, make_cost(AVM_JUMPI_BASE_L2_GAS, 0, AVM_JUMPI_DYN_L2_GAS, 0) }, { OpCode::INTERNALCALL, make_cost(AVM_INTERNALCALL_BASE_L2_GAS, 0, AVM_INTERNALCALL_DYN_L2_GAS, 0) }, diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/opcode.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/opcode.cpp index 56d67fa90f9..91a6ba60ae3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/opcode.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/opcode.cpp @@ -88,38 +88,12 @@ std::string to_string(OpCode opcode) case OpCode::CAST_16: return "CAST_16"; // Execution Environment - case OpCode::ADDRESS: - return "ADDRESS"; - case OpCode::STORAGEADDRESS: - return "STORAGEADDRESS"; - case OpCode::SENDER: - return "SENDER"; - case OpCode::FUNCTIONSELECTOR: - return "FUNCTIONSELECTOR"; - case OpCode::TRANSACTIONFEE: - return "TRANSACTIONFEE"; - // Execution Environment - Globals - case OpCode::CHAINID: - return "CHAINID"; - case OpCode::VERSION: - return "VERSION"; - case OpCode::BLOCKNUMBER: - return "BLOCKNUMBER"; - case OpCode::TIMESTAMP: - return "TIMESTAMP"; - case OpCode::FEEPERL2GAS: - return "FEEPERL2GAS"; - case OpCode::FEEPERDAGAS: - return "FEEPERDAGAS"; + case OpCode::GETENVVAR_16: + return "GETENVVAR_16"; // Execution Environment - Calldata case OpCode::CALLDATACOPY: return "CALLDATACOPY"; // Machine State - // Machine State - Gas - case OpCode::L2GASLEFT: - return "L2GASLEFT"; - case OpCode::DAGASLEFT: - return "DAGASLEFT"; // Machine State - Internal Control Flow case OpCode::JUMP_16: return "JUMP_16"; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/opcode.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/opcode.hpp index 36ffca9234d..97dd50c033b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/opcode.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/opcode.hpp @@ -53,25 +53,11 @@ enum class OpCode : uint8_t { CAST_16, // Execution Environment - ADDRESS, - STORAGEADDRESS, - SENDER, - FUNCTIONSELECTOR, - TRANSACTIONFEE, - // Execution Environment - Globals - CHAINID, - VERSION, - BLOCKNUMBER, - TIMESTAMP, - FEEPERL2GAS, - FEEPERDAGAS, + GETENVVAR_16, // Execution Environment - Calldata CALLDATACOPY, // Machine State - // Machine State - Gas - L2GASLEFT, - DAGASLEFT, // Machine State - Internal Control Flow JUMP_16, JUMPI_16, diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp index 7e3eb6cad44..d3af5d62f2b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp @@ -1272,6 +1272,59 @@ Row AvmTraceBuilder::create_kernel_lookup_opcode(uint8_t indirect, uint32_t dst_ }; } +void AvmTraceBuilder::op_get_env_var(uint8_t indirect, uint8_t env_var, uint32_t dst_offset) +{ + ASSERT(env_var < static_cast(EnvironmentVariable::MAX_ENV_VAR)); + EnvironmentVariable var = static_cast(env_var); + + switch (var) { + case EnvironmentVariable::ADDRESS: + op_address(indirect, dst_offset); + break; + case EnvironmentVariable::STORAGEADDRESS: + op_storage_address(indirect, dst_offset); + break; + case EnvironmentVariable::SENDER: + op_sender(indirect, dst_offset); + break; + case EnvironmentVariable::FUNCTIONSELECTOR: + op_function_selector(indirect, dst_offset); + break; + case EnvironmentVariable::TRANSACTIONFEE: + op_transaction_fee(indirect, dst_offset); + break; + case EnvironmentVariable::CHAINID: + op_chain_id(indirect, dst_offset); + break; + case EnvironmentVariable::VERSION: + op_version(indirect, dst_offset); + break; + case EnvironmentVariable::BLOCKNUMBER: + op_block_number(indirect, dst_offset); + break; + case EnvironmentVariable::TIMESTAMP: + op_timestamp(indirect, dst_offset); + break; + case EnvironmentVariable::FEEPERL2GAS: + op_fee_per_l2_gas(indirect, dst_offset); + break; + case EnvironmentVariable::FEEPERDAGAS: + op_fee_per_da_gas(indirect, dst_offset); + break; + case EnvironmentVariable::ISSTATICCALL: + op_is_static_call(indirect, dst_offset); + break; + case EnvironmentVariable::L2GASLEFT: + op_l2gasleft(indirect, dst_offset); + break; + case EnvironmentVariable::DAGASLEFT: + op_dagasleft(indirect, dst_offset); + break; + default: + throw std::runtime_error("Invalid environment variable"); + } +} + void AvmTraceBuilder::op_address(uint8_t indirect, uint32_t dst_offset) { auto const clk = static_cast(main_trace.size()) + 1; @@ -1280,7 +1333,7 @@ void AvmTraceBuilder::op_address(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_address = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::ADDRESS); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::GETENVVAR_16); main_trace.push_back(row); } @@ -1293,7 +1346,7 @@ void AvmTraceBuilder::op_storage_address(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_storage_address = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::STORAGEADDRESS); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::GETENVVAR_16); main_trace.push_back(row); } @@ -1306,7 +1359,7 @@ void AvmTraceBuilder::op_sender(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_sender = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::SENDER); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::GETENVVAR_16); main_trace.push_back(row); } @@ -1319,7 +1372,7 @@ void AvmTraceBuilder::op_function_selector(uint8_t indirect, uint32_t dst_offset row.main_sel_op_function_selector = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::FUNCTIONSELECTOR); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::GETENVVAR_16); main_trace.push_back(row); } @@ -1332,11 +1385,26 @@ void AvmTraceBuilder::op_transaction_fee(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_transaction_fee = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::TRANSACTIONFEE); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::GETENVVAR_16); main_trace.push_back(row); } +void AvmTraceBuilder::op_is_static_call([[maybe_unused]] uint8_t indirect, [[maybe_unused]] uint32_t dst_offset) +{ + // TO BE IMPLEMENTED. + op_mov(0, 0, 0); + // auto const clk = static_cast(main_trace.size()) + 1; + // FF ia_value = kernel_trace_builder.op_is_static_call(clk); + // Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::U1); + // row.main_sel_op_is_static_call = FF(1); + + // // Constrain gas cost + // gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::GETENVVAR_16); + + // main_trace.push_back(row); +} + /************************************************************************************************** * EXECUTION ENVIRONMENT - GLOBALS **************************************************************************************************/ @@ -1349,7 +1417,7 @@ void AvmTraceBuilder::op_chain_id(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_chain_id = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::CHAINID); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::GETENVVAR_16); main_trace.push_back(row); } @@ -1362,7 +1430,7 @@ void AvmTraceBuilder::op_version(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_version = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::VERSION); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::GETENVVAR_16); main_trace.push_back(row); } @@ -1375,7 +1443,7 @@ void AvmTraceBuilder::op_block_number(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_block_number = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::BLOCKNUMBER); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::GETENVVAR_16); main_trace.push_back(row); } @@ -1388,7 +1456,7 @@ void AvmTraceBuilder::op_timestamp(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_timestamp = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::TIMESTAMP); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::GETENVVAR_16); main_trace.push_back(row); } @@ -1401,7 +1469,7 @@ void AvmTraceBuilder::op_fee_per_l2_gas(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_fee_per_l2_gas = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::FEEPERL2GAS); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::GETENVVAR_16); main_trace.push_back(row); } @@ -1414,7 +1482,7 @@ void AvmTraceBuilder::op_fee_per_da_gas(uint8_t indirect, uint32_t dst_offset) row.main_sel_op_fee_per_da_gas = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::FEEPERDAGAS); + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::GETENVVAR_16); main_trace.push_back(row); } @@ -1504,20 +1572,20 @@ void AvmTraceBuilder::op_calldata_copy(uint8_t indirect, **************************************************************************************************/ // Helper for "gas left" related opcodes -void AvmTraceBuilder::execute_gasleft(OpCode opcode, uint8_t indirect, uint32_t dst_offset) +void AvmTraceBuilder::execute_gasleft(EnvironmentVariable var, uint8_t indirect, uint32_t dst_offset) { - assert(opcode == OpCode::L2GASLEFT || opcode == OpCode::DAGASLEFT); + assert(var == EnvironmentVariable::L2GASLEFT || var == EnvironmentVariable::DAGASLEFT); auto clk = static_cast(main_trace.size()) + 1; auto [resolved_dst] = unpack_indirects<1>(indirect, { dst_offset }); // Constrain gas cost - gas_trace_builder.constrain_gas(clk, opcode); + gas_trace_builder.constrain_gas(clk, OpCode::GETENVVAR_16); uint32_t gas_remaining = 0; - if (opcode == OpCode::L2GASLEFT) { + if (var == EnvironmentVariable::L2GASLEFT) { gas_remaining = gas_trace_builder.get_l2_gas_left(); } else { gas_remaining = gas_trace_builder.get_da_gas_left(); @@ -1539,8 +1607,8 @@ void AvmTraceBuilder::execute_gasleft(OpCode opcode, uint8_t indirect, uint32_t .main_r_in_tag = FF(static_cast(AvmMemoryTag::U0)), .main_rwa = FF(1), .main_sel_mem_op_a = FF(1), - .main_sel_op_dagasleft = (opcode == OpCode::DAGASLEFT) ? FF(1) : FF(0), - .main_sel_op_l2gasleft = (opcode == OpCode::L2GASLEFT) ? FF(1) : FF(0), + .main_sel_op_dagasleft = (var == EnvironmentVariable::DAGASLEFT) ? FF(1) : FF(0), + .main_sel_op_l2gasleft = (var == EnvironmentVariable::L2GASLEFT) ? FF(1) : FF(0), .main_sel_resolve_ind_addr_a = FF(static_cast(is_operand_indirect(indirect, 0))), .main_tag_err = FF(static_cast(!write_dst.tag_match)), .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), // TODO: probably will be U32 in final version @@ -1550,12 +1618,12 @@ void AvmTraceBuilder::execute_gasleft(OpCode opcode, uint8_t indirect, uint32_t void AvmTraceBuilder::op_l2gasleft(uint8_t indirect, uint32_t dst_offset) { - execute_gasleft(OpCode::L2GASLEFT, indirect, dst_offset); + execute_gasleft(EnvironmentVariable::L2GASLEFT, indirect, dst_offset); } void AvmTraceBuilder::op_dagasleft(uint8_t indirect, uint32_t dst_offset) { - execute_gasleft(OpCode::DAGASLEFT, indirect, dst_offset); + execute_gasleft(EnvironmentVariable::DAGASLEFT, indirect, dst_offset); } /************************************************************************************************** diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp index 6390d6a1aba..a28b336c454 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp @@ -83,11 +83,13 @@ class AvmTraceBuilder { void op_cast(uint8_t indirect, uint32_t a_offset, uint32_t dst_offset, AvmMemoryTag dst_tag); // Execution Environment + void op_get_env_var(uint8_t indirect, uint8_t env_var, uint32_t dst_offset); void op_address(uint8_t indirect, uint32_t dst_offset); void op_storage_address(uint8_t indirect, uint32_t dst_offset); void op_sender(uint8_t indirect, uint32_t dst_offset); void op_function_selector(uint8_t indirect, uint32_t dst_offset); void op_transaction_fee(uint8_t indirect, uint32_t dst_offset); + void op_is_static_call(uint8_t indirect, uint32_t dst_offset); // Execution Environment - Globals void op_chain_id(uint8_t indirect, uint32_t dst_offset); @@ -289,7 +291,25 @@ class AvmTraceBuilder { uint32_t success_offset, [[maybe_unused]] uint32_t function_selector_offset); - void execute_gasleft(OpCode opcode, uint8_t indirect, uint32_t dst_offset); + enum class EnvironmentVariable { + ADDRESS, + STORAGEADDRESS, + SENDER, + FUNCTIONSELECTOR, + TRANSACTIONFEE, + CHAINID, + VERSION, + BLOCKNUMBER, + TIMESTAMP, + FEEPERL2GAS, + FEEPERDAGAS, + ISSTATICCALL, + L2GASLEFT, + DAGASLEFT, + // sentinel + MAX_ENV_VAR + }; + void execute_gasleft(EnvironmentVariable var, uint8_t indirect, uint32_t dst_offset); void finalise_mem_trace_lookup_counts(); From 1a06b00a694583b25b2bf038d4091caf51db7418 Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Mon, 23 Sep 2024 10:58:45 +0000 Subject: [PATCH 3/9] is_static_call impl --- barretenberg/cpp/pil/avm/constants_gen.pil | 1 + barretenberg/cpp/pil/avm/kernel.pil | 9 +- barretenberg/cpp/pil/avm/main.pil | 2 + .../vm/avm/generated/circuit_builder.cpp | 1 + .../barretenberg/vm/avm/generated/flavor.cpp | 1083 +++++++++-------- .../barretenberg/vm/avm/generated/flavor.hpp | 6 +- .../vm/avm/generated/full_row.cpp | 2 + .../vm/avm/generated/full_row.hpp | 3 +- .../vm/avm/generated/relations/kernel.hpp | 150 +-- .../vm/avm/generated/relations/main.hpp | 304 ++--- .../vm/avm/trace/kernel_trace.cpp | 28 +- .../vm/avm/trace/kernel_trace.hpp | 2 + .../src/barretenberg/vm/avm/trace/trace.cpp | 18 +- .../src/barretenberg/vm/aztec_constants.hpp | 3 +- .../src/core/libraries/ConstantsGen.sol | 1 + .../crates/types/src/constants.nr | 3 +- yarn-project/circuits.js/src/constants.gen.ts | 3 +- .../circuits.js/src/scripts/constants.in.ts | 2 + 18 files changed, 828 insertions(+), 793 deletions(-) diff --git a/barretenberg/cpp/pil/avm/constants_gen.pil b/barretenberg/cpp/pil/avm/constants_gen.pil index 04af42fb49c..be8d4bfae2c 100644 --- a/barretenberg/cpp/pil/avm/constants_gen.pil +++ b/barretenberg/cpp/pil/avm/constants_gen.pil @@ -22,6 +22,7 @@ namespace constants(256); pol ADDRESS_SELECTOR = 1; pol STORAGE_ADDRESS_SELECTOR = 1; pol FUNCTION_SELECTOR_SELECTOR = 2; + pol IS_STATIC_CALL_SELECTOR = 4; pol START_GLOBAL_VARIABLES = 29; pol CHAIN_ID_SELECTOR = 29; pol VERSION_SELECTOR = 30; diff --git a/barretenberg/cpp/pil/avm/kernel.pil b/barretenberg/cpp/pil/avm/kernel.pil index fce9aec35be..bdd555426fb 100644 --- a/barretenberg/cpp/pil/avm/kernel.pil +++ b/barretenberg/cpp/pil/avm/kernel.pil @@ -22,9 +22,9 @@ namespace main(256); pol commit sel_kernel_out; // Kernel Outputs - // + // // The current implementation of kernel outputs is described within https://hackmd.io/zP1oMXF6Rf-L-ZZLXWmfHg - + // Global side effect counter; incremented after each side effect is produced. pol commit side_effect_counter; @@ -98,6 +98,9 @@ namespace main(256); #[FEE_TRANSACTION_FEE_KERNEL] sel_op_transaction_fee * (kernel_in_offset - constants.TRANSACTION_FEE_SELECTOR) = 0; + #[IS_STATIC_CALL_KERNEL] + sel_op_is_static_call * (kernel_in_offset - constants.IS_STATIC_CALL_SELECTOR) = 0; + // CONTEXT - ENVIRONMENT - GLOBALS #[CHAIN_ID_KERNEL] sel_op_chain_id * (kernel_in_offset - constants.CHAIN_ID_SELECTOR) = 0; @@ -123,7 +126,7 @@ namespace main(256); #[NOTE_HASH_KERNEL_OUTPUT] sel_op_note_hash_exists * (kernel_out_offset - (constants.START_NOTE_HASH_EXISTS_WRITE_OFFSET + note_hash_exist_write_offset)) = 0; sel_first * note_hash_exist_write_offset = 0; - + #[EMIT_NOTE_HASH_KERNEL_OUTPUT] sel_op_emit_note_hash * (kernel_out_offset - (constants.START_EMIT_NOTE_HASH_WRITE_OFFSET + emit_note_hash_write_offset)) = 0; sel_first * emit_note_hash_write_offset = 0; diff --git a/barretenberg/cpp/pil/avm/main.pil b/barretenberg/cpp/pil/avm/main.pil index afef1b00e78..29840e932b5 100644 --- a/barretenberg/cpp/pil/avm/main.pil +++ b/barretenberg/cpp/pil/avm/main.pil @@ -46,6 +46,7 @@ namespace main(256); pol commit sel_op_sender; pol commit sel_op_function_selector; pol commit sel_op_transaction_fee; + pol commit sel_op_is_static_call; // CONTEXT - ENVIRONMENT - GLOBALS pol commit sel_op_chain_id; @@ -227,6 +228,7 @@ namespace main(256); sel_op_timestamp * (1 - sel_op_timestamp) = 0; sel_op_fee_per_l2_gas * (1 - sel_op_fee_per_l2_gas) = 0; sel_op_fee_per_da_gas * (1 - sel_op_fee_per_da_gas) = 0; + sel_op_is_static_call * (1 - sel_op_is_static_call) = 0; // MACHINE STATE - GAS sel_op_l2gasleft * (1 - sel_op_l2gasleft) = 0; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp index fcd0da7e015..6606d0667ec 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp @@ -257,6 +257,7 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co rows[i].main_sel_op_get_contract_instance); polys.main_sel_op_internal_call.set_if_valid_index(i, rows[i].main_sel_op_internal_call); polys.main_sel_op_internal_return.set_if_valid_index(i, rows[i].main_sel_op_internal_return); + polys.main_sel_op_is_static_call.set_if_valid_index(i, rows[i].main_sel_op_is_static_call); polys.main_sel_op_jump.set_if_valid_index(i, rows[i].main_sel_op_jump); polys.main_sel_op_jumpi.set_if_valid_index(i, rows[i].main_sel_op_jumpi); polys.main_sel_op_keccak.set_if_valid_index(i, rows[i].main_sel_op_keccak); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp index 0ab8cb1aad5..0ff1bdefc96 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp @@ -209,546 +209,547 @@ AvmFlavor::AllConstRefValues::AllConstRefValues( , main_sel_op_get_contract_instance(il[201]) , main_sel_op_internal_call(il[202]) , main_sel_op_internal_return(il[203]) - , main_sel_op_jump(il[204]) - , main_sel_op_jumpi(il[205]) - , main_sel_op_keccak(il[206]) - , main_sel_op_l1_to_l2_msg_exists(il[207]) - , main_sel_op_l2gasleft(il[208]) - , main_sel_op_lt(il[209]) - , main_sel_op_lte(il[210]) - , main_sel_op_mov(il[211]) - , main_sel_op_msm(il[212]) - , main_sel_op_mul(il[213]) - , main_sel_op_not(il[214]) - , main_sel_op_note_hash_exists(il[215]) - , main_sel_op_nullifier_exists(il[216]) - , main_sel_op_or(il[217]) - , main_sel_op_pedersen(il[218]) - , main_sel_op_pedersen_commit(il[219]) - , main_sel_op_poseidon2(il[220]) - , main_sel_op_radix_le(il[221]) - , main_sel_op_sender(il[222]) - , main_sel_op_set(il[223]) - , main_sel_op_sha256(il[224]) - , main_sel_op_shl(il[225]) - , main_sel_op_shr(il[226]) - , main_sel_op_sload(il[227]) - , main_sel_op_sstore(il[228]) - , main_sel_op_static_call(il[229]) - , main_sel_op_storage_address(il[230]) - , main_sel_op_sub(il[231]) - , main_sel_op_timestamp(il[232]) - , main_sel_op_transaction_fee(il[233]) - , main_sel_op_version(il[234]) - , main_sel_op_xor(il[235]) - , main_sel_q_kernel_lookup(il[236]) - , main_sel_q_kernel_output_lookup(il[237]) - , main_sel_resolve_ind_addr_a(il[238]) - , main_sel_resolve_ind_addr_b(il[239]) - , main_sel_resolve_ind_addr_c(il[240]) - , main_sel_resolve_ind_addr_d(il[241]) - , main_sel_returndata(il[242]) - , main_sel_rng_16(il[243]) - , main_sel_rng_8(il[244]) - , main_sel_slice_gadget(il[245]) - , main_side_effect_counter(il[246]) - , main_sload_write_offset(il[247]) - , main_space_id(il[248]) - , main_sstore_write_offset(il[249]) - , main_tag_err(il[250]) - , main_w_in_tag(il[251]) - , mem_addr(il[252]) - , mem_clk(il[253]) - , mem_diff(il[254]) - , mem_glob_addr(il[255]) - , mem_last(il[256]) - , mem_lastAccess(il[257]) - , mem_one_min_inv(il[258]) - , mem_r_in_tag(il[259]) - , mem_rw(il[260]) - , mem_sel_mem(il[261]) - , mem_sel_mov_ia_to_ic(il[262]) - , mem_sel_mov_ib_to_ic(il[263]) - , mem_sel_op_a(il[264]) - , mem_sel_op_b(il[265]) - , mem_sel_op_c(il[266]) - , mem_sel_op_cmov(il[267]) - , mem_sel_op_d(il[268]) - , mem_sel_op_poseidon_read_a(il[269]) - , mem_sel_op_poseidon_read_b(il[270]) - , mem_sel_op_poseidon_read_c(il[271]) - , mem_sel_op_poseidon_read_d(il[272]) - , mem_sel_op_poseidon_write_a(il[273]) - , mem_sel_op_poseidon_write_b(il[274]) - , mem_sel_op_poseidon_write_c(il[275]) - , mem_sel_op_poseidon_write_d(il[276]) - , mem_sel_op_slice(il[277]) - , mem_sel_resolve_ind_addr_a(il[278]) - , mem_sel_resolve_ind_addr_b(il[279]) - , mem_sel_resolve_ind_addr_c(il[280]) - , mem_sel_resolve_ind_addr_d(il[281]) - , mem_sel_rng_chk(il[282]) - , mem_skip_check_tag(il[283]) - , mem_space_id(il[284]) - , mem_tag(il[285]) - , mem_tag_err(il[286]) - , mem_tsp(il[287]) - , mem_val(il[288]) - , mem_w_in_tag(il[289]) - , pedersen_clk(il[290]) - , pedersen_input(il[291]) - , pedersen_output(il[292]) - , pedersen_sel_pedersen(il[293]) - , poseidon2_B_10_0(il[294]) - , poseidon2_B_10_1(il[295]) - , poseidon2_B_10_2(il[296]) - , poseidon2_B_10_3(il[297]) - , poseidon2_B_11_0(il[298]) - , poseidon2_B_11_1(il[299]) - , poseidon2_B_11_2(il[300]) - , poseidon2_B_11_3(il[301]) - , poseidon2_B_12_0(il[302]) - , poseidon2_B_12_1(il[303]) - , poseidon2_B_12_2(il[304]) - , poseidon2_B_12_3(il[305]) - , poseidon2_B_13_0(il[306]) - , poseidon2_B_13_1(il[307]) - , poseidon2_B_13_2(il[308]) - , poseidon2_B_13_3(il[309]) - , poseidon2_B_14_0(il[310]) - , poseidon2_B_14_1(il[311]) - , poseidon2_B_14_2(il[312]) - , poseidon2_B_14_3(il[313]) - , poseidon2_B_15_0(il[314]) - , poseidon2_B_15_1(il[315]) - , poseidon2_B_15_2(il[316]) - , poseidon2_B_15_3(il[317]) - , poseidon2_B_16_0(il[318]) - , poseidon2_B_16_1(il[319]) - , poseidon2_B_16_2(il[320]) - , poseidon2_B_16_3(il[321]) - , poseidon2_B_17_0(il[322]) - , poseidon2_B_17_1(il[323]) - , poseidon2_B_17_2(il[324]) - , poseidon2_B_17_3(il[325]) - , poseidon2_B_18_0(il[326]) - , poseidon2_B_18_1(il[327]) - , poseidon2_B_18_2(il[328]) - , poseidon2_B_18_3(il[329]) - , poseidon2_B_19_0(il[330]) - , poseidon2_B_19_1(il[331]) - , poseidon2_B_19_2(il[332]) - , poseidon2_B_19_3(il[333]) - , poseidon2_B_20_0(il[334]) - , poseidon2_B_20_1(il[335]) - , poseidon2_B_20_2(il[336]) - , poseidon2_B_20_3(il[337]) - , poseidon2_B_21_0(il[338]) - , poseidon2_B_21_1(il[339]) - , poseidon2_B_21_2(il[340]) - , poseidon2_B_21_3(il[341]) - , poseidon2_B_22_0(il[342]) - , poseidon2_B_22_1(il[343]) - , poseidon2_B_22_2(il[344]) - , poseidon2_B_22_3(il[345]) - , poseidon2_B_23_0(il[346]) - , poseidon2_B_23_1(il[347]) - , poseidon2_B_23_2(il[348]) - , poseidon2_B_23_3(il[349]) - , poseidon2_B_24_0(il[350]) - , poseidon2_B_24_1(il[351]) - , poseidon2_B_24_2(il[352]) - , poseidon2_B_24_3(il[353]) - , poseidon2_B_25_0(il[354]) - , poseidon2_B_25_1(il[355]) - , poseidon2_B_25_2(il[356]) - , poseidon2_B_25_3(il[357]) - , poseidon2_B_26_0(il[358]) - , poseidon2_B_26_1(il[359]) - , poseidon2_B_26_2(il[360]) - , poseidon2_B_26_3(il[361]) - , poseidon2_B_27_0(il[362]) - , poseidon2_B_27_1(il[363]) - , poseidon2_B_27_2(il[364]) - , poseidon2_B_27_3(il[365]) - , poseidon2_B_28_0(il[366]) - , poseidon2_B_28_1(il[367]) - , poseidon2_B_28_2(il[368]) - , poseidon2_B_28_3(il[369]) - , poseidon2_B_29_0(il[370]) - , poseidon2_B_29_1(il[371]) - , poseidon2_B_29_2(il[372]) - , poseidon2_B_29_3(il[373]) - , poseidon2_B_30_0(il[374]) - , poseidon2_B_30_1(il[375]) - , poseidon2_B_30_2(il[376]) - , poseidon2_B_30_3(il[377]) - , poseidon2_B_31_0(il[378]) - , poseidon2_B_31_1(il[379]) - , poseidon2_B_31_2(il[380]) - , poseidon2_B_31_3(il[381]) - , poseidon2_B_32_0(il[382]) - , poseidon2_B_32_1(il[383]) - , poseidon2_B_32_2(il[384]) - , poseidon2_B_32_3(il[385]) - , poseidon2_B_33_0(il[386]) - , poseidon2_B_33_1(il[387]) - , poseidon2_B_33_2(il[388]) - , poseidon2_B_33_3(il[389]) - , poseidon2_B_34_0(il[390]) - , poseidon2_B_34_1(il[391]) - , poseidon2_B_34_2(il[392]) - , poseidon2_B_34_3(il[393]) - , poseidon2_B_35_0(il[394]) - , poseidon2_B_35_1(il[395]) - , poseidon2_B_35_2(il[396]) - , poseidon2_B_35_3(il[397]) - , poseidon2_B_36_0(il[398]) - , poseidon2_B_36_1(il[399]) - , poseidon2_B_36_2(il[400]) - , poseidon2_B_36_3(il[401]) - , poseidon2_B_37_0(il[402]) - , poseidon2_B_37_1(il[403]) - , poseidon2_B_37_2(il[404]) - , poseidon2_B_37_3(il[405]) - , poseidon2_B_38_0(il[406]) - , poseidon2_B_38_1(il[407]) - , poseidon2_B_38_2(il[408]) - , poseidon2_B_38_3(il[409]) - , poseidon2_B_39_0(il[410]) - , poseidon2_B_39_1(il[411]) - , poseidon2_B_39_2(il[412]) - , poseidon2_B_39_3(il[413]) - , poseidon2_B_40_0(il[414]) - , poseidon2_B_40_1(il[415]) - , poseidon2_B_40_2(il[416]) - , poseidon2_B_40_3(il[417]) - , poseidon2_B_41_0(il[418]) - , poseidon2_B_41_1(il[419]) - , poseidon2_B_41_2(il[420]) - , poseidon2_B_41_3(il[421]) - , poseidon2_B_42_0(il[422]) - , poseidon2_B_42_1(il[423]) - , poseidon2_B_42_2(il[424]) - , poseidon2_B_42_3(il[425]) - , poseidon2_B_43_0(il[426]) - , poseidon2_B_43_1(il[427]) - , poseidon2_B_43_2(il[428]) - , poseidon2_B_43_3(il[429]) - , poseidon2_B_44_0(il[430]) - , poseidon2_B_44_1(il[431]) - , poseidon2_B_44_2(il[432]) - , poseidon2_B_44_3(il[433]) - , poseidon2_B_45_0(il[434]) - , poseidon2_B_45_1(il[435]) - , poseidon2_B_45_2(il[436]) - , poseidon2_B_45_3(il[437]) - , poseidon2_B_46_0(il[438]) - , poseidon2_B_46_1(il[439]) - , poseidon2_B_46_2(il[440]) - , poseidon2_B_46_3(il[441]) - , poseidon2_B_47_0(il[442]) - , poseidon2_B_47_1(il[443]) - , poseidon2_B_47_2(il[444]) - , poseidon2_B_47_3(il[445]) - , poseidon2_B_48_0(il[446]) - , poseidon2_B_48_1(il[447]) - , poseidon2_B_48_2(il[448]) - , poseidon2_B_48_3(il[449]) - , poseidon2_B_49_0(il[450]) - , poseidon2_B_49_1(il[451]) - , poseidon2_B_49_2(il[452]) - , poseidon2_B_49_3(il[453]) - , poseidon2_B_4_0(il[454]) - , poseidon2_B_4_1(il[455]) - , poseidon2_B_4_2(il[456]) - , poseidon2_B_4_3(il[457]) - , poseidon2_B_50_0(il[458]) - , poseidon2_B_50_1(il[459]) - , poseidon2_B_50_2(il[460]) - , poseidon2_B_50_3(il[461]) - , poseidon2_B_51_0(il[462]) - , poseidon2_B_51_1(il[463]) - , poseidon2_B_51_2(il[464]) - , poseidon2_B_51_3(il[465]) - , poseidon2_B_52_0(il[466]) - , poseidon2_B_52_1(il[467]) - , poseidon2_B_52_2(il[468]) - , poseidon2_B_52_3(il[469]) - , poseidon2_B_53_0(il[470]) - , poseidon2_B_53_1(il[471]) - , poseidon2_B_53_2(il[472]) - , poseidon2_B_53_3(il[473]) - , poseidon2_B_54_0(il[474]) - , poseidon2_B_54_1(il[475]) - , poseidon2_B_54_2(il[476]) - , poseidon2_B_54_3(il[477]) - , poseidon2_B_55_0(il[478]) - , poseidon2_B_55_1(il[479]) - , poseidon2_B_55_2(il[480]) - , poseidon2_B_55_3(il[481]) - , poseidon2_B_56_0(il[482]) - , poseidon2_B_56_1(il[483]) - , poseidon2_B_56_2(il[484]) - , poseidon2_B_56_3(il[485]) - , poseidon2_B_57_0(il[486]) - , poseidon2_B_57_1(il[487]) - , poseidon2_B_57_2(il[488]) - , poseidon2_B_57_3(il[489]) - , poseidon2_B_58_0(il[490]) - , poseidon2_B_58_1(il[491]) - , poseidon2_B_58_2(il[492]) - , poseidon2_B_58_3(il[493]) - , poseidon2_B_59_0(il[494]) - , poseidon2_B_59_1(il[495]) - , poseidon2_B_59_2(il[496]) - , poseidon2_B_59_3(il[497]) - , poseidon2_B_5_0(il[498]) - , poseidon2_B_5_1(il[499]) - , poseidon2_B_5_2(il[500]) - , poseidon2_B_5_3(il[501]) - , poseidon2_B_6_0(il[502]) - , poseidon2_B_6_1(il[503]) - , poseidon2_B_6_2(il[504]) - , poseidon2_B_6_3(il[505]) - , poseidon2_B_7_0(il[506]) - , poseidon2_B_7_1(il[507]) - , poseidon2_B_7_2(il[508]) - , poseidon2_B_7_3(il[509]) - , poseidon2_B_8_0(il[510]) - , poseidon2_B_8_1(il[511]) - , poseidon2_B_8_2(il[512]) - , poseidon2_B_8_3(il[513]) - , poseidon2_B_9_0(il[514]) - , poseidon2_B_9_1(il[515]) - , poseidon2_B_9_2(il[516]) - , poseidon2_B_9_3(il[517]) - , poseidon2_EXT_LAYER_4(il[518]) - , poseidon2_EXT_LAYER_5(il[519]) - , poseidon2_EXT_LAYER_6(il[520]) - , poseidon2_EXT_LAYER_7(il[521]) - , poseidon2_T_0_4(il[522]) - , poseidon2_T_0_5(il[523]) - , poseidon2_T_0_6(il[524]) - , poseidon2_T_0_7(il[525]) - , poseidon2_T_1_4(il[526]) - , poseidon2_T_1_5(il[527]) - , poseidon2_T_1_6(il[528]) - , poseidon2_T_1_7(il[529]) - , poseidon2_T_2_4(il[530]) - , poseidon2_T_2_5(il[531]) - , poseidon2_T_2_6(il[532]) - , poseidon2_T_2_7(il[533]) - , poseidon2_T_3_4(il[534]) - , poseidon2_T_3_5(il[535]) - , poseidon2_T_3_6(il[536]) - , poseidon2_T_3_7(il[537]) - , poseidon2_T_60_4(il[538]) - , poseidon2_T_60_5(il[539]) - , poseidon2_T_60_6(il[540]) - , poseidon2_T_60_7(il[541]) - , poseidon2_T_61_4(il[542]) - , poseidon2_T_61_5(il[543]) - , poseidon2_T_61_6(il[544]) - , poseidon2_T_61_7(il[545]) - , poseidon2_T_62_4(il[546]) - , poseidon2_T_62_5(il[547]) - , poseidon2_T_62_6(il[548]) - , poseidon2_T_62_7(il[549]) - , poseidon2_T_63_4(il[550]) - , poseidon2_T_63_5(il[551]) - , poseidon2_T_63_6(il[552]) - , poseidon2_T_63_7(il[553]) - , poseidon2_a_0(il[554]) - , poseidon2_a_1(il[555]) - , poseidon2_a_2(il[556]) - , poseidon2_a_3(il[557]) - , poseidon2_b_0(il[558]) - , poseidon2_b_1(il[559]) - , poseidon2_b_2(il[560]) - , poseidon2_b_3(il[561]) - , poseidon2_clk(il[562]) - , poseidon2_input_addr(il[563]) - , poseidon2_mem_addr_read_a(il[564]) - , poseidon2_mem_addr_read_b(il[565]) - , poseidon2_mem_addr_read_c(il[566]) - , poseidon2_mem_addr_read_d(il[567]) - , poseidon2_mem_addr_write_a(il[568]) - , poseidon2_mem_addr_write_b(il[569]) - , poseidon2_mem_addr_write_c(il[570]) - , poseidon2_mem_addr_write_d(il[571]) - , poseidon2_output_addr(il[572]) - , poseidon2_sel_poseidon_perm(il[573]) - , range_check_alu_rng_chk(il[574]) - , range_check_clk(il[575]) - , range_check_cmp_hi_bits_rng_chk(il[576]) - , range_check_cmp_lo_bits_rng_chk(il[577]) - , range_check_dyn_diff(il[578]) - , range_check_dyn_rng_chk_bits(il[579]) - , range_check_dyn_rng_chk_pow_2(il[580]) - , range_check_gas_da_rng_chk(il[581]) - , range_check_gas_l2_rng_chk(il[582]) - , range_check_is_lte_u112(il[583]) - , range_check_is_lte_u128(il[584]) - , range_check_is_lte_u16(il[585]) - , range_check_is_lte_u32(il[586]) - , range_check_is_lte_u48(il[587]) - , range_check_is_lte_u64(il[588]) - , range_check_is_lte_u80(il[589]) - , range_check_is_lte_u96(il[590]) - , range_check_mem_rng_chk(il[591]) - , range_check_rng_chk_bits(il[592]) - , range_check_sel_lookup_0(il[593]) - , range_check_sel_lookup_1(il[594]) - , range_check_sel_lookup_2(il[595]) - , range_check_sel_lookup_3(il[596]) - , range_check_sel_lookup_4(il[597]) - , range_check_sel_lookup_5(il[598]) - , range_check_sel_lookup_6(il[599]) - , range_check_sel_rng_chk(il[600]) - , range_check_u16_r0(il[601]) - , range_check_u16_r1(il[602]) - , range_check_u16_r2(il[603]) - , range_check_u16_r3(il[604]) - , range_check_u16_r4(il[605]) - , range_check_u16_r5(il[606]) - , range_check_u16_r6(il[607]) - , range_check_u16_r7(il[608]) - , range_check_value(il[609]) - , sha256_clk(il[610]) - , sha256_input(il[611]) - , sha256_output(il[612]) - , sha256_sel_sha256_compression(il[613]) - , sha256_state(il[614]) - , slice_addr(il[615]) - , slice_clk(il[616]) - , slice_cnt(il[617]) - , slice_col_offset(il[618]) - , slice_one_min_inv(il[619]) - , slice_sel_cd_cpy(il[620]) - , slice_sel_mem_active(il[621]) - , slice_sel_return(il[622]) - , slice_sel_start(il[623]) - , slice_space_id(il[624]) - , slice_val(il[625]) - , lookup_rng_chk_pow_2_counts(il[626]) - , lookup_rng_chk_diff_counts(il[627]) - , lookup_rng_chk_0_counts(il[628]) - , lookup_rng_chk_1_counts(il[629]) - , lookup_rng_chk_2_counts(il[630]) - , lookup_rng_chk_3_counts(il[631]) - , lookup_rng_chk_4_counts(il[632]) - , lookup_rng_chk_5_counts(il[633]) - , lookup_rng_chk_6_counts(il[634]) - , lookup_rng_chk_7_counts(il[635]) - , lookup_pow_2_0_counts(il[636]) - , lookup_pow_2_1_counts(il[637]) - , lookup_byte_lengths_counts(il[638]) - , lookup_byte_operations_counts(il[639]) - , lookup_opcode_gas_counts(il[640]) - , kernel_output_lookup_counts(il[641]) - , lookup_into_kernel_counts(il[642]) - , lookup_cd_value_counts(il[643]) - , lookup_ret_value_counts(il[644]) - , incl_main_tag_err_counts(il[645]) - , incl_mem_tag_err_counts(il[646]) - , perm_rng_mem_inv(il[647]) - , perm_rng_cmp_lo_inv(il[648]) - , perm_rng_cmp_hi_inv(il[649]) - , perm_rng_alu_inv(il[650]) - , perm_cmp_alu_inv(il[651]) - , perm_rng_gas_l2_inv(il[652]) - , perm_rng_gas_da_inv(il[653]) - , perm_pos_mem_read_a_inv(il[654]) - , perm_pos_mem_read_b_inv(il[655]) - , perm_pos_mem_read_c_inv(il[656]) - , perm_pos_mem_read_d_inv(il[657]) - , perm_pos_mem_write_a_inv(il[658]) - , perm_pos_mem_write_b_inv(il[659]) - , perm_pos_mem_write_c_inv(il[660]) - , perm_pos_mem_write_d_inv(il[661]) - , perm_slice_mem_inv(il[662]) - , perm_main_alu_inv(il[663]) - , perm_main_bin_inv(il[664]) - , perm_main_conv_inv(il[665]) - , perm_main_pos2_perm_inv(il[666]) - , perm_main_pedersen_inv(il[667]) - , perm_main_slice_inv(il[668]) - , perm_main_mem_a_inv(il[669]) - , perm_main_mem_b_inv(il[670]) - , perm_main_mem_c_inv(il[671]) - , perm_main_mem_d_inv(il[672]) - , perm_main_mem_ind_addr_a_inv(il[673]) - , perm_main_mem_ind_addr_b_inv(il[674]) - , perm_main_mem_ind_addr_c_inv(il[675]) - , perm_main_mem_ind_addr_d_inv(il[676]) - , lookup_rng_chk_pow_2_inv(il[677]) - , lookup_rng_chk_diff_inv(il[678]) - , lookup_rng_chk_0_inv(il[679]) - , lookup_rng_chk_1_inv(il[680]) - , lookup_rng_chk_2_inv(il[681]) - , lookup_rng_chk_3_inv(il[682]) - , lookup_rng_chk_4_inv(il[683]) - , lookup_rng_chk_5_inv(il[684]) - , lookup_rng_chk_6_inv(il[685]) - , lookup_rng_chk_7_inv(il[686]) - , lookup_pow_2_0_inv(il[687]) - , lookup_pow_2_1_inv(il[688]) - , lookup_byte_lengths_inv(il[689]) - , lookup_byte_operations_inv(il[690]) - , lookup_opcode_gas_inv(il[691]) - , kernel_output_lookup_inv(il[692]) - , lookup_into_kernel_inv(il[693]) - , lookup_cd_value_inv(il[694]) - , lookup_ret_value_inv(il[695]) - , incl_main_tag_err_inv(il[696]) - , incl_mem_tag_err_inv(il[697]) - , binary_acc_ia_shift(il[698]) - , binary_acc_ib_shift(il[699]) - , binary_acc_ic_shift(il[700]) - , binary_mem_tag_ctr_shift(il[701]) - , binary_op_id_shift(il[702]) - , cmp_a_hi_shift(il[703]) - , cmp_a_lo_shift(il[704]) - , cmp_b_hi_shift(il[705]) - , cmp_b_lo_shift(il[706]) - , cmp_cmp_rng_ctr_shift(il[707]) - , cmp_op_gt_shift(il[708]) - , cmp_p_sub_a_hi_shift(il[709]) - , cmp_p_sub_a_lo_shift(il[710]) - , cmp_p_sub_b_hi_shift(il[711]) - , cmp_p_sub_b_lo_shift(il[712]) - , cmp_sel_rng_chk_shift(il[713]) - , main_da_gas_remaining_shift(il[714]) - , main_emit_l2_to_l1_msg_write_offset_shift(il[715]) - , main_emit_note_hash_write_offset_shift(il[716]) - , main_emit_nullifier_write_offset_shift(il[717]) - , main_emit_unencrypted_log_write_offset_shift(il[718]) - , main_internal_return_ptr_shift(il[719]) - , main_l1_to_l2_msg_exists_write_offset_shift(il[720]) - , main_l2_gas_remaining_shift(il[721]) - , main_note_hash_exist_write_offset_shift(il[722]) - , main_nullifier_exists_write_offset_shift(il[723]) - , main_nullifier_non_exists_write_offset_shift(il[724]) - , main_pc_shift(il[725]) - , main_sel_execution_row_shift(il[726]) - , main_sload_write_offset_shift(il[727]) - , main_sstore_write_offset_shift(il[728]) - , mem_glob_addr_shift(il[729]) - , mem_rw_shift(il[730]) - , mem_sel_mem_shift(il[731]) - , mem_tag_shift(il[732]) - , mem_tsp_shift(il[733]) - , mem_val_shift(il[734]) - , slice_addr_shift(il[735]) - , slice_clk_shift(il[736]) - , slice_cnt_shift(il[737]) - , slice_col_offset_shift(il[738]) - , slice_sel_cd_cpy_shift(il[739]) - , slice_sel_mem_active_shift(il[740]) - , slice_sel_return_shift(il[741]) - , slice_sel_start_shift(il[742]) - , slice_space_id_shift(il[743]) + , main_sel_op_is_static_call(il[204]) + , main_sel_op_jump(il[205]) + , main_sel_op_jumpi(il[206]) + , main_sel_op_keccak(il[207]) + , main_sel_op_l1_to_l2_msg_exists(il[208]) + , main_sel_op_l2gasleft(il[209]) + , main_sel_op_lt(il[210]) + , main_sel_op_lte(il[211]) + , main_sel_op_mov(il[212]) + , main_sel_op_msm(il[213]) + , main_sel_op_mul(il[214]) + , main_sel_op_not(il[215]) + , main_sel_op_note_hash_exists(il[216]) + , main_sel_op_nullifier_exists(il[217]) + , main_sel_op_or(il[218]) + , main_sel_op_pedersen(il[219]) + , main_sel_op_pedersen_commit(il[220]) + , main_sel_op_poseidon2(il[221]) + , main_sel_op_radix_le(il[222]) + , main_sel_op_sender(il[223]) + , main_sel_op_set(il[224]) + , main_sel_op_sha256(il[225]) + , main_sel_op_shl(il[226]) + , main_sel_op_shr(il[227]) + , main_sel_op_sload(il[228]) + , main_sel_op_sstore(il[229]) + , main_sel_op_static_call(il[230]) + , main_sel_op_storage_address(il[231]) + , main_sel_op_sub(il[232]) + , main_sel_op_timestamp(il[233]) + , main_sel_op_transaction_fee(il[234]) + , main_sel_op_version(il[235]) + , main_sel_op_xor(il[236]) + , main_sel_q_kernel_lookup(il[237]) + , main_sel_q_kernel_output_lookup(il[238]) + , main_sel_resolve_ind_addr_a(il[239]) + , main_sel_resolve_ind_addr_b(il[240]) + , main_sel_resolve_ind_addr_c(il[241]) + , main_sel_resolve_ind_addr_d(il[242]) + , main_sel_returndata(il[243]) + , main_sel_rng_16(il[244]) + , main_sel_rng_8(il[245]) + , main_sel_slice_gadget(il[246]) + , main_side_effect_counter(il[247]) + , main_sload_write_offset(il[248]) + , main_space_id(il[249]) + , main_sstore_write_offset(il[250]) + , main_tag_err(il[251]) + , main_w_in_tag(il[252]) + , mem_addr(il[253]) + , mem_clk(il[254]) + , mem_diff(il[255]) + , mem_glob_addr(il[256]) + , mem_last(il[257]) + , mem_lastAccess(il[258]) + , mem_one_min_inv(il[259]) + , mem_r_in_tag(il[260]) + , mem_rw(il[261]) + , mem_sel_mem(il[262]) + , mem_sel_mov_ia_to_ic(il[263]) + , mem_sel_mov_ib_to_ic(il[264]) + , mem_sel_op_a(il[265]) + , mem_sel_op_b(il[266]) + , mem_sel_op_c(il[267]) + , mem_sel_op_cmov(il[268]) + , mem_sel_op_d(il[269]) + , mem_sel_op_poseidon_read_a(il[270]) + , mem_sel_op_poseidon_read_b(il[271]) + , mem_sel_op_poseidon_read_c(il[272]) + , mem_sel_op_poseidon_read_d(il[273]) + , mem_sel_op_poseidon_write_a(il[274]) + , mem_sel_op_poseidon_write_b(il[275]) + , mem_sel_op_poseidon_write_c(il[276]) + , mem_sel_op_poseidon_write_d(il[277]) + , mem_sel_op_slice(il[278]) + , mem_sel_resolve_ind_addr_a(il[279]) + , mem_sel_resolve_ind_addr_b(il[280]) + , mem_sel_resolve_ind_addr_c(il[281]) + , mem_sel_resolve_ind_addr_d(il[282]) + , mem_sel_rng_chk(il[283]) + , mem_skip_check_tag(il[284]) + , mem_space_id(il[285]) + , mem_tag(il[286]) + , mem_tag_err(il[287]) + , mem_tsp(il[288]) + , mem_val(il[289]) + , mem_w_in_tag(il[290]) + , pedersen_clk(il[291]) + , pedersen_input(il[292]) + , pedersen_output(il[293]) + , pedersen_sel_pedersen(il[294]) + , poseidon2_B_10_0(il[295]) + , poseidon2_B_10_1(il[296]) + , poseidon2_B_10_2(il[297]) + , poseidon2_B_10_3(il[298]) + , poseidon2_B_11_0(il[299]) + , poseidon2_B_11_1(il[300]) + , poseidon2_B_11_2(il[301]) + , poseidon2_B_11_3(il[302]) + , poseidon2_B_12_0(il[303]) + , poseidon2_B_12_1(il[304]) + , poseidon2_B_12_2(il[305]) + , poseidon2_B_12_3(il[306]) + , poseidon2_B_13_0(il[307]) + , poseidon2_B_13_1(il[308]) + , poseidon2_B_13_2(il[309]) + , poseidon2_B_13_3(il[310]) + , poseidon2_B_14_0(il[311]) + , poseidon2_B_14_1(il[312]) + , poseidon2_B_14_2(il[313]) + , poseidon2_B_14_3(il[314]) + , poseidon2_B_15_0(il[315]) + , poseidon2_B_15_1(il[316]) + , poseidon2_B_15_2(il[317]) + , poseidon2_B_15_3(il[318]) + , poseidon2_B_16_0(il[319]) + , poseidon2_B_16_1(il[320]) + , poseidon2_B_16_2(il[321]) + , poseidon2_B_16_3(il[322]) + , poseidon2_B_17_0(il[323]) + , poseidon2_B_17_1(il[324]) + , poseidon2_B_17_2(il[325]) + , poseidon2_B_17_3(il[326]) + , poseidon2_B_18_0(il[327]) + , poseidon2_B_18_1(il[328]) + , poseidon2_B_18_2(il[329]) + , poseidon2_B_18_3(il[330]) + , poseidon2_B_19_0(il[331]) + , poseidon2_B_19_1(il[332]) + , poseidon2_B_19_2(il[333]) + , poseidon2_B_19_3(il[334]) + , poseidon2_B_20_0(il[335]) + , poseidon2_B_20_1(il[336]) + , poseidon2_B_20_2(il[337]) + , poseidon2_B_20_3(il[338]) + , poseidon2_B_21_0(il[339]) + , poseidon2_B_21_1(il[340]) + , poseidon2_B_21_2(il[341]) + , poseidon2_B_21_3(il[342]) + , poseidon2_B_22_0(il[343]) + , poseidon2_B_22_1(il[344]) + , poseidon2_B_22_2(il[345]) + , poseidon2_B_22_3(il[346]) + , poseidon2_B_23_0(il[347]) + , poseidon2_B_23_1(il[348]) + , poseidon2_B_23_2(il[349]) + , poseidon2_B_23_3(il[350]) + , poseidon2_B_24_0(il[351]) + , poseidon2_B_24_1(il[352]) + , poseidon2_B_24_2(il[353]) + , poseidon2_B_24_3(il[354]) + , poseidon2_B_25_0(il[355]) + , poseidon2_B_25_1(il[356]) + , poseidon2_B_25_2(il[357]) + , poseidon2_B_25_3(il[358]) + , poseidon2_B_26_0(il[359]) + , poseidon2_B_26_1(il[360]) + , poseidon2_B_26_2(il[361]) + , poseidon2_B_26_3(il[362]) + , poseidon2_B_27_0(il[363]) + , poseidon2_B_27_1(il[364]) + , poseidon2_B_27_2(il[365]) + , poseidon2_B_27_3(il[366]) + , poseidon2_B_28_0(il[367]) + , poseidon2_B_28_1(il[368]) + , poseidon2_B_28_2(il[369]) + , poseidon2_B_28_3(il[370]) + , poseidon2_B_29_0(il[371]) + , poseidon2_B_29_1(il[372]) + , poseidon2_B_29_2(il[373]) + , poseidon2_B_29_3(il[374]) + , poseidon2_B_30_0(il[375]) + , poseidon2_B_30_1(il[376]) + , poseidon2_B_30_2(il[377]) + , poseidon2_B_30_3(il[378]) + , poseidon2_B_31_0(il[379]) + , poseidon2_B_31_1(il[380]) + , poseidon2_B_31_2(il[381]) + , poseidon2_B_31_3(il[382]) + , poseidon2_B_32_0(il[383]) + , poseidon2_B_32_1(il[384]) + , poseidon2_B_32_2(il[385]) + , poseidon2_B_32_3(il[386]) + , poseidon2_B_33_0(il[387]) + , poseidon2_B_33_1(il[388]) + , poseidon2_B_33_2(il[389]) + , poseidon2_B_33_3(il[390]) + , poseidon2_B_34_0(il[391]) + , poseidon2_B_34_1(il[392]) + , poseidon2_B_34_2(il[393]) + , poseidon2_B_34_3(il[394]) + , poseidon2_B_35_0(il[395]) + , poseidon2_B_35_1(il[396]) + , poseidon2_B_35_2(il[397]) + , poseidon2_B_35_3(il[398]) + , poseidon2_B_36_0(il[399]) + , poseidon2_B_36_1(il[400]) + , poseidon2_B_36_2(il[401]) + , poseidon2_B_36_3(il[402]) + , poseidon2_B_37_0(il[403]) + , poseidon2_B_37_1(il[404]) + , poseidon2_B_37_2(il[405]) + , poseidon2_B_37_3(il[406]) + , poseidon2_B_38_0(il[407]) + , poseidon2_B_38_1(il[408]) + , poseidon2_B_38_2(il[409]) + , poseidon2_B_38_3(il[410]) + , poseidon2_B_39_0(il[411]) + , poseidon2_B_39_1(il[412]) + , poseidon2_B_39_2(il[413]) + , poseidon2_B_39_3(il[414]) + , poseidon2_B_40_0(il[415]) + , poseidon2_B_40_1(il[416]) + , poseidon2_B_40_2(il[417]) + , poseidon2_B_40_3(il[418]) + , poseidon2_B_41_0(il[419]) + , poseidon2_B_41_1(il[420]) + , poseidon2_B_41_2(il[421]) + , poseidon2_B_41_3(il[422]) + , poseidon2_B_42_0(il[423]) + , poseidon2_B_42_1(il[424]) + , poseidon2_B_42_2(il[425]) + , poseidon2_B_42_3(il[426]) + , poseidon2_B_43_0(il[427]) + , poseidon2_B_43_1(il[428]) + , poseidon2_B_43_2(il[429]) + , poseidon2_B_43_3(il[430]) + , poseidon2_B_44_0(il[431]) + , poseidon2_B_44_1(il[432]) + , poseidon2_B_44_2(il[433]) + , poseidon2_B_44_3(il[434]) + , poseidon2_B_45_0(il[435]) + , poseidon2_B_45_1(il[436]) + , poseidon2_B_45_2(il[437]) + , poseidon2_B_45_3(il[438]) + , poseidon2_B_46_0(il[439]) + , poseidon2_B_46_1(il[440]) + , poseidon2_B_46_2(il[441]) + , poseidon2_B_46_3(il[442]) + , poseidon2_B_47_0(il[443]) + , poseidon2_B_47_1(il[444]) + , poseidon2_B_47_2(il[445]) + , poseidon2_B_47_3(il[446]) + , poseidon2_B_48_0(il[447]) + , poseidon2_B_48_1(il[448]) + , poseidon2_B_48_2(il[449]) + , poseidon2_B_48_3(il[450]) + , poseidon2_B_49_0(il[451]) + , poseidon2_B_49_1(il[452]) + , poseidon2_B_49_2(il[453]) + , poseidon2_B_49_3(il[454]) + , poseidon2_B_4_0(il[455]) + , poseidon2_B_4_1(il[456]) + , poseidon2_B_4_2(il[457]) + , poseidon2_B_4_3(il[458]) + , poseidon2_B_50_0(il[459]) + , poseidon2_B_50_1(il[460]) + , poseidon2_B_50_2(il[461]) + , poseidon2_B_50_3(il[462]) + , poseidon2_B_51_0(il[463]) + , poseidon2_B_51_1(il[464]) + , poseidon2_B_51_2(il[465]) + , poseidon2_B_51_3(il[466]) + , poseidon2_B_52_0(il[467]) + , poseidon2_B_52_1(il[468]) + , poseidon2_B_52_2(il[469]) + , poseidon2_B_52_3(il[470]) + , poseidon2_B_53_0(il[471]) + , poseidon2_B_53_1(il[472]) + , poseidon2_B_53_2(il[473]) + , poseidon2_B_53_3(il[474]) + , poseidon2_B_54_0(il[475]) + , poseidon2_B_54_1(il[476]) + , poseidon2_B_54_2(il[477]) + , poseidon2_B_54_3(il[478]) + , poseidon2_B_55_0(il[479]) + , poseidon2_B_55_1(il[480]) + , poseidon2_B_55_2(il[481]) + , poseidon2_B_55_3(il[482]) + , poseidon2_B_56_0(il[483]) + , poseidon2_B_56_1(il[484]) + , poseidon2_B_56_2(il[485]) + , poseidon2_B_56_3(il[486]) + , poseidon2_B_57_0(il[487]) + , poseidon2_B_57_1(il[488]) + , poseidon2_B_57_2(il[489]) + , poseidon2_B_57_3(il[490]) + , poseidon2_B_58_0(il[491]) + , poseidon2_B_58_1(il[492]) + , poseidon2_B_58_2(il[493]) + , poseidon2_B_58_3(il[494]) + , poseidon2_B_59_0(il[495]) + , poseidon2_B_59_1(il[496]) + , poseidon2_B_59_2(il[497]) + , poseidon2_B_59_3(il[498]) + , poseidon2_B_5_0(il[499]) + , poseidon2_B_5_1(il[500]) + , poseidon2_B_5_2(il[501]) + , poseidon2_B_5_3(il[502]) + , poseidon2_B_6_0(il[503]) + , poseidon2_B_6_1(il[504]) + , poseidon2_B_6_2(il[505]) + , poseidon2_B_6_3(il[506]) + , poseidon2_B_7_0(il[507]) + , poseidon2_B_7_1(il[508]) + , poseidon2_B_7_2(il[509]) + , poseidon2_B_7_3(il[510]) + , poseidon2_B_8_0(il[511]) + , poseidon2_B_8_1(il[512]) + , poseidon2_B_8_2(il[513]) + , poseidon2_B_8_3(il[514]) + , poseidon2_B_9_0(il[515]) + , poseidon2_B_9_1(il[516]) + , poseidon2_B_9_2(il[517]) + , poseidon2_B_9_3(il[518]) + , poseidon2_EXT_LAYER_4(il[519]) + , poseidon2_EXT_LAYER_5(il[520]) + , poseidon2_EXT_LAYER_6(il[521]) + , poseidon2_EXT_LAYER_7(il[522]) + , poseidon2_T_0_4(il[523]) + , poseidon2_T_0_5(il[524]) + , poseidon2_T_0_6(il[525]) + , poseidon2_T_0_7(il[526]) + , poseidon2_T_1_4(il[527]) + , poseidon2_T_1_5(il[528]) + , poseidon2_T_1_6(il[529]) + , poseidon2_T_1_7(il[530]) + , poseidon2_T_2_4(il[531]) + , poseidon2_T_2_5(il[532]) + , poseidon2_T_2_6(il[533]) + , poseidon2_T_2_7(il[534]) + , poseidon2_T_3_4(il[535]) + , poseidon2_T_3_5(il[536]) + , poseidon2_T_3_6(il[537]) + , poseidon2_T_3_7(il[538]) + , poseidon2_T_60_4(il[539]) + , poseidon2_T_60_5(il[540]) + , poseidon2_T_60_6(il[541]) + , poseidon2_T_60_7(il[542]) + , poseidon2_T_61_4(il[543]) + , poseidon2_T_61_5(il[544]) + , poseidon2_T_61_6(il[545]) + , poseidon2_T_61_7(il[546]) + , poseidon2_T_62_4(il[547]) + , poseidon2_T_62_5(il[548]) + , poseidon2_T_62_6(il[549]) + , poseidon2_T_62_7(il[550]) + , poseidon2_T_63_4(il[551]) + , poseidon2_T_63_5(il[552]) + , poseidon2_T_63_6(il[553]) + , poseidon2_T_63_7(il[554]) + , poseidon2_a_0(il[555]) + , poseidon2_a_1(il[556]) + , poseidon2_a_2(il[557]) + , poseidon2_a_3(il[558]) + , poseidon2_b_0(il[559]) + , poseidon2_b_1(il[560]) + , poseidon2_b_2(il[561]) + , poseidon2_b_3(il[562]) + , poseidon2_clk(il[563]) + , poseidon2_input_addr(il[564]) + , poseidon2_mem_addr_read_a(il[565]) + , poseidon2_mem_addr_read_b(il[566]) + , poseidon2_mem_addr_read_c(il[567]) + , poseidon2_mem_addr_read_d(il[568]) + , poseidon2_mem_addr_write_a(il[569]) + , poseidon2_mem_addr_write_b(il[570]) + , poseidon2_mem_addr_write_c(il[571]) + , poseidon2_mem_addr_write_d(il[572]) + , poseidon2_output_addr(il[573]) + , poseidon2_sel_poseidon_perm(il[574]) + , range_check_alu_rng_chk(il[575]) + , range_check_clk(il[576]) + , range_check_cmp_hi_bits_rng_chk(il[577]) + , range_check_cmp_lo_bits_rng_chk(il[578]) + , range_check_dyn_diff(il[579]) + , range_check_dyn_rng_chk_bits(il[580]) + , range_check_dyn_rng_chk_pow_2(il[581]) + , range_check_gas_da_rng_chk(il[582]) + , range_check_gas_l2_rng_chk(il[583]) + , range_check_is_lte_u112(il[584]) + , range_check_is_lte_u128(il[585]) + , range_check_is_lte_u16(il[586]) + , range_check_is_lte_u32(il[587]) + , range_check_is_lte_u48(il[588]) + , range_check_is_lte_u64(il[589]) + , range_check_is_lte_u80(il[590]) + , range_check_is_lte_u96(il[591]) + , range_check_mem_rng_chk(il[592]) + , range_check_rng_chk_bits(il[593]) + , range_check_sel_lookup_0(il[594]) + , range_check_sel_lookup_1(il[595]) + , range_check_sel_lookup_2(il[596]) + , range_check_sel_lookup_3(il[597]) + , range_check_sel_lookup_4(il[598]) + , range_check_sel_lookup_5(il[599]) + , range_check_sel_lookup_6(il[600]) + , range_check_sel_rng_chk(il[601]) + , range_check_u16_r0(il[602]) + , range_check_u16_r1(il[603]) + , range_check_u16_r2(il[604]) + , range_check_u16_r3(il[605]) + , range_check_u16_r4(il[606]) + , range_check_u16_r5(il[607]) + , range_check_u16_r6(il[608]) + , range_check_u16_r7(il[609]) + , range_check_value(il[610]) + , sha256_clk(il[611]) + , sha256_input(il[612]) + , sha256_output(il[613]) + , sha256_sel_sha256_compression(il[614]) + , sha256_state(il[615]) + , slice_addr(il[616]) + , slice_clk(il[617]) + , slice_cnt(il[618]) + , slice_col_offset(il[619]) + , slice_one_min_inv(il[620]) + , slice_sel_cd_cpy(il[621]) + , slice_sel_mem_active(il[622]) + , slice_sel_return(il[623]) + , slice_sel_start(il[624]) + , slice_space_id(il[625]) + , slice_val(il[626]) + , lookup_rng_chk_pow_2_counts(il[627]) + , lookup_rng_chk_diff_counts(il[628]) + , lookup_rng_chk_0_counts(il[629]) + , lookup_rng_chk_1_counts(il[630]) + , lookup_rng_chk_2_counts(il[631]) + , lookup_rng_chk_3_counts(il[632]) + , lookup_rng_chk_4_counts(il[633]) + , lookup_rng_chk_5_counts(il[634]) + , lookup_rng_chk_6_counts(il[635]) + , lookup_rng_chk_7_counts(il[636]) + , lookup_pow_2_0_counts(il[637]) + , lookup_pow_2_1_counts(il[638]) + , lookup_byte_lengths_counts(il[639]) + , lookup_byte_operations_counts(il[640]) + , lookup_opcode_gas_counts(il[641]) + , kernel_output_lookup_counts(il[642]) + , lookup_into_kernel_counts(il[643]) + , lookup_cd_value_counts(il[644]) + , lookup_ret_value_counts(il[645]) + , incl_main_tag_err_counts(il[646]) + , incl_mem_tag_err_counts(il[647]) + , perm_rng_mem_inv(il[648]) + , perm_rng_cmp_lo_inv(il[649]) + , perm_rng_cmp_hi_inv(il[650]) + , perm_rng_alu_inv(il[651]) + , perm_cmp_alu_inv(il[652]) + , perm_rng_gas_l2_inv(il[653]) + , perm_rng_gas_da_inv(il[654]) + , perm_pos_mem_read_a_inv(il[655]) + , perm_pos_mem_read_b_inv(il[656]) + , perm_pos_mem_read_c_inv(il[657]) + , perm_pos_mem_read_d_inv(il[658]) + , perm_pos_mem_write_a_inv(il[659]) + , perm_pos_mem_write_b_inv(il[660]) + , perm_pos_mem_write_c_inv(il[661]) + , perm_pos_mem_write_d_inv(il[662]) + , perm_slice_mem_inv(il[663]) + , perm_main_alu_inv(il[664]) + , perm_main_bin_inv(il[665]) + , perm_main_conv_inv(il[666]) + , perm_main_pos2_perm_inv(il[667]) + , perm_main_pedersen_inv(il[668]) + , perm_main_slice_inv(il[669]) + , perm_main_mem_a_inv(il[670]) + , perm_main_mem_b_inv(il[671]) + , perm_main_mem_c_inv(il[672]) + , perm_main_mem_d_inv(il[673]) + , perm_main_mem_ind_addr_a_inv(il[674]) + , perm_main_mem_ind_addr_b_inv(il[675]) + , perm_main_mem_ind_addr_c_inv(il[676]) + , perm_main_mem_ind_addr_d_inv(il[677]) + , lookup_rng_chk_pow_2_inv(il[678]) + , lookup_rng_chk_diff_inv(il[679]) + , lookup_rng_chk_0_inv(il[680]) + , lookup_rng_chk_1_inv(il[681]) + , lookup_rng_chk_2_inv(il[682]) + , lookup_rng_chk_3_inv(il[683]) + , lookup_rng_chk_4_inv(il[684]) + , lookup_rng_chk_5_inv(il[685]) + , lookup_rng_chk_6_inv(il[686]) + , lookup_rng_chk_7_inv(il[687]) + , lookup_pow_2_0_inv(il[688]) + , lookup_pow_2_1_inv(il[689]) + , lookup_byte_lengths_inv(il[690]) + , lookup_byte_operations_inv(il[691]) + , lookup_opcode_gas_inv(il[692]) + , kernel_output_lookup_inv(il[693]) + , lookup_into_kernel_inv(il[694]) + , lookup_cd_value_inv(il[695]) + , lookup_ret_value_inv(il[696]) + , incl_main_tag_err_inv(il[697]) + , incl_mem_tag_err_inv(il[698]) + , binary_acc_ia_shift(il[699]) + , binary_acc_ib_shift(il[700]) + , binary_acc_ic_shift(il[701]) + , binary_mem_tag_ctr_shift(il[702]) + , binary_op_id_shift(il[703]) + , cmp_a_hi_shift(il[704]) + , cmp_a_lo_shift(il[705]) + , cmp_b_hi_shift(il[706]) + , cmp_b_lo_shift(il[707]) + , cmp_cmp_rng_ctr_shift(il[708]) + , cmp_op_gt_shift(il[709]) + , cmp_p_sub_a_hi_shift(il[710]) + , cmp_p_sub_a_lo_shift(il[711]) + , cmp_p_sub_b_hi_shift(il[712]) + , cmp_p_sub_b_lo_shift(il[713]) + , cmp_sel_rng_chk_shift(il[714]) + , main_da_gas_remaining_shift(il[715]) + , main_emit_l2_to_l1_msg_write_offset_shift(il[716]) + , main_emit_note_hash_write_offset_shift(il[717]) + , main_emit_nullifier_write_offset_shift(il[718]) + , main_emit_unencrypted_log_write_offset_shift(il[719]) + , main_internal_return_ptr_shift(il[720]) + , main_l1_to_l2_msg_exists_write_offset_shift(il[721]) + , main_l2_gas_remaining_shift(il[722]) + , main_note_hash_exist_write_offset_shift(il[723]) + , main_nullifier_exists_write_offset_shift(il[724]) + , main_nullifier_non_exists_write_offset_shift(il[725]) + , main_pc_shift(il[726]) + , main_sel_execution_row_shift(il[727]) + , main_sload_write_offset_shift(il[728]) + , main_sstore_write_offset_shift(il[729]) + , mem_glob_addr_shift(il[730]) + , mem_rw_shift(il[731]) + , mem_sel_mem_shift(il[732]) + , mem_tag_shift(il[733]) + , mem_tsp_shift(il[734]) + , mem_val_shift(il[735]) + , slice_addr_shift(il[736]) + , slice_clk_shift(il[737]) + , slice_cnt_shift(il[738]) + , slice_col_offset_shift(il[739]) + , slice_sel_cd_cpy_shift(il[740]) + , slice_sel_mem_active_shift(il[741]) + , slice_sel_return_shift(il[742]) + , slice_sel_start_shift(il[743]) + , slice_space_id_shift(il[744]) {} AvmFlavor::ProverPolynomials::ProverPolynomials(ProvingKey& proving_key) @@ -969,6 +970,7 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id main_sel_op_get_contract_instance[row_idx], main_sel_op_internal_call[row_idx], main_sel_op_internal_return[row_idx], + main_sel_op_is_static_call[row_idx], main_sel_op_jump[row_idx], main_sel_op_jumpi[row_idx], main_sel_op_keccak[row_idx], @@ -1717,6 +1719,7 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::main_sel_op_get_contract_instance = "MAIN_SEL_OP_GET_CONTRACT_INSTANCE"; Base::main_sel_op_internal_call = "MAIN_SEL_OP_INTERNAL_CALL"; Base::main_sel_op_internal_return = "MAIN_SEL_OP_INTERNAL_RETURN"; + Base::main_sel_op_is_static_call = "MAIN_SEL_OP_IS_STATIC_CALL"; Base::main_sel_op_jump = "MAIN_SEL_OP_JUMP"; Base::main_sel_op_jumpi = "MAIN_SEL_OP_JUMPI"; Base::main_sel_op_keccak = "MAIN_SEL_OP_KECCAK"; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp index fef4f1ccb89..ca6708e976f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp @@ -90,7 +90,7 @@ template using tuple_cat_t = decltype(std::tuple_cat(std:: // The entities that will be used in the flavor. // clang-format off #define PRECOMPUTED_ENTITIES byte_lookup_sel_bin, byte_lookup_table_byte_lengths, byte_lookup_table_in_tags, byte_lookup_table_input_a, byte_lookup_table_input_b, byte_lookup_table_op_id, byte_lookup_table_output, gas_base_da_gas_fixed_table, gas_base_l2_gas_fixed_table, gas_dyn_da_gas_fixed_table, gas_dyn_l2_gas_fixed_table, gas_sel_gas_cost, main_clk, main_sel_first, main_zeroes, powers_power_of_2 -#define WIRE_ENTITIES main_kernel_inputs, main_kernel_value_out, main_kernel_side_effect_out, main_kernel_metadata_out, main_calldata, main_returndata, alu_a_hi, alu_a_lo, alu_b_hi, alu_b_lo, alu_b_pow, alu_c_hi, alu_c_lo, alu_cf, alu_clk, alu_cmp_gadget_gt, alu_cmp_gadget_input_a, alu_cmp_gadget_input_b, alu_cmp_gadget_result, alu_cmp_gadget_sel, alu_ff_tag, alu_ia, alu_ib, alu_ic, alu_in_tag, alu_max_bits_sub_b_bits, alu_max_bits_sub_b_pow, alu_op_add, alu_op_cast, alu_op_div, alu_op_eq, alu_op_lt, alu_op_lte, alu_op_mul, alu_op_not, alu_op_shl, alu_op_shr, alu_op_sub, alu_partial_prod_hi, alu_partial_prod_lo, alu_range_check_input_value, alu_range_check_num_bits, alu_range_check_sel, alu_remainder, alu_sel_alu, alu_sel_cmp, alu_sel_shift_which, alu_u128_tag, alu_u16_tag, alu_u1_tag, alu_u32_tag, alu_u64_tag, alu_u8_tag, alu_zero_shift, binary_acc_ia, binary_acc_ib, binary_acc_ic, binary_clk, binary_ia_bytes, binary_ib_bytes, binary_ic_bytes, binary_in_tag, binary_mem_tag_ctr, binary_mem_tag_ctr_inv, binary_op_id, binary_sel_bin, binary_start, cmp_a_hi, cmp_a_lo, cmp_b_hi, cmp_b_lo, cmp_borrow, cmp_clk, cmp_cmp_rng_ctr, cmp_input_a, cmp_input_b, cmp_op_eq, cmp_op_eq_diff_inv, cmp_op_gt, cmp_p_a_borrow, cmp_p_b_borrow, cmp_p_sub_a_hi, cmp_p_sub_a_lo, cmp_p_sub_b_hi, cmp_p_sub_b_lo, cmp_range_chk_clk, cmp_res_hi, cmp_res_lo, cmp_result, cmp_sel_cmp, cmp_sel_rng_chk, cmp_shift_sel, conversion_clk, conversion_input, conversion_num_limbs, conversion_output_bits, conversion_radix, conversion_sel_to_radix_le, keccakf1600_clk, keccakf1600_input, keccakf1600_output, keccakf1600_sel_keccakf1600, main_abs_da_rem_gas, main_abs_l2_rem_gas, main_alu_in_tag, main_base_da_gas_op_cost, main_base_l2_gas_op_cost, main_bin_op_id, main_call_ptr, main_da_gas_remaining, main_da_out_of_gas, main_dyn_da_gas_op_cost, main_dyn_gas_multiplier, main_dyn_l2_gas_op_cost, main_emit_l2_to_l1_msg_write_offset, main_emit_note_hash_write_offset, main_emit_nullifier_write_offset, main_emit_unencrypted_log_write_offset, main_ia, main_ib, main_ic, main_id, main_id_zero, main_ind_addr_a, main_ind_addr_b, main_ind_addr_c, main_ind_addr_d, main_internal_return_ptr, main_inv, main_kernel_in_offset, main_kernel_out_offset, main_l1_to_l2_msg_exists_write_offset, main_l2_gas_remaining, main_l2_out_of_gas, main_mem_addr_a, main_mem_addr_b, main_mem_addr_c, main_mem_addr_d, main_note_hash_exist_write_offset, main_nullifier_exists_write_offset, main_nullifier_non_exists_write_offset, main_op_err, main_opcode_val, main_pc, main_r_in_tag, main_rwa, main_rwb, main_rwc, main_rwd, main_sel_alu, main_sel_bin, main_sel_calldata, main_sel_execution_row, main_sel_kernel_inputs, main_sel_kernel_out, main_sel_last, main_sel_mem_op_a, main_sel_mem_op_b, main_sel_mem_op_c, main_sel_mem_op_d, main_sel_mov_ia_to_ic, main_sel_mov_ib_to_ic, main_sel_op_add, main_sel_op_address, main_sel_op_and, main_sel_op_block_number, main_sel_op_calldata_copy, main_sel_op_cast, main_sel_op_chain_id, main_sel_op_cmov, main_sel_op_dagasleft, main_sel_op_div, main_sel_op_ecadd, main_sel_op_emit_l2_to_l1_msg, main_sel_op_emit_note_hash, main_sel_op_emit_nullifier, main_sel_op_emit_unencrypted_log, main_sel_op_eq, main_sel_op_external_call, main_sel_op_external_return, main_sel_op_external_revert, main_sel_op_fdiv, main_sel_op_fee_per_da_gas, main_sel_op_fee_per_l2_gas, main_sel_op_function_selector, main_sel_op_get_contract_instance, main_sel_op_internal_call, main_sel_op_internal_return, main_sel_op_jump, main_sel_op_jumpi, main_sel_op_keccak, main_sel_op_l1_to_l2_msg_exists, main_sel_op_l2gasleft, main_sel_op_lt, main_sel_op_lte, main_sel_op_mov, main_sel_op_msm, main_sel_op_mul, main_sel_op_not, main_sel_op_note_hash_exists, main_sel_op_nullifier_exists, main_sel_op_or, main_sel_op_pedersen, main_sel_op_pedersen_commit, main_sel_op_poseidon2, main_sel_op_radix_le, main_sel_op_sender, main_sel_op_set, main_sel_op_sha256, main_sel_op_shl, main_sel_op_shr, main_sel_op_sload, main_sel_op_sstore, main_sel_op_static_call, main_sel_op_storage_address, main_sel_op_sub, main_sel_op_timestamp, main_sel_op_transaction_fee, main_sel_op_version, main_sel_op_xor, main_sel_q_kernel_lookup, main_sel_q_kernel_output_lookup, main_sel_resolve_ind_addr_a, main_sel_resolve_ind_addr_b, main_sel_resolve_ind_addr_c, main_sel_resolve_ind_addr_d, main_sel_returndata, main_sel_rng_16, main_sel_rng_8, main_sel_slice_gadget, main_side_effect_counter, main_sload_write_offset, main_space_id, main_sstore_write_offset, main_tag_err, main_w_in_tag, mem_addr, mem_clk, mem_diff, mem_glob_addr, mem_last, mem_lastAccess, mem_one_min_inv, mem_r_in_tag, mem_rw, mem_sel_mem, mem_sel_mov_ia_to_ic, mem_sel_mov_ib_to_ic, mem_sel_op_a, mem_sel_op_b, mem_sel_op_c, mem_sel_op_cmov, mem_sel_op_d, mem_sel_op_poseidon_read_a, mem_sel_op_poseidon_read_b, mem_sel_op_poseidon_read_c, mem_sel_op_poseidon_read_d, mem_sel_op_poseidon_write_a, mem_sel_op_poseidon_write_b, mem_sel_op_poseidon_write_c, mem_sel_op_poseidon_write_d, mem_sel_op_slice, mem_sel_resolve_ind_addr_a, mem_sel_resolve_ind_addr_b, mem_sel_resolve_ind_addr_c, mem_sel_resolve_ind_addr_d, mem_sel_rng_chk, mem_skip_check_tag, mem_space_id, mem_tag, mem_tag_err, mem_tsp, mem_val, mem_w_in_tag, pedersen_clk, pedersen_input, pedersen_output, pedersen_sel_pedersen, poseidon2_B_10_0, poseidon2_B_10_1, poseidon2_B_10_2, poseidon2_B_10_3, poseidon2_B_11_0, poseidon2_B_11_1, poseidon2_B_11_2, poseidon2_B_11_3, poseidon2_B_12_0, poseidon2_B_12_1, poseidon2_B_12_2, poseidon2_B_12_3, poseidon2_B_13_0, poseidon2_B_13_1, poseidon2_B_13_2, poseidon2_B_13_3, poseidon2_B_14_0, poseidon2_B_14_1, poseidon2_B_14_2, poseidon2_B_14_3, poseidon2_B_15_0, poseidon2_B_15_1, poseidon2_B_15_2, poseidon2_B_15_3, poseidon2_B_16_0, poseidon2_B_16_1, poseidon2_B_16_2, poseidon2_B_16_3, poseidon2_B_17_0, poseidon2_B_17_1, poseidon2_B_17_2, poseidon2_B_17_3, poseidon2_B_18_0, poseidon2_B_18_1, poseidon2_B_18_2, poseidon2_B_18_3, poseidon2_B_19_0, poseidon2_B_19_1, poseidon2_B_19_2, poseidon2_B_19_3, poseidon2_B_20_0, poseidon2_B_20_1, poseidon2_B_20_2, poseidon2_B_20_3, poseidon2_B_21_0, poseidon2_B_21_1, poseidon2_B_21_2, poseidon2_B_21_3, poseidon2_B_22_0, poseidon2_B_22_1, poseidon2_B_22_2, poseidon2_B_22_3, poseidon2_B_23_0, poseidon2_B_23_1, poseidon2_B_23_2, poseidon2_B_23_3, poseidon2_B_24_0, poseidon2_B_24_1, poseidon2_B_24_2, poseidon2_B_24_3, poseidon2_B_25_0, poseidon2_B_25_1, poseidon2_B_25_2, poseidon2_B_25_3, poseidon2_B_26_0, poseidon2_B_26_1, poseidon2_B_26_2, poseidon2_B_26_3, poseidon2_B_27_0, poseidon2_B_27_1, poseidon2_B_27_2, poseidon2_B_27_3, poseidon2_B_28_0, poseidon2_B_28_1, poseidon2_B_28_2, poseidon2_B_28_3, poseidon2_B_29_0, poseidon2_B_29_1, poseidon2_B_29_2, poseidon2_B_29_3, poseidon2_B_30_0, poseidon2_B_30_1, poseidon2_B_30_2, poseidon2_B_30_3, poseidon2_B_31_0, poseidon2_B_31_1, poseidon2_B_31_2, poseidon2_B_31_3, poseidon2_B_32_0, poseidon2_B_32_1, poseidon2_B_32_2, poseidon2_B_32_3, poseidon2_B_33_0, poseidon2_B_33_1, poseidon2_B_33_2, poseidon2_B_33_3, poseidon2_B_34_0, poseidon2_B_34_1, poseidon2_B_34_2, poseidon2_B_34_3, poseidon2_B_35_0, poseidon2_B_35_1, poseidon2_B_35_2, poseidon2_B_35_3, poseidon2_B_36_0, poseidon2_B_36_1, poseidon2_B_36_2, poseidon2_B_36_3, poseidon2_B_37_0, poseidon2_B_37_1, poseidon2_B_37_2, poseidon2_B_37_3, poseidon2_B_38_0, poseidon2_B_38_1, poseidon2_B_38_2, poseidon2_B_38_3, poseidon2_B_39_0, poseidon2_B_39_1, poseidon2_B_39_2, poseidon2_B_39_3, poseidon2_B_40_0, poseidon2_B_40_1, poseidon2_B_40_2, poseidon2_B_40_3, poseidon2_B_41_0, poseidon2_B_41_1, poseidon2_B_41_2, poseidon2_B_41_3, poseidon2_B_42_0, poseidon2_B_42_1, poseidon2_B_42_2, poseidon2_B_42_3, poseidon2_B_43_0, poseidon2_B_43_1, poseidon2_B_43_2, poseidon2_B_43_3, poseidon2_B_44_0, poseidon2_B_44_1, poseidon2_B_44_2, poseidon2_B_44_3, poseidon2_B_45_0, poseidon2_B_45_1, poseidon2_B_45_2, poseidon2_B_45_3, poseidon2_B_46_0, poseidon2_B_46_1, poseidon2_B_46_2, poseidon2_B_46_3, poseidon2_B_47_0, poseidon2_B_47_1, poseidon2_B_47_2, poseidon2_B_47_3, poseidon2_B_48_0, poseidon2_B_48_1, poseidon2_B_48_2, poseidon2_B_48_3, poseidon2_B_49_0, poseidon2_B_49_1, poseidon2_B_49_2, poseidon2_B_49_3, poseidon2_B_4_0, poseidon2_B_4_1, poseidon2_B_4_2, poseidon2_B_4_3, poseidon2_B_50_0, poseidon2_B_50_1, poseidon2_B_50_2, poseidon2_B_50_3, poseidon2_B_51_0, poseidon2_B_51_1, poseidon2_B_51_2, poseidon2_B_51_3, poseidon2_B_52_0, poseidon2_B_52_1, poseidon2_B_52_2, poseidon2_B_52_3, poseidon2_B_53_0, poseidon2_B_53_1, poseidon2_B_53_2, poseidon2_B_53_3, poseidon2_B_54_0, poseidon2_B_54_1, poseidon2_B_54_2, poseidon2_B_54_3, poseidon2_B_55_0, poseidon2_B_55_1, poseidon2_B_55_2, poseidon2_B_55_3, poseidon2_B_56_0, poseidon2_B_56_1, poseidon2_B_56_2, poseidon2_B_56_3, poseidon2_B_57_0, poseidon2_B_57_1, poseidon2_B_57_2, poseidon2_B_57_3, poseidon2_B_58_0, poseidon2_B_58_1, poseidon2_B_58_2, poseidon2_B_58_3, poseidon2_B_59_0, poseidon2_B_59_1, poseidon2_B_59_2, poseidon2_B_59_3, poseidon2_B_5_0, poseidon2_B_5_1, poseidon2_B_5_2, poseidon2_B_5_3, poseidon2_B_6_0, poseidon2_B_6_1, poseidon2_B_6_2, poseidon2_B_6_3, poseidon2_B_7_0, poseidon2_B_7_1, poseidon2_B_7_2, poseidon2_B_7_3, poseidon2_B_8_0, poseidon2_B_8_1, poseidon2_B_8_2, poseidon2_B_8_3, poseidon2_B_9_0, poseidon2_B_9_1, poseidon2_B_9_2, poseidon2_B_9_3, poseidon2_EXT_LAYER_4, poseidon2_EXT_LAYER_5, poseidon2_EXT_LAYER_6, poseidon2_EXT_LAYER_7, poseidon2_T_0_4, poseidon2_T_0_5, poseidon2_T_0_6, poseidon2_T_0_7, poseidon2_T_1_4, poseidon2_T_1_5, poseidon2_T_1_6, poseidon2_T_1_7, poseidon2_T_2_4, poseidon2_T_2_5, poseidon2_T_2_6, poseidon2_T_2_7, poseidon2_T_3_4, poseidon2_T_3_5, poseidon2_T_3_6, poseidon2_T_3_7, poseidon2_T_60_4, poseidon2_T_60_5, poseidon2_T_60_6, poseidon2_T_60_7, poseidon2_T_61_4, poseidon2_T_61_5, poseidon2_T_61_6, poseidon2_T_61_7, poseidon2_T_62_4, poseidon2_T_62_5, poseidon2_T_62_6, poseidon2_T_62_7, poseidon2_T_63_4, poseidon2_T_63_5, poseidon2_T_63_6, poseidon2_T_63_7, poseidon2_a_0, poseidon2_a_1, poseidon2_a_2, poseidon2_a_3, poseidon2_b_0, poseidon2_b_1, poseidon2_b_2, poseidon2_b_3, poseidon2_clk, poseidon2_input_addr, poseidon2_mem_addr_read_a, poseidon2_mem_addr_read_b, poseidon2_mem_addr_read_c, poseidon2_mem_addr_read_d, poseidon2_mem_addr_write_a, poseidon2_mem_addr_write_b, poseidon2_mem_addr_write_c, poseidon2_mem_addr_write_d, poseidon2_output_addr, poseidon2_sel_poseidon_perm, range_check_alu_rng_chk, range_check_clk, range_check_cmp_hi_bits_rng_chk, range_check_cmp_lo_bits_rng_chk, range_check_dyn_diff, range_check_dyn_rng_chk_bits, range_check_dyn_rng_chk_pow_2, range_check_gas_da_rng_chk, range_check_gas_l2_rng_chk, range_check_is_lte_u112, range_check_is_lte_u128, range_check_is_lte_u16, range_check_is_lte_u32, range_check_is_lte_u48, range_check_is_lte_u64, range_check_is_lte_u80, range_check_is_lte_u96, range_check_mem_rng_chk, range_check_rng_chk_bits, range_check_sel_lookup_0, range_check_sel_lookup_1, range_check_sel_lookup_2, range_check_sel_lookup_3, range_check_sel_lookup_4, range_check_sel_lookup_5, range_check_sel_lookup_6, range_check_sel_rng_chk, range_check_u16_r0, range_check_u16_r1, range_check_u16_r2, range_check_u16_r3, range_check_u16_r4, range_check_u16_r5, range_check_u16_r6, range_check_u16_r7, range_check_value, sha256_clk, sha256_input, sha256_output, sha256_sel_sha256_compression, sha256_state, slice_addr, slice_clk, slice_cnt, slice_col_offset, slice_one_min_inv, slice_sel_cd_cpy, slice_sel_mem_active, slice_sel_return, slice_sel_start, slice_space_id, slice_val, lookup_rng_chk_pow_2_counts, lookup_rng_chk_diff_counts, lookup_rng_chk_0_counts, lookup_rng_chk_1_counts, lookup_rng_chk_2_counts, lookup_rng_chk_3_counts, lookup_rng_chk_4_counts, lookup_rng_chk_5_counts, lookup_rng_chk_6_counts, lookup_rng_chk_7_counts, lookup_pow_2_0_counts, lookup_pow_2_1_counts, lookup_byte_lengths_counts, lookup_byte_operations_counts, lookup_opcode_gas_counts, kernel_output_lookup_counts, lookup_into_kernel_counts, lookup_cd_value_counts, lookup_ret_value_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts +#define WIRE_ENTITIES main_kernel_inputs, main_kernel_value_out, main_kernel_side_effect_out, main_kernel_metadata_out, main_calldata, main_returndata, alu_a_hi, alu_a_lo, alu_b_hi, alu_b_lo, alu_b_pow, alu_c_hi, alu_c_lo, alu_cf, alu_clk, alu_cmp_gadget_gt, alu_cmp_gadget_input_a, alu_cmp_gadget_input_b, alu_cmp_gadget_result, alu_cmp_gadget_sel, alu_ff_tag, alu_ia, alu_ib, alu_ic, alu_in_tag, alu_max_bits_sub_b_bits, alu_max_bits_sub_b_pow, alu_op_add, alu_op_cast, alu_op_div, alu_op_eq, alu_op_lt, alu_op_lte, alu_op_mul, alu_op_not, alu_op_shl, alu_op_shr, alu_op_sub, alu_partial_prod_hi, alu_partial_prod_lo, alu_range_check_input_value, alu_range_check_num_bits, alu_range_check_sel, alu_remainder, alu_sel_alu, alu_sel_cmp, alu_sel_shift_which, alu_u128_tag, alu_u16_tag, alu_u1_tag, alu_u32_tag, alu_u64_tag, alu_u8_tag, alu_zero_shift, binary_acc_ia, binary_acc_ib, binary_acc_ic, binary_clk, binary_ia_bytes, binary_ib_bytes, binary_ic_bytes, binary_in_tag, binary_mem_tag_ctr, binary_mem_tag_ctr_inv, binary_op_id, binary_sel_bin, binary_start, cmp_a_hi, cmp_a_lo, cmp_b_hi, cmp_b_lo, cmp_borrow, cmp_clk, cmp_cmp_rng_ctr, cmp_input_a, cmp_input_b, cmp_op_eq, cmp_op_eq_diff_inv, cmp_op_gt, cmp_p_a_borrow, cmp_p_b_borrow, cmp_p_sub_a_hi, cmp_p_sub_a_lo, cmp_p_sub_b_hi, cmp_p_sub_b_lo, cmp_range_chk_clk, cmp_res_hi, cmp_res_lo, cmp_result, cmp_sel_cmp, cmp_sel_rng_chk, cmp_shift_sel, conversion_clk, conversion_input, conversion_num_limbs, conversion_output_bits, conversion_radix, conversion_sel_to_radix_le, keccakf1600_clk, keccakf1600_input, keccakf1600_output, keccakf1600_sel_keccakf1600, main_abs_da_rem_gas, main_abs_l2_rem_gas, main_alu_in_tag, main_base_da_gas_op_cost, main_base_l2_gas_op_cost, main_bin_op_id, main_call_ptr, main_da_gas_remaining, main_da_out_of_gas, main_dyn_da_gas_op_cost, main_dyn_gas_multiplier, main_dyn_l2_gas_op_cost, main_emit_l2_to_l1_msg_write_offset, main_emit_note_hash_write_offset, main_emit_nullifier_write_offset, main_emit_unencrypted_log_write_offset, main_ia, main_ib, main_ic, main_id, main_id_zero, main_ind_addr_a, main_ind_addr_b, main_ind_addr_c, main_ind_addr_d, main_internal_return_ptr, main_inv, main_kernel_in_offset, main_kernel_out_offset, main_l1_to_l2_msg_exists_write_offset, main_l2_gas_remaining, main_l2_out_of_gas, main_mem_addr_a, main_mem_addr_b, main_mem_addr_c, main_mem_addr_d, main_note_hash_exist_write_offset, main_nullifier_exists_write_offset, main_nullifier_non_exists_write_offset, main_op_err, main_opcode_val, main_pc, main_r_in_tag, main_rwa, main_rwb, main_rwc, main_rwd, main_sel_alu, main_sel_bin, main_sel_calldata, main_sel_execution_row, main_sel_kernel_inputs, main_sel_kernel_out, main_sel_last, main_sel_mem_op_a, main_sel_mem_op_b, main_sel_mem_op_c, main_sel_mem_op_d, main_sel_mov_ia_to_ic, main_sel_mov_ib_to_ic, main_sel_op_add, main_sel_op_address, main_sel_op_and, main_sel_op_block_number, main_sel_op_calldata_copy, main_sel_op_cast, main_sel_op_chain_id, main_sel_op_cmov, main_sel_op_dagasleft, main_sel_op_div, main_sel_op_ecadd, main_sel_op_emit_l2_to_l1_msg, main_sel_op_emit_note_hash, main_sel_op_emit_nullifier, main_sel_op_emit_unencrypted_log, main_sel_op_eq, main_sel_op_external_call, main_sel_op_external_return, main_sel_op_external_revert, main_sel_op_fdiv, main_sel_op_fee_per_da_gas, main_sel_op_fee_per_l2_gas, main_sel_op_function_selector, main_sel_op_get_contract_instance, main_sel_op_internal_call, main_sel_op_internal_return, main_sel_op_is_static_call, main_sel_op_jump, main_sel_op_jumpi, main_sel_op_keccak, main_sel_op_l1_to_l2_msg_exists, main_sel_op_l2gasleft, main_sel_op_lt, main_sel_op_lte, main_sel_op_mov, main_sel_op_msm, main_sel_op_mul, main_sel_op_not, main_sel_op_note_hash_exists, main_sel_op_nullifier_exists, main_sel_op_or, main_sel_op_pedersen, main_sel_op_pedersen_commit, main_sel_op_poseidon2, main_sel_op_radix_le, main_sel_op_sender, main_sel_op_set, main_sel_op_sha256, main_sel_op_shl, main_sel_op_shr, main_sel_op_sload, main_sel_op_sstore, main_sel_op_static_call, main_sel_op_storage_address, main_sel_op_sub, main_sel_op_timestamp, main_sel_op_transaction_fee, main_sel_op_version, main_sel_op_xor, main_sel_q_kernel_lookup, main_sel_q_kernel_output_lookup, main_sel_resolve_ind_addr_a, main_sel_resolve_ind_addr_b, main_sel_resolve_ind_addr_c, main_sel_resolve_ind_addr_d, main_sel_returndata, main_sel_rng_16, main_sel_rng_8, main_sel_slice_gadget, main_side_effect_counter, main_sload_write_offset, main_space_id, main_sstore_write_offset, main_tag_err, main_w_in_tag, mem_addr, mem_clk, mem_diff, mem_glob_addr, mem_last, mem_lastAccess, mem_one_min_inv, mem_r_in_tag, mem_rw, mem_sel_mem, mem_sel_mov_ia_to_ic, mem_sel_mov_ib_to_ic, mem_sel_op_a, mem_sel_op_b, mem_sel_op_c, mem_sel_op_cmov, mem_sel_op_d, mem_sel_op_poseidon_read_a, mem_sel_op_poseidon_read_b, mem_sel_op_poseidon_read_c, mem_sel_op_poseidon_read_d, mem_sel_op_poseidon_write_a, mem_sel_op_poseidon_write_b, mem_sel_op_poseidon_write_c, mem_sel_op_poseidon_write_d, mem_sel_op_slice, mem_sel_resolve_ind_addr_a, mem_sel_resolve_ind_addr_b, mem_sel_resolve_ind_addr_c, mem_sel_resolve_ind_addr_d, mem_sel_rng_chk, mem_skip_check_tag, mem_space_id, mem_tag, mem_tag_err, mem_tsp, mem_val, mem_w_in_tag, pedersen_clk, pedersen_input, pedersen_output, pedersen_sel_pedersen, poseidon2_B_10_0, poseidon2_B_10_1, poseidon2_B_10_2, poseidon2_B_10_3, poseidon2_B_11_0, poseidon2_B_11_1, poseidon2_B_11_2, poseidon2_B_11_3, poseidon2_B_12_0, poseidon2_B_12_1, poseidon2_B_12_2, poseidon2_B_12_3, poseidon2_B_13_0, poseidon2_B_13_1, poseidon2_B_13_2, poseidon2_B_13_3, poseidon2_B_14_0, poseidon2_B_14_1, poseidon2_B_14_2, poseidon2_B_14_3, poseidon2_B_15_0, poseidon2_B_15_1, poseidon2_B_15_2, poseidon2_B_15_3, poseidon2_B_16_0, poseidon2_B_16_1, poseidon2_B_16_2, poseidon2_B_16_3, poseidon2_B_17_0, poseidon2_B_17_1, poseidon2_B_17_2, poseidon2_B_17_3, poseidon2_B_18_0, poseidon2_B_18_1, poseidon2_B_18_2, poseidon2_B_18_3, poseidon2_B_19_0, poseidon2_B_19_1, poseidon2_B_19_2, poseidon2_B_19_3, poseidon2_B_20_0, poseidon2_B_20_1, poseidon2_B_20_2, poseidon2_B_20_3, poseidon2_B_21_0, poseidon2_B_21_1, poseidon2_B_21_2, poseidon2_B_21_3, poseidon2_B_22_0, poseidon2_B_22_1, poseidon2_B_22_2, poseidon2_B_22_3, poseidon2_B_23_0, poseidon2_B_23_1, poseidon2_B_23_2, poseidon2_B_23_3, poseidon2_B_24_0, poseidon2_B_24_1, poseidon2_B_24_2, poseidon2_B_24_3, poseidon2_B_25_0, poseidon2_B_25_1, poseidon2_B_25_2, poseidon2_B_25_3, poseidon2_B_26_0, poseidon2_B_26_1, poseidon2_B_26_2, poseidon2_B_26_3, poseidon2_B_27_0, poseidon2_B_27_1, poseidon2_B_27_2, poseidon2_B_27_3, poseidon2_B_28_0, poseidon2_B_28_1, poseidon2_B_28_2, poseidon2_B_28_3, poseidon2_B_29_0, poseidon2_B_29_1, poseidon2_B_29_2, poseidon2_B_29_3, poseidon2_B_30_0, poseidon2_B_30_1, poseidon2_B_30_2, poseidon2_B_30_3, poseidon2_B_31_0, poseidon2_B_31_1, poseidon2_B_31_2, poseidon2_B_31_3, poseidon2_B_32_0, poseidon2_B_32_1, poseidon2_B_32_2, poseidon2_B_32_3, poseidon2_B_33_0, poseidon2_B_33_1, poseidon2_B_33_2, poseidon2_B_33_3, poseidon2_B_34_0, poseidon2_B_34_1, poseidon2_B_34_2, poseidon2_B_34_3, poseidon2_B_35_0, poseidon2_B_35_1, poseidon2_B_35_2, poseidon2_B_35_3, poseidon2_B_36_0, poseidon2_B_36_1, poseidon2_B_36_2, poseidon2_B_36_3, poseidon2_B_37_0, poseidon2_B_37_1, poseidon2_B_37_2, poseidon2_B_37_3, poseidon2_B_38_0, poseidon2_B_38_1, poseidon2_B_38_2, poseidon2_B_38_3, poseidon2_B_39_0, poseidon2_B_39_1, poseidon2_B_39_2, poseidon2_B_39_3, poseidon2_B_40_0, poseidon2_B_40_1, poseidon2_B_40_2, poseidon2_B_40_3, poseidon2_B_41_0, poseidon2_B_41_1, poseidon2_B_41_2, poseidon2_B_41_3, poseidon2_B_42_0, poseidon2_B_42_1, poseidon2_B_42_2, poseidon2_B_42_3, poseidon2_B_43_0, poseidon2_B_43_1, poseidon2_B_43_2, poseidon2_B_43_3, poseidon2_B_44_0, poseidon2_B_44_1, poseidon2_B_44_2, poseidon2_B_44_3, poseidon2_B_45_0, poseidon2_B_45_1, poseidon2_B_45_2, poseidon2_B_45_3, poseidon2_B_46_0, poseidon2_B_46_1, poseidon2_B_46_2, poseidon2_B_46_3, poseidon2_B_47_0, poseidon2_B_47_1, poseidon2_B_47_2, poseidon2_B_47_3, poseidon2_B_48_0, poseidon2_B_48_1, poseidon2_B_48_2, poseidon2_B_48_3, poseidon2_B_49_0, poseidon2_B_49_1, poseidon2_B_49_2, poseidon2_B_49_3, poseidon2_B_4_0, poseidon2_B_4_1, poseidon2_B_4_2, poseidon2_B_4_3, poseidon2_B_50_0, poseidon2_B_50_1, poseidon2_B_50_2, poseidon2_B_50_3, poseidon2_B_51_0, poseidon2_B_51_1, poseidon2_B_51_2, poseidon2_B_51_3, poseidon2_B_52_0, poseidon2_B_52_1, poseidon2_B_52_2, poseidon2_B_52_3, poseidon2_B_53_0, poseidon2_B_53_1, poseidon2_B_53_2, poseidon2_B_53_3, poseidon2_B_54_0, poseidon2_B_54_1, poseidon2_B_54_2, poseidon2_B_54_3, poseidon2_B_55_0, poseidon2_B_55_1, poseidon2_B_55_2, poseidon2_B_55_3, poseidon2_B_56_0, poseidon2_B_56_1, poseidon2_B_56_2, poseidon2_B_56_3, poseidon2_B_57_0, poseidon2_B_57_1, poseidon2_B_57_2, poseidon2_B_57_3, poseidon2_B_58_0, poseidon2_B_58_1, poseidon2_B_58_2, poseidon2_B_58_3, poseidon2_B_59_0, poseidon2_B_59_1, poseidon2_B_59_2, poseidon2_B_59_3, poseidon2_B_5_0, poseidon2_B_5_1, poseidon2_B_5_2, poseidon2_B_5_3, poseidon2_B_6_0, poseidon2_B_6_1, poseidon2_B_6_2, poseidon2_B_6_3, poseidon2_B_7_0, poseidon2_B_7_1, poseidon2_B_7_2, poseidon2_B_7_3, poseidon2_B_8_0, poseidon2_B_8_1, poseidon2_B_8_2, poseidon2_B_8_3, poseidon2_B_9_0, poseidon2_B_9_1, poseidon2_B_9_2, poseidon2_B_9_3, poseidon2_EXT_LAYER_4, poseidon2_EXT_LAYER_5, poseidon2_EXT_LAYER_6, poseidon2_EXT_LAYER_7, poseidon2_T_0_4, poseidon2_T_0_5, poseidon2_T_0_6, poseidon2_T_0_7, poseidon2_T_1_4, poseidon2_T_1_5, poseidon2_T_1_6, poseidon2_T_1_7, poseidon2_T_2_4, poseidon2_T_2_5, poseidon2_T_2_6, poseidon2_T_2_7, poseidon2_T_3_4, poseidon2_T_3_5, poseidon2_T_3_6, poseidon2_T_3_7, poseidon2_T_60_4, poseidon2_T_60_5, poseidon2_T_60_6, poseidon2_T_60_7, poseidon2_T_61_4, poseidon2_T_61_5, poseidon2_T_61_6, poseidon2_T_61_7, poseidon2_T_62_4, poseidon2_T_62_5, poseidon2_T_62_6, poseidon2_T_62_7, poseidon2_T_63_4, poseidon2_T_63_5, poseidon2_T_63_6, poseidon2_T_63_7, poseidon2_a_0, poseidon2_a_1, poseidon2_a_2, poseidon2_a_3, poseidon2_b_0, poseidon2_b_1, poseidon2_b_2, poseidon2_b_3, poseidon2_clk, poseidon2_input_addr, poseidon2_mem_addr_read_a, poseidon2_mem_addr_read_b, poseidon2_mem_addr_read_c, poseidon2_mem_addr_read_d, poseidon2_mem_addr_write_a, poseidon2_mem_addr_write_b, poseidon2_mem_addr_write_c, poseidon2_mem_addr_write_d, poseidon2_output_addr, poseidon2_sel_poseidon_perm, range_check_alu_rng_chk, range_check_clk, range_check_cmp_hi_bits_rng_chk, range_check_cmp_lo_bits_rng_chk, range_check_dyn_diff, range_check_dyn_rng_chk_bits, range_check_dyn_rng_chk_pow_2, range_check_gas_da_rng_chk, range_check_gas_l2_rng_chk, range_check_is_lte_u112, range_check_is_lte_u128, range_check_is_lte_u16, range_check_is_lte_u32, range_check_is_lte_u48, range_check_is_lte_u64, range_check_is_lte_u80, range_check_is_lte_u96, range_check_mem_rng_chk, range_check_rng_chk_bits, range_check_sel_lookup_0, range_check_sel_lookup_1, range_check_sel_lookup_2, range_check_sel_lookup_3, range_check_sel_lookup_4, range_check_sel_lookup_5, range_check_sel_lookup_6, range_check_sel_rng_chk, range_check_u16_r0, range_check_u16_r1, range_check_u16_r2, range_check_u16_r3, range_check_u16_r4, range_check_u16_r5, range_check_u16_r6, range_check_u16_r7, range_check_value, sha256_clk, sha256_input, sha256_output, sha256_sel_sha256_compression, sha256_state, slice_addr, slice_clk, slice_cnt, slice_col_offset, slice_one_min_inv, slice_sel_cd_cpy, slice_sel_mem_active, slice_sel_return, slice_sel_start, slice_space_id, slice_val, lookup_rng_chk_pow_2_counts, lookup_rng_chk_diff_counts, lookup_rng_chk_0_counts, lookup_rng_chk_1_counts, lookup_rng_chk_2_counts, lookup_rng_chk_3_counts, lookup_rng_chk_4_counts, lookup_rng_chk_5_counts, lookup_rng_chk_6_counts, lookup_rng_chk_7_counts, lookup_pow_2_0_counts, lookup_pow_2_1_counts, lookup_byte_lengths_counts, lookup_byte_operations_counts, lookup_opcode_gas_counts, kernel_output_lookup_counts, lookup_into_kernel_counts, lookup_cd_value_counts, lookup_ret_value_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts #define DERIVED_WITNESS_ENTITIES perm_rng_mem_inv, perm_rng_cmp_lo_inv, perm_rng_cmp_hi_inv, perm_rng_alu_inv, perm_cmp_alu_inv, perm_rng_gas_l2_inv, perm_rng_gas_da_inv, perm_pos_mem_read_a_inv, perm_pos_mem_read_b_inv, perm_pos_mem_read_c_inv, perm_pos_mem_read_d_inv, perm_pos_mem_write_a_inv, perm_pos_mem_write_b_inv, perm_pos_mem_write_c_inv, perm_pos_mem_write_d_inv, perm_slice_mem_inv, perm_main_alu_inv, perm_main_bin_inv, perm_main_conv_inv, perm_main_pos2_perm_inv, perm_main_pedersen_inv, perm_main_slice_inv, perm_main_mem_a_inv, perm_main_mem_b_inv, perm_main_mem_c_inv, perm_main_mem_d_inv, perm_main_mem_ind_addr_a_inv, perm_main_mem_ind_addr_b_inv, perm_main_mem_ind_addr_c_inv, perm_main_mem_ind_addr_d_inv, lookup_rng_chk_pow_2_inv, lookup_rng_chk_diff_inv, lookup_rng_chk_0_inv, lookup_rng_chk_1_inv, lookup_rng_chk_2_inv, lookup_rng_chk_3_inv, lookup_rng_chk_4_inv, lookup_rng_chk_5_inv, lookup_rng_chk_6_inv, lookup_rng_chk_7_inv, lookup_pow_2_0_inv, lookup_pow_2_1_inv, lookup_byte_lengths_inv, lookup_byte_operations_inv, lookup_opcode_gas_inv, kernel_output_lookup_inv, lookup_into_kernel_inv, lookup_cd_value_inv, lookup_ret_value_inv, incl_main_tag_err_inv, incl_mem_tag_err_inv #define SHIFTED_ENTITIES binary_acc_ia_shift, binary_acc_ib_shift, binary_acc_ic_shift, binary_mem_tag_ctr_shift, binary_op_id_shift, cmp_a_hi_shift, cmp_a_lo_shift, cmp_b_hi_shift, cmp_b_lo_shift, cmp_cmp_rng_ctr_shift, cmp_op_gt_shift, cmp_p_sub_a_hi_shift, cmp_p_sub_a_lo_shift, cmp_p_sub_b_hi_shift, cmp_p_sub_b_lo_shift, cmp_sel_rng_chk_shift, main_da_gas_remaining_shift, main_emit_l2_to_l1_msg_write_offset_shift, main_emit_note_hash_write_offset_shift, main_emit_nullifier_write_offset_shift, main_emit_unencrypted_log_write_offset_shift, main_internal_return_ptr_shift, main_l1_to_l2_msg_exists_write_offset_shift, main_l2_gas_remaining_shift, main_note_hash_exist_write_offset_shift, main_nullifier_exists_write_offset_shift, main_nullifier_non_exists_write_offset_shift, main_pc_shift, main_sel_execution_row_shift, main_sload_write_offset_shift, main_sstore_write_offset_shift, mem_glob_addr_shift, mem_rw_shift, mem_sel_mem_shift, mem_tag_shift, mem_tsp_shift, mem_val_shift, slice_addr_shift, slice_clk_shift, slice_cnt_shift, slice_col_offset_shift, slice_sel_cd_cpy_shift, slice_sel_mem_active_shift, slice_sel_return_shift, slice_sel_start_shift, slice_space_id_shift #define TO_BE_SHIFTED(e) e.binary_acc_ia, e.binary_acc_ib, e.binary_acc_ic, e.binary_mem_tag_ctr, e.binary_op_id, e.cmp_a_hi, e.cmp_a_lo, e.cmp_b_hi, e.cmp_b_lo, e.cmp_cmp_rng_ctr, e.cmp_op_gt, e.cmp_p_sub_a_hi, e.cmp_p_sub_a_lo, e.cmp_p_sub_b_hi, e.cmp_p_sub_b_lo, e.cmp_sel_rng_chk, e.main_da_gas_remaining, e.main_emit_l2_to_l1_msg_write_offset, e.main_emit_note_hash_write_offset, e.main_emit_nullifier_write_offset, e.main_emit_unencrypted_log_write_offset, e.main_internal_return_ptr, e.main_l1_to_l2_msg_exists_write_offset, e.main_l2_gas_remaining, e.main_note_hash_exist_write_offset, e.main_nullifier_exists_write_offset, e.main_nullifier_non_exists_write_offset, e.main_pc, e.main_sel_execution_row, e.main_sload_write_offset, e.main_sstore_write_offset, e.mem_glob_addr, e.mem_rw, e.mem_sel_mem, e.mem_tag, e.mem_tsp, e.mem_val, e.slice_addr, e.slice_clk, e.slice_cnt, e.slice_col_offset, e.slice_sel_cd_cpy, e.slice_sel_mem_active, e.slice_sel_return, e.slice_sel_start, e.slice_space_id @@ -119,12 +119,12 @@ class AvmFlavor { static constexpr bool HasZK = false; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 16; - static constexpr size_t NUM_WITNESS_ENTITIES = 682; + static constexpr size_t NUM_WITNESS_ENTITIES = 683; static constexpr size_t NUM_SHIFTED_ENTITIES = 46; static constexpr size_t NUM_WIRES = NUM_WITNESS_ENTITIES + NUM_PRECOMPUTED_ENTITIES; // We have two copies of the witness entities, so we subtract the number of fixed ones (they have no shift), one for // the unshifted and one for the shifted - static constexpr size_t NUM_ALL_ENTITIES = 744; + static constexpr size_t NUM_ALL_ENTITIES = 745; // The total number of witnesses including shifts and derived entities. static constexpr size_t NUM_ALL_WITNESS_ENTITIES = NUM_WITNESS_ENTITIES + NUM_SHIFTED_ENTITIES; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp index 8ea8fcbaf4d..e1ded958f99 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp @@ -223,6 +223,7 @@ template std::vector AvmFullRow::names() "main_sel_op_get_contract_instance", "main_sel_op_internal_call", "main_sel_op_internal_return", + "main_sel_op_is_static_call", "main_sel_op_jump", "main_sel_op_jumpi", "main_sel_op_keccak", @@ -926,6 +927,7 @@ template RefVector AvmFullRow::as_vector() const main_sel_op_get_contract_instance, main_sel_op_internal_call, main_sel_op_internal_return, + main_sel_op_is_static_call, main_sel_op_jump, main_sel_op_jumpi, main_sel_op_keccak, diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp index 58519dc3bc1..687678508cc 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp @@ -214,6 +214,7 @@ template struct AvmFullRow { FF main_sel_op_get_contract_instance{}; FF main_sel_op_internal_call{}; FF main_sel_op_internal_return{}; + FF main_sel_op_is_static_call{}; FF main_sel_op_jump{}; FF main_sel_op_jumpi{}; FF main_sel_op_keccak{}; @@ -712,7 +713,7 @@ template struct AvmFullRow { RefVector as_vector() const; static std::vector names(); - static constexpr size_t SIZE = 698; + static constexpr size_t SIZE = 699; }; template std::ostream& operator<<(std::ostream& os, AvmFullRow const& row); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp index 1542c964bff..68eb712f40b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp @@ -10,9 +10,9 @@ template class kernelImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; template void static accumulate(ContainerOverSubrelations& evals, @@ -24,6 +24,7 @@ template class kernelImpl { const auto constants_ADDRESS_SELECTOR = FF(1); const auto constants_STORAGE_ADDRESS_SELECTOR = FF(1); const auto constants_FUNCTION_SELECTOR_SELECTOR = FF(2); + const auto constants_IS_STATIC_CALL_SELECTOR = FF(4); const auto constants_CHAIN_ID_SELECTOR = FF(29); const auto constants_VERSION_SELECTOR = FF(30); const auto constants_BLOCK_NUMBER_SELECTOR = FF(31); @@ -180,74 +181,81 @@ template class kernelImpl { } { using Accumulator = typename std::tuple_element_t<15, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_chain_id * (new_term.main_kernel_in_offset - constants_CHAIN_ID_SELECTOR)); + auto tmp = (new_term.main_sel_op_is_static_call * + (new_term.main_kernel_in_offset - constants_IS_STATIC_CALL_SELECTOR)); tmp *= scaling_factor; std::get<15>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<16, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_version * (new_term.main_kernel_in_offset - constants_VERSION_SELECTOR)); + auto tmp = (new_term.main_sel_op_chain_id * (new_term.main_kernel_in_offset - constants_CHAIN_ID_SELECTOR)); tmp *= scaling_factor; std::get<16>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<17, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_block_number * - (new_term.main_kernel_in_offset - constants_BLOCK_NUMBER_SELECTOR)); + auto tmp = (new_term.main_sel_op_version * (new_term.main_kernel_in_offset - constants_VERSION_SELECTOR)); tmp *= scaling_factor; std::get<17>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<18, ContainerOverSubrelations>; - auto tmp = - (new_term.main_sel_op_timestamp * (new_term.main_kernel_in_offset - constants_TIMESTAMP_SELECTOR)); + auto tmp = (new_term.main_sel_op_block_number * + (new_term.main_kernel_in_offset - constants_BLOCK_NUMBER_SELECTOR)); tmp *= scaling_factor; std::get<18>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<19, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_fee_per_da_gas * - (new_term.main_kernel_in_offset - constants_FEE_PER_DA_GAS_SELECTOR)); + auto tmp = + (new_term.main_sel_op_timestamp * (new_term.main_kernel_in_offset - constants_TIMESTAMP_SELECTOR)); tmp *= scaling_factor; std::get<19>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<20, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_fee_per_l2_gas * - (new_term.main_kernel_in_offset - constants_FEE_PER_L2_GAS_SELECTOR)); + auto tmp = (new_term.main_sel_op_fee_per_da_gas * + (new_term.main_kernel_in_offset - constants_FEE_PER_DA_GAS_SELECTOR)); tmp *= scaling_factor; std::get<20>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<21, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_note_hash_exists * - (new_term.main_kernel_out_offset - - (constants_START_NOTE_HASH_EXISTS_WRITE_OFFSET + new_term.main_note_hash_exist_write_offset))); + auto tmp = (new_term.main_sel_op_fee_per_l2_gas * + (new_term.main_kernel_in_offset - constants_FEE_PER_L2_GAS_SELECTOR)); tmp *= scaling_factor; std::get<21>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<22, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.main_note_hash_exist_write_offset); + auto tmp = (new_term.main_sel_op_note_hash_exists * + (new_term.main_kernel_out_offset - + (constants_START_NOTE_HASH_EXISTS_WRITE_OFFSET + new_term.main_note_hash_exist_write_offset))); tmp *= scaling_factor; std::get<22>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<23, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_emit_note_hash * - (new_term.main_kernel_out_offset - - (constants_START_EMIT_NOTE_HASH_WRITE_OFFSET + new_term.main_emit_note_hash_write_offset))); + auto tmp = (new_term.main_sel_first * new_term.main_note_hash_exist_write_offset); tmp *= scaling_factor; std::get<23>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<24, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.main_emit_note_hash_write_offset); + auto tmp = (new_term.main_sel_op_emit_note_hash * + (new_term.main_kernel_out_offset - + (constants_START_EMIT_NOTE_HASH_WRITE_OFFSET + new_term.main_emit_note_hash_write_offset))); tmp *= scaling_factor; std::get<24>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<25, ContainerOverSubrelations>; + auto tmp = (new_term.main_sel_first * new_term.main_emit_note_hash_write_offset); + tmp *= scaling_factor; + std::get<25>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<26, ContainerOverSubrelations>; auto tmp = (new_term.main_sel_op_nullifier_exists * (new_term.main_kernel_out_offset - ((new_term.main_ib * @@ -255,116 +263,116 @@ template class kernelImpl { ((FF(1) - new_term.main_ib) * (constants_START_NULLIFIER_NON_EXISTS_OFFSET + new_term.main_nullifier_non_exists_write_offset))))); tmp *= scaling_factor; - std::get<25>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<26, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.main_nullifier_exists_write_offset); - tmp *= scaling_factor; std::get<26>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<27, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.main_nullifier_non_exists_write_offset); + auto tmp = (new_term.main_sel_first * new_term.main_nullifier_exists_write_offset); tmp *= scaling_factor; std::get<27>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<28, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_emit_nullifier * - (new_term.main_kernel_out_offset - - (constants_START_EMIT_NULLIFIER_WRITE_OFFSET + new_term.main_emit_nullifier_write_offset))); + auto tmp = (new_term.main_sel_first * new_term.main_nullifier_non_exists_write_offset); tmp *= scaling_factor; std::get<28>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<29, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.main_emit_nullifier_write_offset); + auto tmp = (new_term.main_sel_op_emit_nullifier * + (new_term.main_kernel_out_offset - + (constants_START_EMIT_NULLIFIER_WRITE_OFFSET + new_term.main_emit_nullifier_write_offset))); tmp *= scaling_factor; std::get<29>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<30, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_l1_to_l2_msg_exists * - (new_term.main_kernel_out_offset - (constants_START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + - new_term.main_l1_to_l2_msg_exists_write_offset))); + auto tmp = (new_term.main_sel_first * new_term.main_emit_nullifier_write_offset); tmp *= scaling_factor; std::get<30>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<31, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.main_l1_to_l2_msg_exists_write_offset); + auto tmp = (new_term.main_sel_op_l1_to_l2_msg_exists * + (new_term.main_kernel_out_offset - (constants_START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + + new_term.main_l1_to_l2_msg_exists_write_offset))); tmp *= scaling_factor; std::get<31>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<32, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_emit_unencrypted_log * - (new_term.main_kernel_out_offset - (constants_START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET + - new_term.main_emit_unencrypted_log_write_offset))); + auto tmp = (new_term.main_sel_first * new_term.main_l1_to_l2_msg_exists_write_offset); tmp *= scaling_factor; std::get<32>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<33, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.main_emit_unencrypted_log_write_offset); + auto tmp = (new_term.main_sel_op_emit_unencrypted_log * + (new_term.main_kernel_out_offset - (constants_START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET + + new_term.main_emit_unencrypted_log_write_offset))); tmp *= scaling_factor; std::get<33>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<34, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_emit_l2_to_l1_msg * - (new_term.main_kernel_out_offset - (constants_START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET + - new_term.main_emit_l2_to_l1_msg_write_offset))); + auto tmp = (new_term.main_sel_first * new_term.main_emit_unencrypted_log_write_offset); tmp *= scaling_factor; std::get<34>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<35, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.main_emit_l2_to_l1_msg_write_offset); + auto tmp = (new_term.main_sel_op_emit_l2_to_l1_msg * + (new_term.main_kernel_out_offset - (constants_START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET + + new_term.main_emit_l2_to_l1_msg_write_offset))); tmp *= scaling_factor; std::get<35>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<36, ContainerOverSubrelations>; - auto tmp = - (new_term.main_sel_op_sload * (new_term.main_kernel_out_offset - (constants_START_SLOAD_WRITE_OFFSET + - new_term.main_sload_write_offset))); + auto tmp = (new_term.main_sel_first * new_term.main_emit_l2_to_l1_msg_write_offset); tmp *= scaling_factor; std::get<36>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<37, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.main_sload_write_offset); + auto tmp = + (new_term.main_sel_op_sload * (new_term.main_kernel_out_offset - (constants_START_SLOAD_WRITE_OFFSET + + new_term.main_sload_write_offset))); tmp *= scaling_factor; std::get<37>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<38, ContainerOverSubrelations>; - auto tmp = - (new_term.main_sel_op_sstore * (new_term.main_kernel_out_offset - (constants_START_SSTORE_WRITE_OFFSET + - new_term.main_sstore_write_offset))); + auto tmp = (new_term.main_sel_first * new_term.main_sload_write_offset); tmp *= scaling_factor; std::get<38>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<39, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_first * new_term.main_sstore_write_offset); + auto tmp = + (new_term.main_sel_op_sstore * (new_term.main_kernel_out_offset - (constants_START_SSTORE_WRITE_OFFSET + + new_term.main_sstore_write_offset))); tmp *= scaling_factor; std::get<39>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<40, ContainerOverSubrelations>; - auto tmp = (main_KERNEL_INPUT_SELECTORS * (FF(1) - new_term.main_sel_q_kernel_lookup)); + auto tmp = (new_term.main_sel_first * new_term.main_sstore_write_offset); tmp *= scaling_factor; std::get<40>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<41, ContainerOverSubrelations>; - auto tmp = (main_KERNEL_OUTPUT_SELECTORS * (FF(1) - new_term.main_sel_q_kernel_output_lookup)); + auto tmp = (main_KERNEL_INPUT_SELECTORS * (FF(1) - new_term.main_sel_q_kernel_lookup)); tmp *= scaling_factor; std::get<41>(evals) += typename Accumulator::View(tmp); } + { + using Accumulator = typename std::tuple_element_t<42, ContainerOverSubrelations>; + auto tmp = (main_KERNEL_OUTPUT_SELECTORS * (FF(1) - new_term.main_sel_q_kernel_output_lookup)); + tmp *= scaling_factor; + std::get<42>(evals) += typename Accumulator::View(tmp); + } } }; @@ -406,38 +414,40 @@ template class kernel : public Relation> { case 14: return "FEE_TRANSACTION_FEE_KERNEL"; case 15: - return "CHAIN_ID_KERNEL"; + return "IS_STATIC_CALL_KERNEL"; case 16: - return "VERSION_KERNEL"; + return "CHAIN_ID_KERNEL"; case 17: - return "BLOCK_NUMBER_KERNEL"; + return "VERSION_KERNEL"; case 18: - return "TIMESTAMP_KERNEL"; + return "BLOCK_NUMBER_KERNEL"; case 19: - return "FEE_DA_GAS_KERNEL"; + return "TIMESTAMP_KERNEL"; case 20: - return "FEE_L2_GAS_KERNEL"; + return "FEE_DA_GAS_KERNEL"; case 21: + return "FEE_L2_GAS_KERNEL"; + case 22: return "NOTE_HASH_KERNEL_OUTPUT"; - case 23: + case 24: return "EMIT_NOTE_HASH_KERNEL_OUTPUT"; - case 25: + case 26: return "NULLIFIER_EXISTS_KERNEL_OUTPUT"; - case 28: + case 29: return "EMIT_NULLIFIER_KERNEL_OUTPUT"; - case 30: + case 31: return "L1_TO_L2_MSG_EXISTS_KERNEL_OUTPUT"; - case 32: + case 33: return "EMIT_UNENCRYPTED_LOG_KERNEL_OUTPUT"; - case 34: + case 35: return "EMIT_L2_TO_L1_MSGS_KERNEL_OUTPUT"; - case 36: + case 37: return "SLOAD_KERNEL_OUTPUT"; - case 38: + case 39: return "SSTORE_KERNEL_OUTPUT"; - case 40: - return "KERNEL_INPUT_ACTIVE_CHECK"; case 41: + return "KERNEL_INPUT_ACTIVE_CHECK"; + case 42: return "KERNEL_OUTPUT_ACTIVE_CHECK"; } return std::to_string(index); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp index bbed9a78f22..f985dcc30ae 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp @@ -10,11 +10,11 @@ template class mainImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 4, 3, 3, 3, 3, 4, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 3, 3, 4, 4, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 4, 2, 2 + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 4, 4, 3, 3, 3, 3, 4, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 3, 3, 4, 4, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 4, 2, 2 }; template @@ -168,633 +168,639 @@ template class mainImpl { } { using Accumulator = typename std::tuple_element_t<13, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_l2gasleft * (FF(1) - new_term.main_sel_op_l2gasleft)); + auto tmp = (new_term.main_sel_op_is_static_call * (FF(1) - new_term.main_sel_op_is_static_call)); tmp *= scaling_factor; std::get<13>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<14, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_dagasleft * (FF(1) - new_term.main_sel_op_dagasleft)); + auto tmp = (new_term.main_sel_op_l2gasleft * (FF(1) - new_term.main_sel_op_l2gasleft)); tmp *= scaling_factor; std::get<14>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<15, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_note_hash_exists * (FF(1) - new_term.main_sel_op_note_hash_exists)); + auto tmp = (new_term.main_sel_op_dagasleft * (FF(1) - new_term.main_sel_op_dagasleft)); tmp *= scaling_factor; std::get<15>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<16, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_emit_note_hash * (FF(1) - new_term.main_sel_op_emit_note_hash)); + auto tmp = (new_term.main_sel_op_note_hash_exists * (FF(1) - new_term.main_sel_op_note_hash_exists)); tmp *= scaling_factor; std::get<16>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<17, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_nullifier_exists * (FF(1) - new_term.main_sel_op_nullifier_exists)); + auto tmp = (new_term.main_sel_op_emit_note_hash * (FF(1) - new_term.main_sel_op_emit_note_hash)); tmp *= scaling_factor; std::get<17>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<18, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_emit_nullifier * (FF(1) - new_term.main_sel_op_emit_nullifier)); + auto tmp = (new_term.main_sel_op_nullifier_exists * (FF(1) - new_term.main_sel_op_nullifier_exists)); tmp *= scaling_factor; std::get<18>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<19, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_l1_to_l2_msg_exists * (FF(1) - new_term.main_sel_op_l1_to_l2_msg_exists)); + auto tmp = (new_term.main_sel_op_emit_nullifier * (FF(1) - new_term.main_sel_op_emit_nullifier)); tmp *= scaling_factor; std::get<19>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<20, ContainerOverSubrelations>; - auto tmp = - (new_term.main_sel_op_emit_unencrypted_log * (FF(1) - new_term.main_sel_op_emit_unencrypted_log)); + auto tmp = (new_term.main_sel_op_l1_to_l2_msg_exists * (FF(1) - new_term.main_sel_op_l1_to_l2_msg_exists)); tmp *= scaling_factor; std::get<20>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<21, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_emit_l2_to_l1_msg * (FF(1) - new_term.main_sel_op_emit_l2_to_l1_msg)); + auto tmp = + (new_term.main_sel_op_emit_unencrypted_log * (FF(1) - new_term.main_sel_op_emit_unencrypted_log)); tmp *= scaling_factor; std::get<21>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<22, ContainerOverSubrelations>; - auto tmp = - (new_term.main_sel_op_get_contract_instance * (FF(1) - new_term.main_sel_op_get_contract_instance)); + auto tmp = (new_term.main_sel_op_emit_l2_to_l1_msg * (FF(1) - new_term.main_sel_op_emit_l2_to_l1_msg)); tmp *= scaling_factor; std::get<22>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<23, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_sload * (FF(1) - new_term.main_sel_op_sload)); + auto tmp = + (new_term.main_sel_op_get_contract_instance * (FF(1) - new_term.main_sel_op_get_contract_instance)); tmp *= scaling_factor; std::get<23>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<24, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_sstore * (FF(1) - new_term.main_sel_op_sstore)); + auto tmp = (new_term.main_sel_op_sload * (FF(1) - new_term.main_sel_op_sload)); tmp *= scaling_factor; std::get<24>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<25, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_radix_le * (FF(1) - new_term.main_sel_op_radix_le)); + auto tmp = (new_term.main_sel_op_sstore * (FF(1) - new_term.main_sel_op_sstore)); tmp *= scaling_factor; std::get<25>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<26, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_sha256 * (FF(1) - new_term.main_sel_op_sha256)); + auto tmp = (new_term.main_sel_op_radix_le * (FF(1) - new_term.main_sel_op_radix_le)); tmp *= scaling_factor; std::get<26>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<27, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_poseidon2 * (FF(1) - new_term.main_sel_op_poseidon2)); + auto tmp = (new_term.main_sel_op_sha256 * (FF(1) - new_term.main_sel_op_sha256)); tmp *= scaling_factor; std::get<27>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<28, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_keccak * (FF(1) - new_term.main_sel_op_keccak)); + auto tmp = (new_term.main_sel_op_poseidon2 * (FF(1) - new_term.main_sel_op_poseidon2)); tmp *= scaling_factor; std::get<28>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<29, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_pedersen * (FF(1) - new_term.main_sel_op_pedersen)); + auto tmp = (new_term.main_sel_op_keccak * (FF(1) - new_term.main_sel_op_keccak)); tmp *= scaling_factor; std::get<29>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<30, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_ecadd * (FF(1) - new_term.main_sel_op_ecadd)); + auto tmp = (new_term.main_sel_op_pedersen * (FF(1) - new_term.main_sel_op_pedersen)); tmp *= scaling_factor; std::get<30>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<31, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_pedersen_commit * (FF(1) - new_term.main_sel_op_pedersen_commit)); + auto tmp = (new_term.main_sel_op_ecadd * (FF(1) - new_term.main_sel_op_ecadd)); tmp *= scaling_factor; std::get<31>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<32, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_msm * (FF(1) - new_term.main_sel_op_msm)); + auto tmp = (new_term.main_sel_op_pedersen_commit * (FF(1) - new_term.main_sel_op_pedersen_commit)); tmp *= scaling_factor; std::get<32>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<33, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_add * (FF(1) - new_term.main_sel_op_add)); + auto tmp = (new_term.main_sel_op_msm * (FF(1) - new_term.main_sel_op_msm)); tmp *= scaling_factor; std::get<33>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<34, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_sub * (FF(1) - new_term.main_sel_op_sub)); + auto tmp = (new_term.main_sel_op_add * (FF(1) - new_term.main_sel_op_add)); tmp *= scaling_factor; std::get<34>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<35, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_mul * (FF(1) - new_term.main_sel_op_mul)); + auto tmp = (new_term.main_sel_op_sub * (FF(1) - new_term.main_sel_op_sub)); tmp *= scaling_factor; std::get<35>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<36, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_div * (FF(1) - new_term.main_sel_op_div)); + auto tmp = (new_term.main_sel_op_mul * (FF(1) - new_term.main_sel_op_mul)); tmp *= scaling_factor; std::get<36>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<37, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_fdiv * (FF(1) - new_term.main_sel_op_fdiv)); + auto tmp = (new_term.main_sel_op_div * (FF(1) - new_term.main_sel_op_div)); tmp *= scaling_factor; std::get<37>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<38, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_not * (FF(1) - new_term.main_sel_op_not)); + auto tmp = (new_term.main_sel_op_fdiv * (FF(1) - new_term.main_sel_op_fdiv)); tmp *= scaling_factor; std::get<38>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<39, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_eq * (FF(1) - new_term.main_sel_op_eq)); + auto tmp = (new_term.main_sel_op_not * (FF(1) - new_term.main_sel_op_not)); tmp *= scaling_factor; std::get<39>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<40, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_and * (FF(1) - new_term.main_sel_op_and)); + auto tmp = (new_term.main_sel_op_eq * (FF(1) - new_term.main_sel_op_eq)); tmp *= scaling_factor; std::get<40>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<41, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_or * (FF(1) - new_term.main_sel_op_or)); + auto tmp = (new_term.main_sel_op_and * (FF(1) - new_term.main_sel_op_and)); tmp *= scaling_factor; std::get<41>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<42, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_xor * (FF(1) - new_term.main_sel_op_xor)); + auto tmp = (new_term.main_sel_op_or * (FF(1) - new_term.main_sel_op_or)); tmp *= scaling_factor; std::get<42>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<43, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_cast * (FF(1) - new_term.main_sel_op_cast)); + auto tmp = (new_term.main_sel_op_xor * (FF(1) - new_term.main_sel_op_xor)); tmp *= scaling_factor; std::get<43>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<44, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_lt * (FF(1) - new_term.main_sel_op_lt)); + auto tmp = (new_term.main_sel_op_cast * (FF(1) - new_term.main_sel_op_cast)); tmp *= scaling_factor; std::get<44>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<45, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_lte * (FF(1) - new_term.main_sel_op_lte)); + auto tmp = (new_term.main_sel_op_lt * (FF(1) - new_term.main_sel_op_lt)); tmp *= scaling_factor; std::get<45>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<46, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_shl * (FF(1) - new_term.main_sel_op_shl)); + auto tmp = (new_term.main_sel_op_lte * (FF(1) - new_term.main_sel_op_lte)); tmp *= scaling_factor; std::get<46>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<47, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_shr * (FF(1) - new_term.main_sel_op_shr)); + auto tmp = (new_term.main_sel_op_shl * (FF(1) - new_term.main_sel_op_shl)); tmp *= scaling_factor; std::get<47>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<48, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_call * (FF(1) - new_term.main_sel_op_internal_call)); + auto tmp = (new_term.main_sel_op_shr * (FF(1) - new_term.main_sel_op_shr)); tmp *= scaling_factor; std::get<48>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<49, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_return * (FF(1) - new_term.main_sel_op_internal_return)); + auto tmp = (new_term.main_sel_op_internal_call * (FF(1) - new_term.main_sel_op_internal_call)); tmp *= scaling_factor; std::get<49>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<50, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_jump * (FF(1) - new_term.main_sel_op_jump)); + auto tmp = (new_term.main_sel_op_internal_return * (FF(1) - new_term.main_sel_op_internal_return)); tmp *= scaling_factor; std::get<50>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<51, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_jumpi * (FF(1) - new_term.main_sel_op_jumpi)); + auto tmp = (new_term.main_sel_op_jump * (FF(1) - new_term.main_sel_op_jump)); tmp *= scaling_factor; std::get<51>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<52, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_external_call * (FF(1) - new_term.main_sel_op_external_call)); + auto tmp = (new_term.main_sel_op_jumpi * (FF(1) - new_term.main_sel_op_jumpi)); tmp *= scaling_factor; std::get<52>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<53, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_static_call * (FF(1) - new_term.main_sel_op_static_call)); + auto tmp = (new_term.main_sel_op_external_call * (FF(1) - new_term.main_sel_op_external_call)); tmp *= scaling_factor; std::get<53>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<54, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_calldata_copy * (FF(1) - new_term.main_sel_op_calldata_copy)); + auto tmp = (new_term.main_sel_op_static_call * (FF(1) - new_term.main_sel_op_static_call)); tmp *= scaling_factor; std::get<54>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<55, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_external_return * (FF(1) - new_term.main_sel_op_external_return)); + auto tmp = (new_term.main_sel_op_calldata_copy * (FF(1) - new_term.main_sel_op_calldata_copy)); tmp *= scaling_factor; std::get<55>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<56, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_external_revert * (FF(1) - new_term.main_sel_op_external_revert)); + auto tmp = (new_term.main_sel_op_external_return * (FF(1) - new_term.main_sel_op_external_return)); tmp *= scaling_factor; std::get<56>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<57, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_set * (FF(1) - new_term.main_sel_op_set)); + auto tmp = (new_term.main_sel_op_external_revert * (FF(1) - new_term.main_sel_op_external_revert)); tmp *= scaling_factor; std::get<57>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<58, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_mov * (FF(1) - new_term.main_sel_op_mov)); + auto tmp = (new_term.main_sel_op_set * (FF(1) - new_term.main_sel_op_set)); tmp *= scaling_factor; std::get<58>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<59, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_cmov * (FF(1) - new_term.main_sel_op_cmov)); + auto tmp = (new_term.main_sel_op_mov * (FF(1) - new_term.main_sel_op_mov)); tmp *= scaling_factor; std::get<59>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<60, ContainerOverSubrelations>; - auto tmp = (new_term.main_op_err * (FF(1) - new_term.main_op_err)); + auto tmp = (new_term.main_sel_op_cmov * (FF(1) - new_term.main_sel_op_cmov)); tmp *= scaling_factor; std::get<60>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<61, ContainerOverSubrelations>; - auto tmp = (new_term.main_tag_err * (FF(1) - new_term.main_tag_err)); + auto tmp = (new_term.main_op_err * (FF(1) - new_term.main_op_err)); tmp *= scaling_factor; std::get<61>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<62, ContainerOverSubrelations>; - auto tmp = (new_term.main_id_zero * (FF(1) - new_term.main_id_zero)); + auto tmp = (new_term.main_tag_err * (FF(1) - new_term.main_tag_err)); tmp *= scaling_factor; std::get<62>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<63, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_mem_op_a * (FF(1) - new_term.main_sel_mem_op_a)); + auto tmp = (new_term.main_id_zero * (FF(1) - new_term.main_id_zero)); tmp *= scaling_factor; std::get<63>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<64, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_mem_op_b * (FF(1) - new_term.main_sel_mem_op_b)); + auto tmp = (new_term.main_sel_mem_op_a * (FF(1) - new_term.main_sel_mem_op_a)); tmp *= scaling_factor; std::get<64>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<65, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_mem_op_c * (FF(1) - new_term.main_sel_mem_op_c)); + auto tmp = (new_term.main_sel_mem_op_b * (FF(1) - new_term.main_sel_mem_op_b)); tmp *= scaling_factor; std::get<65>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<66, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_mem_op_d * (FF(1) - new_term.main_sel_mem_op_d)); + auto tmp = (new_term.main_sel_mem_op_c * (FF(1) - new_term.main_sel_mem_op_c)); tmp *= scaling_factor; std::get<66>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<67, ContainerOverSubrelations>; - auto tmp = (new_term.main_rwa * (FF(1) - new_term.main_rwa)); + auto tmp = (new_term.main_sel_mem_op_d * (FF(1) - new_term.main_sel_mem_op_d)); tmp *= scaling_factor; std::get<67>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<68, ContainerOverSubrelations>; - auto tmp = (new_term.main_rwb * (FF(1) - new_term.main_rwb)); + auto tmp = (new_term.main_rwa * (FF(1) - new_term.main_rwa)); tmp *= scaling_factor; std::get<68>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<69, ContainerOverSubrelations>; - auto tmp = (new_term.main_rwc * (FF(1) - new_term.main_rwc)); + auto tmp = (new_term.main_rwb * (FF(1) - new_term.main_rwb)); tmp *= scaling_factor; std::get<69>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<70, ContainerOverSubrelations>; - auto tmp = (new_term.main_rwd * (FF(1) - new_term.main_rwd)); + auto tmp = (new_term.main_rwc * (FF(1) - new_term.main_rwc)); tmp *= scaling_factor; std::get<70>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<71, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_resolve_ind_addr_a * (FF(1) - new_term.main_sel_resolve_ind_addr_a)); + auto tmp = (new_term.main_rwd * (FF(1) - new_term.main_rwd)); tmp *= scaling_factor; std::get<71>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<72, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_resolve_ind_addr_b * (FF(1) - new_term.main_sel_resolve_ind_addr_b)); + auto tmp = (new_term.main_sel_resolve_ind_addr_a * (FF(1) - new_term.main_sel_resolve_ind_addr_a)); tmp *= scaling_factor; std::get<72>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<73, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_resolve_ind_addr_c * (FF(1) - new_term.main_sel_resolve_ind_addr_c)); + auto tmp = (new_term.main_sel_resolve_ind_addr_b * (FF(1) - new_term.main_sel_resolve_ind_addr_b)); tmp *= scaling_factor; std::get<73>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<74, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_resolve_ind_addr_d * (FF(1) - new_term.main_sel_resolve_ind_addr_d)); + auto tmp = (new_term.main_sel_resolve_ind_addr_c * (FF(1) - new_term.main_sel_resolve_ind_addr_c)); tmp *= scaling_factor; std::get<74>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<75, ContainerOverSubrelations>; - auto tmp = (((new_term.main_sel_op_eq + new_term.main_sel_op_lte) + new_term.main_sel_op_lt) * - (new_term.main_w_in_tag - constants_MEM_TAG_U1)); + auto tmp = (new_term.main_sel_resolve_ind_addr_d * (FF(1) - new_term.main_sel_resolve_ind_addr_d)); tmp *= scaling_factor; std::get<75>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<76, ContainerOverSubrelations>; - auto tmp = ((new_term.main_sel_op_fdiv * (FF(1) - new_term.main_op_err)) * - ((new_term.main_ic * new_term.main_ib) - new_term.main_ia)); + auto tmp = (((new_term.main_sel_op_eq + new_term.main_sel_op_lte) + new_term.main_sel_op_lt) * + (new_term.main_w_in_tag - constants_MEM_TAG_U1)); tmp *= scaling_factor; std::get<76>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<77, ContainerOverSubrelations>; - auto tmp = ((new_term.main_sel_op_fdiv + new_term.main_sel_op_div) * - (((new_term.main_ib * new_term.main_inv) - FF(1)) + new_term.main_op_err)); + auto tmp = ((new_term.main_sel_op_fdiv * (FF(1) - new_term.main_op_err)) * + ((new_term.main_ic * new_term.main_ib) - new_term.main_ia)); tmp *= scaling_factor; std::get<77>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<78, ContainerOverSubrelations>; - auto tmp = (((new_term.main_sel_op_fdiv + new_term.main_sel_op_div) * new_term.main_op_err) * - (FF(1) - new_term.main_inv)); + auto tmp = ((new_term.main_sel_op_fdiv + new_term.main_sel_op_div) * + (((new_term.main_ib * new_term.main_inv) - FF(1)) + new_term.main_op_err)); tmp *= scaling_factor; std::get<78>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<79, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_fdiv * (new_term.main_r_in_tag - constants_MEM_TAG_FF)); + auto tmp = (((new_term.main_sel_op_fdiv + new_term.main_sel_op_div) * new_term.main_op_err) * + (FF(1) - new_term.main_inv)); tmp *= scaling_factor; std::get<79>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<80, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_fdiv * (new_term.main_w_in_tag - constants_MEM_TAG_FF)); + auto tmp = (new_term.main_sel_op_fdiv * (new_term.main_r_in_tag - constants_MEM_TAG_FF)); tmp *= scaling_factor; std::get<80>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<81, ContainerOverSubrelations>; - auto tmp = (new_term.main_op_err * ((new_term.main_sel_op_fdiv + new_term.main_sel_op_div) - FF(1))); + auto tmp = (new_term.main_sel_op_fdiv * (new_term.main_w_in_tag - constants_MEM_TAG_FF)); tmp *= scaling_factor; std::get<81>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<82, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_jump * (new_term.main_pc_shift - new_term.main_ia)); + auto tmp = (new_term.main_op_err * ((new_term.main_sel_op_fdiv + new_term.main_sel_op_div) - FF(1))); tmp *= scaling_factor; std::get<82>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<83, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_jumpi * - (((FF(1) - new_term.main_id_zero) * (new_term.main_pc_shift - new_term.main_ia)) + - (new_term.main_id_zero * ((new_term.main_pc_shift - new_term.main_pc) - FF(1))))); + auto tmp = (new_term.main_sel_op_jump * (new_term.main_pc_shift - new_term.main_ia)); tmp *= scaling_factor; std::get<83>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<84, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_call * - (new_term.main_internal_return_ptr_shift - (new_term.main_internal_return_ptr + FF(1)))); + auto tmp = (new_term.main_sel_op_jumpi * + (((FF(1) - new_term.main_id_zero) * (new_term.main_pc_shift - new_term.main_ia)) + + (new_term.main_id_zero * ((new_term.main_pc_shift - new_term.main_pc) - FF(1))))); tmp *= scaling_factor; std::get<84>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<85, ContainerOverSubrelations>; - auto tmp = - (new_term.main_sel_op_internal_call * (new_term.main_internal_return_ptr - new_term.main_mem_addr_b)); + auto tmp = (new_term.main_sel_op_internal_call * + (new_term.main_internal_return_ptr_shift - (new_term.main_internal_return_ptr + FF(1)))); tmp *= scaling_factor; std::get<85>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<86, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_pc_shift - new_term.main_ia)); + auto tmp = + (new_term.main_sel_op_internal_call * (new_term.main_internal_return_ptr - new_term.main_mem_addr_b)); tmp *= scaling_factor; std::get<86>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<87, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_call * ((new_term.main_pc + FF(1)) - new_term.main_ib)); + auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_pc_shift - new_term.main_ia)); tmp *= scaling_factor; std::get<87>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<88, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_rwb - FF(1))); + auto tmp = (new_term.main_sel_op_internal_call * ((new_term.main_pc + FF(1)) - new_term.main_ib)); tmp *= scaling_factor; std::get<88>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<89, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_sel_mem_op_b - FF(1))); + auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_rwb - FF(1))); tmp *= scaling_factor; std::get<89>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<90, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_return * - (new_term.main_internal_return_ptr_shift - (new_term.main_internal_return_ptr - FF(1)))); + auto tmp = (new_term.main_sel_op_internal_call * (new_term.main_sel_mem_op_b - FF(1))); tmp *= scaling_factor; std::get<90>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<91, ContainerOverSubrelations>; auto tmp = (new_term.main_sel_op_internal_return * - ((new_term.main_internal_return_ptr - FF(1)) - new_term.main_mem_addr_a)); + (new_term.main_internal_return_ptr_shift - (new_term.main_internal_return_ptr - FF(1)))); tmp *= scaling_factor; std::get<91>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<92, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_return * (new_term.main_pc_shift - new_term.main_ia)); + auto tmp = (new_term.main_sel_op_internal_return * + ((new_term.main_internal_return_ptr - FF(1)) - new_term.main_mem_addr_a)); tmp *= scaling_factor; std::get<92>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<93, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_return * new_term.main_rwa); + auto tmp = (new_term.main_sel_op_internal_return * (new_term.main_pc_shift - new_term.main_ia)); tmp *= scaling_factor; std::get<93>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<94, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_internal_return * (new_term.main_sel_mem_op_a - FF(1))); + auto tmp = (new_term.main_sel_op_internal_return * new_term.main_rwa); tmp *= scaling_factor; std::get<94>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<95, ContainerOverSubrelations>; - auto tmp = ((main_CUR_AND_NEXT_ARE_MAIN * (FF(1) - main_SEL_ALL_CTRL_FLOW)) * - (new_term.main_pc_shift - (new_term.main_pc + FF(1)))); + auto tmp = (new_term.main_sel_op_internal_return * (new_term.main_sel_mem_op_a - FF(1))); tmp *= scaling_factor; std::get<95>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<96, ContainerOverSubrelations>; auto tmp = ((main_CUR_AND_NEXT_ARE_MAIN * (FF(1) - main_SEL_ALL_CTRL_FLOW)) * - (new_term.main_internal_return_ptr_shift - new_term.main_internal_return_ptr)); + (new_term.main_pc_shift - (new_term.main_pc + FF(1)))); tmp *= scaling_factor; std::get<96>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<97, ContainerOverSubrelations>; - auto tmp = ((new_term.main_sel_op_internal_call + new_term.main_sel_op_internal_return) * - (new_term.main_space_id - constants_misc_INTERNAL_CALL_SPACE_ID)); + auto tmp = ((main_CUR_AND_NEXT_ARE_MAIN * (FF(1) - main_SEL_ALL_CTRL_FLOW)) * + (new_term.main_internal_return_ptr_shift - new_term.main_internal_return_ptr)); tmp *= scaling_factor; std::get<97>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<98, ContainerOverSubrelations>; - auto tmp = (((FF(1) - new_term.main_sel_op_internal_call) - new_term.main_sel_op_internal_return) * - (new_term.main_call_ptr - new_term.main_space_id)); + auto tmp = ((new_term.main_sel_op_internal_call + new_term.main_sel_op_internal_return) * + (new_term.main_space_id - constants_misc_INTERNAL_CALL_SPACE_ID)); tmp *= scaling_factor; std::get<98>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<99, ContainerOverSubrelations>; - auto tmp = ((new_term.main_sel_op_cmov + new_term.main_sel_op_jumpi) * - (((new_term.main_id * new_term.main_inv) - FF(1)) + new_term.main_id_zero)); + auto tmp = (((FF(1) - new_term.main_sel_op_internal_call) - new_term.main_sel_op_internal_return) * + (new_term.main_call_ptr - new_term.main_space_id)); tmp *= scaling_factor; std::get<99>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<100, ContainerOverSubrelations>; - auto tmp = (((new_term.main_sel_op_cmov + new_term.main_sel_op_jumpi) * new_term.main_id_zero) * - (FF(1) - new_term.main_inv)); + auto tmp = ((new_term.main_sel_op_cmov + new_term.main_sel_op_jumpi) * + (((new_term.main_id * new_term.main_inv) - FF(1)) + new_term.main_id_zero)); tmp *= scaling_factor; std::get<100>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<101, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_mov_ia_to_ic - - (new_term.main_sel_op_mov + (new_term.main_sel_op_cmov * (FF(1) - new_term.main_id_zero)))); + auto tmp = (((new_term.main_sel_op_cmov + new_term.main_sel_op_jumpi) * new_term.main_id_zero) * + (FF(1) - new_term.main_inv)); tmp *= scaling_factor; std::get<101>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<102, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_mov_ib_to_ic - (new_term.main_sel_op_cmov * new_term.main_id_zero)); + auto tmp = (new_term.main_sel_mov_ia_to_ic - + (new_term.main_sel_op_mov + (new_term.main_sel_op_cmov * (FF(1) - new_term.main_id_zero)))); tmp *= scaling_factor; std::get<102>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<103, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_mov_ia_to_ic * (new_term.main_ia - new_term.main_ic)); + auto tmp = (new_term.main_sel_mov_ib_to_ic - (new_term.main_sel_op_cmov * new_term.main_id_zero)); tmp *= scaling_factor; std::get<103>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<104, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_mov_ib_to_ic * (new_term.main_ib - new_term.main_ic)); + auto tmp = (new_term.main_sel_mov_ia_to_ic * (new_term.main_ia - new_term.main_ic)); tmp *= scaling_factor; std::get<104>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<105, ContainerOverSubrelations>; - auto tmp = ((new_term.main_sel_op_mov + new_term.main_sel_op_cmov) * - (new_term.main_r_in_tag - new_term.main_w_in_tag)); + auto tmp = (new_term.main_sel_mov_ib_to_ic * (new_term.main_ib - new_term.main_ic)); tmp *= scaling_factor; std::get<105>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<106, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_alu - - ((main_SEL_ALL_ALU * (FF(1) - new_term.main_tag_err)) * (FF(1) - new_term.main_op_err))); + auto tmp = ((new_term.main_sel_op_mov + new_term.main_sel_op_cmov) * + (new_term.main_r_in_tag - new_term.main_w_in_tag)); tmp *= scaling_factor; std::get<106>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<107, ContainerOverSubrelations>; - auto tmp = (main_SEL_ALU_R_TAG * (new_term.main_alu_in_tag - new_term.main_r_in_tag)); + auto tmp = (new_term.main_sel_alu - + ((main_SEL_ALL_ALU * (FF(1) - new_term.main_tag_err)) * (FF(1) - new_term.main_op_err))); tmp *= scaling_factor; std::get<107>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<108, ContainerOverSubrelations>; - auto tmp = (main_SEL_ALU_W_TAG * (new_term.main_alu_in_tag - new_term.main_w_in_tag)); + auto tmp = (main_SEL_ALU_R_TAG * (new_term.main_alu_in_tag - new_term.main_r_in_tag)); tmp *= scaling_factor; std::get<108>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<109, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_l2gasleft * (new_term.main_ia - new_term.main_l2_gas_remaining_shift)); + auto tmp = (main_SEL_ALU_W_TAG * (new_term.main_alu_in_tag - new_term.main_w_in_tag)); tmp *= scaling_factor; std::get<109>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<110, ContainerOverSubrelations>; - auto tmp = (new_term.main_sel_op_dagasleft * (new_term.main_ia - new_term.main_da_gas_remaining_shift)); + auto tmp = (new_term.main_sel_op_l2gasleft * (new_term.main_ia - new_term.main_l2_gas_remaining_shift)); tmp *= scaling_factor; std::get<110>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<111, ContainerOverSubrelations>; - auto tmp = ((new_term.main_ib * (FF(1) - new_term.main_tag_err)) * - ((new_term.main_sel_op_calldata_copy + new_term.main_sel_op_external_return) - - new_term.main_sel_slice_gadget)); + auto tmp = (new_term.main_sel_op_dagasleft * (new_term.main_ia - new_term.main_da_gas_remaining_shift)); tmp *= scaling_factor; std::get<111>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<112, ContainerOverSubrelations>; - auto tmp = (new_term.main_bin_op_id - (new_term.main_sel_op_or + (FF(2) * new_term.main_sel_op_xor))); + auto tmp = ((new_term.main_ib * (FF(1) - new_term.main_tag_err)) * + ((new_term.main_sel_op_calldata_copy + new_term.main_sel_op_external_return) - + new_term.main_sel_slice_gadget)); tmp *= scaling_factor; std::get<112>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<113, ContainerOverSubrelations>; + auto tmp = (new_term.main_bin_op_id - (new_term.main_sel_op_or + (FF(2) * new_term.main_sel_op_xor))); + tmp *= scaling_factor; + std::get<113>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<114, ContainerOverSubrelations>; auto tmp = (new_term.main_sel_bin - ((new_term.main_sel_op_and + new_term.main_sel_op_or) + new_term.main_sel_op_xor)); tmp *= scaling_factor; - std::get<113>(evals) += typename Accumulator::View(tmp); + std::get<114>(evals) += typename Accumulator::View(tmp); } } }; @@ -808,53 +814,53 @@ template class main : public Relation> { switch (index) { case 0: return "OPCODE_SELECTORS"; - case 75: - return "OUTPUT_U1"; case 76: - return "SUBOP_FDIV"; + return "OUTPUT_U1"; case 77: - return "SUBOP_FDIV_ZERO_ERR1"; + return "SUBOP_FDIV"; case 78: - return "SUBOP_FDIV_ZERO_ERR2"; + return "SUBOP_FDIV_ZERO_ERR1"; case 79: - return "SUBOP_FDIV_R_IN_TAG_FF"; + return "SUBOP_FDIV_ZERO_ERR2"; case 80: - return "SUBOP_FDIV_W_IN_TAG_FF"; + return "SUBOP_FDIV_R_IN_TAG_FF"; case 81: - return "SUBOP_ERROR_RELEVANT_OP"; + return "SUBOP_FDIV_W_IN_TAG_FF"; case 82: - return "PC_JUMP"; + return "SUBOP_ERROR_RELEVANT_OP"; case 83: - return "PC_JUMPI"; + return "PC_JUMP"; case 84: + return "PC_JUMPI"; + case 85: return "RETURN_POINTER_INCREMENT"; - case 90: + case 91: return "RETURN_POINTER_DECREMENT"; - case 95: - return "PC_INCREMENT"; case 96: - return "INTERNAL_RETURN_POINTER_CONSISTENCY"; + return "PC_INCREMENT"; case 97: - return "SPACE_ID_INTERNAL"; + return "INTERNAL_RETURN_POINTER_CONSISTENCY"; case 98: - return "SPACE_ID_STANDARD_OPCODES"; + return "SPACE_ID_INTERNAL"; case 99: - return "CMOV_CONDITION_RES_1"; + return "SPACE_ID_STANDARD_OPCODES"; case 100: + return "CMOV_CONDITION_RES_1"; + case 101: return "CMOV_CONDITION_RES_2"; - case 103: - return "MOV_SAME_VALUE_A"; case 104: - return "MOV_SAME_VALUE_B"; + return "MOV_SAME_VALUE_A"; case 105: + return "MOV_SAME_VALUE_B"; + case 106: return "MOV_MAIN_SAME_TAG"; - case 109: - return "L2GASLEFT"; case 110: + return "L2GASLEFT"; + case 111: return "DAGASLEFT"; - case 112: - return "BIN_SEL_1"; case 113: + return "BIN_SEL_1"; + case 114: return "BIN_SEL_2"; } return std::to_string(index); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.cpp index 348e08df33a..26e2a9a27b4 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.cpp @@ -155,6 +155,16 @@ FF AvmKernelTraceBuilder::op_fee_per_l2_gas(uint32_t clk) return perform_kernel_input_lookup(FEE_PER_L2_GAS_SELECTOR); } +FF AvmKernelTraceBuilder::op_is_static_call(uint32_t clk) +{ + KernelTraceEntry entry = { + .clk = clk, + .operation = KernelTraceOpType::IS_STATIC_CALL, + }; + kernel_trace.push_back(entry); + return perform_kernel_input_lookup(IS_STATIC_CALL_SELECTOR); +} + // TODO(https://github.com/AztecProtocol/aztec-packages/issues/6481): need to process hint from avm in order to know if // output should be set to true or not void AvmKernelTraceBuilder::op_note_hash_exists(uint32_t clk, @@ -399,6 +409,10 @@ void AvmKernelTraceBuilder::finalize(std::vector>& main_trace) dest.main_kernel_in_offset = FEE_PER_L2_GAS_SELECTOR; dest.main_sel_q_kernel_lookup = 1; break; + case KernelTraceOpType::IS_STATIC_CALL: + dest.main_kernel_in_offset = IS_STATIC_CALL_SELECTOR; + dest.main_sel_q_kernel_lookup = 1; + break; // OUT case KernelTraceOpType::NOTE_HASH_EXISTS: dest.main_kernel_out_offset = src.kernel_out_offset; @@ -500,25 +514,11 @@ void AvmKernelTraceBuilder::finalize_columns(std::vector>& main_t for (auto const& [selector, count] : kernel_input_selector_counter) { main_trace.at(selector).lookup_into_kernel_counts = FF(count); } - // for (uint32_t i = 0; i < KERNEL_INPUTS_LENGTH; i++) { - // auto value = kernel_input_selector_counter.find(i); - // if (value != kernel_input_selector_counter.end()) { - // auto& dest = main_trace.at(i); - // dest.lookup_into_kernel_counts = FF(value->second); - // } - // } // Write lookup counts for outputs for (auto const& [selector, count] : kernel_output_selector_counter) { main_trace.at(selector).kernel_output_lookup_counts = FF(count); } - // for (uint32_t i = 0; i < KERNEL_OUTPUTS_LENGTH; i++) { - // auto value = kernel_output_selector_counter.find(i); - // if (value != kernel_output_selector_counter.end()) { - // auto& dest = main_trace.at(i); - // dest.kernel_output_lookup_counts = FF(value->second); - // } - // } } } // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.hpp index bea60ff400a..49979bca3cd 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.hpp @@ -27,6 +27,7 @@ class AvmKernelTraceBuilder { TIMESTAMP, FEE_PER_DA_GAS, FEE_PER_L2_GAS, + IS_STATIC_CALL, // OUT SLOAD, SSTORE, @@ -73,6 +74,7 @@ class AvmKernelTraceBuilder { FF op_sender(uint32_t clk); FF op_function_selector(uint32_t clk); FF op_transaction_fee(uint32_t clk); + FF op_is_static_call(uint32_t clk); // Globals FF op_chain_id(uint32_t clk); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp index d3af5d62f2b..a2e194027e5 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp @@ -1390,19 +1390,17 @@ void AvmTraceBuilder::op_transaction_fee(uint8_t indirect, uint32_t dst_offset) main_trace.push_back(row); } -void AvmTraceBuilder::op_is_static_call([[maybe_unused]] uint8_t indirect, [[maybe_unused]] uint32_t dst_offset) +void AvmTraceBuilder::op_is_static_call(uint8_t indirect, uint32_t dst_offset) { - // TO BE IMPLEMENTED. - op_mov(0, 0, 0); - // auto const clk = static_cast(main_trace.size()) + 1; - // FF ia_value = kernel_trace_builder.op_is_static_call(clk); - // Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::U1); - // row.main_sel_op_is_static_call = FF(1); + auto const clk = static_cast(main_trace.size()) + 1; + FF ia_value = kernel_trace_builder.op_is_static_call(clk); + Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::U1); + row.main_sel_op_is_static_call = FF(1); - // // Constrain gas cost - // gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::GETENVVAR_16); + // Constrain gas cost + gas_trace_builder.constrain_gas(static_cast(row.main_clk), OpCode::GETENVVAR_16); - // main_trace.push_back(row); + main_trace.push_back(row); } /************************************************************************************************** diff --git a/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp b/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp index 2ea4a0fc96f..784353a8776 100644 --- a/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp @@ -34,7 +34,7 @@ #define PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH 691 #define PUBLIC_CONTEXT_INPUTS_LENGTH 42 #define AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS 66 -#define AVM_PROOF_LENGTH_IN_FIELDS 3817 +#define AVM_PROOF_LENGTH_IN_FIELDS 3822 #define AVM_PUBLIC_COLUMN_MAX_SIZE_LOG2 8 #define MEM_TAG_U1 1 #define MEM_TAG_U8 2 @@ -47,6 +47,7 @@ #define ADDRESS_SELECTOR 1 #define STORAGE_ADDRESS_SELECTOR 1 #define FUNCTION_SELECTOR_SELECTOR 2 +#define IS_STATIC_CALL_SELECTOR 4 #define START_GLOBAL_VARIABLES 29 #define CHAIN_ID_SELECTOR 29 #define VERSION_SELECTOR 30 diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index de90972406b..d2f8d7ada13 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -228,6 +228,7 @@ library Constants { uint256 internal constant ADDRESS_SELECTOR = 1; uint256 internal constant STORAGE_ADDRESS_SELECTOR = 1; uint256 internal constant FUNCTION_SELECTOR_SELECTOR = 2; + uint256 internal constant IS_STATIC_CALL_SELECTOR = 4; uint256 internal constant START_GLOBAL_VARIABLES = 29; uint256 internal constant CHAIN_ID_SELECTOR = 29; uint256 internal constant VERSION_SELECTOR = 30; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 16482b83c9c..bc68ac6eb31 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -294,7 +294,7 @@ global AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS: u32 = 2 + 16 * 4; // `AVM_PROOF_LENGTH_IN_FIELDS` must be updated when AVM circuit changes. // To determine latest value, hover `COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS` // in barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp -global AVM_PROOF_LENGTH_IN_FIELDS: u32 = 3817; +global AVM_PROOF_LENGTH_IN_FIELDS: u32 = 3822; global AVM_PUBLIC_COLUMN_MAX_SIZE_LOG2 = 8; /** * Enumerate the hash_indices which are used for pedersen hashing. @@ -379,6 +379,7 @@ global SENDER_SELECTOR: u32 = 0; global ADDRESS_SELECTOR: u32 = SENDER_SELECTOR + 1; global STORAGE_ADDRESS_SELECTOR: u32 = ADDRESS_SELECTOR; global FUNCTION_SELECTOR_SELECTOR: u32 = ADDRESS_SELECTOR + 1; +global IS_STATIC_CALL_SELECTOR: u32 = FUNCTION_SELECTOR_SELECTOR + 2; // Global Variables global START_GLOBAL_VARIABLES: u32 = CALL_CONTEXT_LENGTH + HEADER_LENGTH; global CHAIN_ID_SELECTOR: u32 = START_GLOBAL_VARIABLES; diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 484513c7d17..2dd38b812f2 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -200,7 +200,7 @@ export const NESTED_RECURSIVE_PROOF_LENGTH = 439; export const TUBE_PROOF_LENGTH = 439; export const VERIFICATION_KEY_LENGTH_IN_FIELDS = 128; export const AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS = 66; -export const AVM_PROOF_LENGTH_IN_FIELDS = 3817; +export const AVM_PROOF_LENGTH_IN_FIELDS = 3822; export const AVM_PUBLIC_COLUMN_MAX_SIZE_LOG2 = 8; export const MEM_TAG_U1 = 1; export const MEM_TAG_U8 = 2; @@ -213,6 +213,7 @@ export const SENDER_SELECTOR = 0; export const ADDRESS_SELECTOR = 1; export const STORAGE_ADDRESS_SELECTOR = 1; export const FUNCTION_SELECTOR_SELECTOR = 2; +export const IS_STATIC_CALL_SELECTOR = 4; export const START_GLOBAL_VARIABLES = 29; export const CHAIN_ID_SELECTOR = 29; export const VERSION_SELECTOR = 30; diff --git a/yarn-project/circuits.js/src/scripts/constants.in.ts b/yarn-project/circuits.js/src/scripts/constants.in.ts index 6a2a04e95e3..07728f51e65 100644 --- a/yarn-project/circuits.js/src/scripts/constants.in.ts +++ b/yarn-project/circuits.js/src/scripts/constants.in.ts @@ -66,6 +66,7 @@ const CPP_CONSTANTS = [ 'TIMESTAMP_SELECTOR', 'FEE_PER_DA_GAS_SELECTOR', 'FEE_PER_L2_GAS_SELECTOR', + 'IS_STATIC_CALL_SELECTOR', 'END_GLOBAL_VARIABLES', 'START_SIDE_EFFECT_COUNTER', 'TRANSACTION_FEE_SELECTOR', @@ -111,6 +112,7 @@ const PIL_CONSTANTS = [ 'TIMESTAMP_SELECTOR', 'FEE_PER_DA_GAS_SELECTOR', 'FEE_PER_L2_GAS_SELECTOR', + 'IS_STATIC_CALL_SELECTOR', 'END_GLOBAL_VARIABLES', 'START_SIDE_EFFECT_COUNTER', 'TRANSACTION_FEE_SELECTOR', From f368cd2bff563af74af0cec81354b6d718f1db34 Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Mon, 23 Sep 2024 11:19:25 +0000 Subject: [PATCH 4/9] executor tests --- barretenberg/cpp/pil/avm/kernel.pil | 2 +- .../vm/avm/generated/relations/kernel.hpp | 21 +- .../vm/avm/generated/relations/main.hpp | 21 +- .../vm/avm/tests/execution.test.cpp | 381 ++++++++++-------- .../barretenberg/vm/avm/trace/execution.cpp | 2 + .../src/barretenberg/vm/avm/trace/opcode.hpp | 19 + .../src/barretenberg/vm/avm/trace/trace.hpp | 18 - 7 files changed, 268 insertions(+), 196 deletions(-) diff --git a/barretenberg/cpp/pil/avm/kernel.pil b/barretenberg/cpp/pil/avm/kernel.pil index bdd555426fb..df94d750dac 100644 --- a/barretenberg/cpp/pil/avm/kernel.pil +++ b/barretenberg/cpp/pil/avm/kernel.pil @@ -171,7 +171,7 @@ namespace main(256); pol KERNEL_INPUT_SELECTORS = sel_op_address + sel_op_storage_address + sel_op_sender + sel_op_function_selector + sel_op_transaction_fee + sel_op_chain_id + sel_op_version + sel_op_block_number + sel_op_timestamp - + sel_op_fee_per_l2_gas + sel_op_fee_per_da_gas; + + sel_op_fee_per_l2_gas + sel_op_fee_per_da_gas + sel_op_is_static_call; // Ensure that only one kernel lookup is active when the kernel_in_offset is active #[KERNEL_INPUT_ACTIVE_CHECK] KERNEL_INPUT_SELECTORS * (1 - sel_q_kernel_lookup) = 0; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp index 68eb712f40b..eefe05d9e71 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp @@ -43,16 +43,17 @@ template class kernelImpl { const auto constants_START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET = FF(160); const auto constants_START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET = FF(162); const auto main_KERNEL_INPUT_SELECTORS = - ((((((((((new_term.main_sel_op_address + new_term.main_sel_op_storage_address) + - new_term.main_sel_op_sender) + - new_term.main_sel_op_function_selector) + - new_term.main_sel_op_transaction_fee) + - new_term.main_sel_op_chain_id) + - new_term.main_sel_op_version) + - new_term.main_sel_op_block_number) + - new_term.main_sel_op_timestamp) + - new_term.main_sel_op_fee_per_l2_gas) + - new_term.main_sel_op_fee_per_da_gas); + (((((((((((new_term.main_sel_op_address + new_term.main_sel_op_storage_address) + + new_term.main_sel_op_sender) + + new_term.main_sel_op_function_selector) + + new_term.main_sel_op_transaction_fee) + + new_term.main_sel_op_chain_id) + + new_term.main_sel_op_version) + + new_term.main_sel_op_block_number) + + new_term.main_sel_op_timestamp) + + new_term.main_sel_op_fee_per_l2_gas) + + new_term.main_sel_op_fee_per_da_gas) + + new_term.main_sel_op_is_static_call); const auto main_KERNEL_OUTPUT_SELECTORS = ((((((((new_term.main_sel_op_note_hash_exists + new_term.main_sel_op_emit_note_hash) + new_term.main_sel_op_nullifier_exists) + diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp index f985dcc30ae..a10bb223f4e 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/main.hpp @@ -27,16 +27,17 @@ template class mainImpl { const auto constants_MEM_TAG_FF = FF(7); const auto constants_misc_INTERNAL_CALL_SPACE_ID = FF(255); const auto main_KERNEL_INPUT_SELECTORS = - ((((((((((new_term.main_sel_op_address + new_term.main_sel_op_storage_address) + - new_term.main_sel_op_sender) + - new_term.main_sel_op_function_selector) + - new_term.main_sel_op_transaction_fee) + - new_term.main_sel_op_chain_id) + - new_term.main_sel_op_version) + - new_term.main_sel_op_block_number) + - new_term.main_sel_op_timestamp) + - new_term.main_sel_op_fee_per_l2_gas) + - new_term.main_sel_op_fee_per_da_gas); + (((((((((((new_term.main_sel_op_address + new_term.main_sel_op_storage_address) + + new_term.main_sel_op_sender) + + new_term.main_sel_op_function_selector) + + new_term.main_sel_op_transaction_fee) + + new_term.main_sel_op_chain_id) + + new_term.main_sel_op_version) + + new_term.main_sel_op_block_number) + + new_term.main_sel_op_timestamp) + + new_term.main_sel_op_fee_per_l2_gas) + + new_term.main_sel_op_fee_per_da_gas) + + new_term.main_sel_op_is_static_call); const auto main_KERNEL_OUTPUT_SELECTORS = ((((((((new_term.main_sel_op_note_hash_exists + new_term.main_sel_op_emit_note_hash) + new_term.main_sel_op_nullifier_exists) + diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp index 4e13ea0e508..52f69a41e02 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp @@ -110,7 +110,7 @@ TEST_F(AvmExecutionTests, basicAddReturn) EXPECT_THAT(instructions.at(1), AllOf(Field(&Instruction::op_code, OpCode::RETURN), Field(&Instruction::operands, - ElementsAre(VariantWith(0), VariantWith(0), VariantWith(0))))); + ElementsAre(VariantWith(0), VariantWith(0), VariantWith(0))))); auto trace = gen_trace_from_instr(instructions); validate_trace(std::move(trace), public_inputs, {}, {}); @@ -247,7 +247,7 @@ TEST_F(AvmExecutionTests, powerWithMulOpcodes) EXPECT_THAT(instructions.at(14), AllOf(Field(&Instruction::op_code, OpCode::RETURN), Field(&Instruction::operands, - ElementsAre(VariantWith(0), VariantWith(0), VariantWith(0))))); + ElementsAre(VariantWith(0), VariantWith(0), VariantWith(0))))); auto trace = gen_trace_from_instr(instructions); @@ -305,7 +305,7 @@ TEST_F(AvmExecutionTests, simpleInternalCall) // INTERNALCALL EXPECT_THAT(instructions.at(1), AllOf(Field(&Instruction::op_code, OpCode::INTERNALCALL), - Field(&Instruction::operands, ElementsAre(VariantWith(4))))); + Field(&Instruction::operands, ElementsAre(VariantWith(4))))); // INTERNALRETURN EXPECT_EQ(instructions.at(5).op_code, OpCode::INTERNALRETURN); @@ -458,9 +458,9 @@ TEST_F(AvmExecutionTests, jumpAndCalldatacopy) AllOf(Field(&Instruction::op_code, OpCode::CALLDATACOPY), Field(&Instruction::operands, ElementsAre(VariantWith(0), - VariantWith(0), - VariantWith(1), - VariantWith(10))))); + VariantWith(0), + VariantWith(1), + VariantWith(10))))); // JUMP EXPECT_THAT(instructions.at(3), @@ -667,10 +667,10 @@ TEST_F(AvmExecutionTests, cmovOpcode) AllOf(Field(&Instruction::op_code, OpCode::CMOV), Field(&Instruction::operands, ElementsAre(VariantWith(0), - VariantWith(16), - VariantWith(17), - VariantWith(32), - VariantWith(18))))); + VariantWith(16), + VariantWith(17), + VariantWith(32), + VariantWith(18))))); auto trace = gen_trace_from_instr(instructions); @@ -1456,106 +1456,164 @@ TEST_F(AvmExecutionTests, pedersenCommitmentOpcode) // Positive test for Kernel Input opcodes TEST_F(AvmExecutionTests, kernelInputOpcodes) { - std::string bytecode_hex = to_hex(OpCode::ADDRESS) + // opcode ADDRESS - "00" // Indirect flag - "00000001" // dst_offset - + to_hex(OpCode::STORAGEADDRESS) + // opcode STORAGEADDRESS - "00" // Indirect flag - "00000002" // dst_offset - + to_hex(OpCode::SENDER) + // opcode SENDER - "00" // Indirect flag - "00000003" // dst_offset - + to_hex(OpCode::FUNCTIONSELECTOR) + // opcode TRANSACTIONFEE - "00" // Indirect flag - "00000004" // dst_offset - + to_hex(OpCode::TRANSACTIONFEE) + // opcode TRANSACTIONFEE - "00" // Indirect flag - "00000005" // dst_offset - + to_hex(OpCode::CHAINID) + // opcode CHAINID - "00" // Indirect flag - "00000006" // dst_offset - + to_hex(OpCode::VERSION) + // opcode VERSION - "00" // Indirect flag - "00000007" // dst_offset - + to_hex(OpCode::BLOCKNUMBER) + // opcode BLOCKNUMBER - "00" // Indirect flag - "00000008" // dst_offset - + to_hex(OpCode::TIMESTAMP) + // opcode TIMESTAMP - "00" // Indirect flag - "00000009" // dst_offset - + to_hex(OpCode::FEEPERL2GAS) + // opcode FEEPERL2GAS - "00" // Indirect flag - "0000000a" // dst_offset - + to_hex(OpCode::FEEPERDAGAS) + // opcode FEEPERDAGAS - "00" // Indirect flag - "0000000b" // dst_offset - + to_hex(OpCode::RETURN) + // opcode RETURN - "00" // Indirect flag - "00000001" // ret offset 1 - "0000000b"; // ret size 11 + std::string bytecode_hex = + to_hex(OpCode::GETENVVAR_16) + // opcode ADDRESS + "00" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::ADDRESS)) + // envvar ADDRESS + "0001" // dst_offset + + to_hex(OpCode::GETENVVAR_16) + // opcode STORAGEADDRESS + "00" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::STORAGEADDRESS)) + // envvar STORAGEADDRESS + "0002" // dst_offset + + to_hex(OpCode::GETENVVAR_16) + // opcode SENDER + "00" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::SENDER)) + // envvar SENDER + "0003" // dst_offset + + to_hex(OpCode::GETENVVAR_16) + // opcode FUNCTIONSELECTOR + "00" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::FUNCTIONSELECTOR)) + // envvar FUNCTIONSELECTOR + "0004" // dst_offset + + to_hex(OpCode::GETENVVAR_16) + // opcode TRANSACTIONFEE + "00" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::TRANSACTIONFEE)) + // envvar TRANSACTIONFEE + "0005" // dst_offset + + to_hex(OpCode::GETENVVAR_16) + // opcode CHAINID + "00" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::CHAINID)) + // envvar CHAINID + "0006" // dst_offset + + to_hex(OpCode::GETENVVAR_16) + // opcode VERSION + "00" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::VERSION)) + // envvar VERSION + "0007" // dst_offset + + to_hex(OpCode::GETENVVAR_16) + // opcode BLOCKNUMBER + "00" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::BLOCKNUMBER)) + // envvar BLOCKNUMBER + "0008" // dst_offset + + to_hex(OpCode::GETENVVAR_16) + // opcode TIMESTAMP + "00" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::TIMESTAMP)) + // envvar TIMESTAMP + "0009" // dst_offset + + to_hex(OpCode::GETENVVAR_16) + // opcode FEEPERL2GAS + "00" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::FEEPERL2GAS)) + // envvar FEEPERL2GAS + "000A" // dst_offset + + to_hex(OpCode::GETENVVAR_16) + // opcode FEEPERDAGAS + "00" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::FEEPERDAGAS)) + // envvar FEEPERDAGAS + "000B" // dst_offset + + to_hex(OpCode::GETENVVAR_16) + // opcode FEEPERDAGAS + "00" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::ISSTATICCALL)) + // envvar FEEPERDAGAS + "000C" // dst_offset + + to_hex(OpCode::RETURN) + // opcode RETURN + "00" // Indirect flag + "00000001" // ret offset 1 + "0000000C"; // ret size 12 auto bytecode = hex_to_bytes(bytecode_hex); auto instructions = Deserialization::parse(bytecode); - ASSERT_THAT(instructions, SizeIs(12)); + ASSERT_THAT(instructions, SizeIs(13)); // ADDRESS EXPECT_THAT(instructions.at(0), - AllOf(Field(&Instruction::op_code, OpCode::ADDRESS), - Field(&Instruction::operands, ElementsAre(VariantWith(0), VariantWith(1))))); + AllOf(Field(&Instruction::op_code, OpCode::GETENVVAR_16), + Field(&Instruction::operands, + ElementsAre(VariantWith(0), + VariantWith(static_cast(EnvironmentVariable::ADDRESS)), + VariantWith(1))))); // STORAGEADDRESS EXPECT_THAT(instructions.at(1), - AllOf(Field(&Instruction::op_code, OpCode::STORAGEADDRESS), - Field(&Instruction::operands, ElementsAre(VariantWith(0), VariantWith(2))))); + AllOf(Field(&Instruction::op_code, OpCode::GETENVVAR_16), + Field(&Instruction::operands, + ElementsAre(VariantWith(0), + VariantWith(static_cast(EnvironmentVariable::STORAGEADDRESS)), + VariantWith(2))))); // SENDER EXPECT_THAT(instructions.at(2), - AllOf(Field(&Instruction::op_code, OpCode::SENDER), - Field(&Instruction::operands, ElementsAre(VariantWith(0), VariantWith(3))))); + AllOf(Field(&Instruction::op_code, OpCode::GETENVVAR_16), + Field(&Instruction::operands, + ElementsAre(VariantWith(0), + VariantWith(static_cast(EnvironmentVariable::SENDER)), + VariantWith(3))))); // FUNCTIONSELECTOR - EXPECT_THAT(instructions.at(3), - AllOf(Field(&Instruction::op_code, OpCode::FUNCTIONSELECTOR), - Field(&Instruction::operands, ElementsAre(VariantWith(0), VariantWith(4))))); + EXPECT_THAT( + instructions.at(3), + AllOf(Field(&Instruction::op_code, OpCode::GETENVVAR_16), + Field(&Instruction::operands, + ElementsAre(VariantWith(0), + VariantWith(static_cast(EnvironmentVariable::FUNCTIONSELECTOR)), + VariantWith(4))))); // TRANSACTIONFEE EXPECT_THAT(instructions.at(4), - AllOf(Field(&Instruction::op_code, OpCode::TRANSACTIONFEE), - Field(&Instruction::operands, ElementsAre(VariantWith(0), VariantWith(5))))); + AllOf(Field(&Instruction::op_code, OpCode::GETENVVAR_16), + Field(&Instruction::operands, + ElementsAre(VariantWith(0), + VariantWith(static_cast(EnvironmentVariable::TRANSACTIONFEE)), + VariantWith(5))))); // CHAINID EXPECT_THAT(instructions.at(5), - AllOf(Field(&Instruction::op_code, OpCode::CHAINID), - Field(&Instruction::operands, ElementsAre(VariantWith(0), VariantWith(6))))); + AllOf(Field(&Instruction::op_code, OpCode::GETENVVAR_16), + Field(&Instruction::operands, + ElementsAre(VariantWith(0), + VariantWith(static_cast(EnvironmentVariable::CHAINID)), + VariantWith(6))))); // VERSION EXPECT_THAT(instructions.at(6), - AllOf(Field(&Instruction::op_code, OpCode::VERSION), - Field(&Instruction::operands, ElementsAre(VariantWith(0), VariantWith(7))))); + AllOf(Field(&Instruction::op_code, OpCode::GETENVVAR_16), + Field(&Instruction::operands, + ElementsAre(VariantWith(0), + VariantWith(static_cast(EnvironmentVariable::VERSION)), + VariantWith(7))))); // BLOCKNUMBER EXPECT_THAT(instructions.at(7), - AllOf(Field(&Instruction::op_code, OpCode::BLOCKNUMBER), - Field(&Instruction::operands, ElementsAre(VariantWith(0), VariantWith(8))))); + AllOf(Field(&Instruction::op_code, OpCode::GETENVVAR_16), + Field(&Instruction::operands, + ElementsAre(VariantWith(0), + VariantWith(static_cast(EnvironmentVariable::BLOCKNUMBER)), + VariantWith(8))))); // TIMESTAMP EXPECT_THAT(instructions.at(8), - AllOf(Field(&Instruction::op_code, OpCode::TIMESTAMP), - Field(&Instruction::operands, ElementsAre(VariantWith(0), VariantWith(9))))); + AllOf(Field(&Instruction::op_code, OpCode::GETENVVAR_16), + Field(&Instruction::operands, + ElementsAre(VariantWith(0), + VariantWith(static_cast(EnvironmentVariable::TIMESTAMP)), + VariantWith(9))))); // FEEPERL2GAS EXPECT_THAT(instructions.at(9), - AllOf(Field(&Instruction::op_code, OpCode::FEEPERL2GAS), - Field(&Instruction::operands, ElementsAre(VariantWith(0), VariantWith(10))))); + AllOf(Field(&Instruction::op_code, OpCode::GETENVVAR_16), + Field(&Instruction::operands, + ElementsAre(VariantWith(0), + VariantWith(static_cast(EnvironmentVariable::FEEPERL2GAS)), + VariantWith(10))))); // FEEPERDAGAS EXPECT_THAT(instructions.at(10), - AllOf(Field(&Instruction::op_code, OpCode::FEEPERDAGAS), - Field(&Instruction::operands, ElementsAre(VariantWith(0), VariantWith(11))))); + AllOf(Field(&Instruction::op_code, OpCode::GETENVVAR_16), + Field(&Instruction::operands, + ElementsAre(VariantWith(0), + VariantWith(static_cast(EnvironmentVariable::FEEPERDAGAS)), + VariantWith(11))))); + + // ISSTATICCALL + EXPECT_THAT(instructions.at(11), + AllOf(Field(&Instruction::op_code, OpCode::GETENVVAR_16), + Field(&Instruction::operands, + ElementsAre(VariantWith(0), + VariantWith(static_cast(EnvironmentVariable::ISSTATICCALL)), + VariantWith(12))))); // Public inputs for the circuit - std::vector calldata = {}; + std::vector calldata; FF sender = 1; FF address = 2; @@ -1570,12 +1628,13 @@ TEST_F(AvmExecutionTests, kernelInputOpcodes) FF timestamp = 9; FF feeperl2gas = 10; FF feeperdagas = 11; + FF is_static_call = 12; // The return data for this test should be a the opcodes in sequence, as the opcodes dst address lines up with // this array The returndata call above will then return this array std::vector const expected_returndata = { address, storage_address, sender, function_selector, transaction_fee, chainid, - version, blocknumber, timestamp, feeperl2gas, feeperdagas, + version, blocknumber, timestamp, feeperl2gas, feeperdagas, is_static_call, }; // Set up public inputs to contain the above values @@ -1587,6 +1646,7 @@ TEST_F(AvmExecutionTests, kernelInputOpcodes) public_inputs_vec[SENDER_SELECTOR] = sender; public_inputs_vec[FUNCTION_SELECTOR_SELECTOR] = function_selector; public_inputs_vec[TRANSACTION_FEE_OFFSET] = transaction_fee; + public_inputs_vec[IS_STATIC_CALL_SELECTOR] = is_static_call; // Global variables public_inputs_vec[CHAIN_ID_OFFSET] = chainid; @@ -1658,98 +1718,105 @@ TEST_F(AvmExecutionTests, kernelInputOpcodes) std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fee_per_l2_gas == 1; }); EXPECT_EQ(feeperl2gas_row->main_ia, feeperl2gas); + // Check is_static_call + auto is_static_call_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_is_static_call == 1; }); + EXPECT_EQ(is_static_call_row->main_ia, is_static_call); + validate_trace(std::move(trace), Execution::convert_public_inputs(public_inputs_vec), calldata, returndata); } // Positive test for L2GASLEFT opcode -TEST_F(AvmExecutionTests, l2GasLeft) -{ - std::string bytecode_hex = to_hex(OpCode::SET_16) + // opcode SET - "00" // Indirect flag - + to_hex(AvmMemoryTag::U32) + - "0101" // val 257 - "0011" // dst_offset 17 - + to_hex(OpCode::L2GASLEFT) + // opcode L2GASLEFT - "01" // Indirect flag - "00000011" // dst_offset (indirect addr: 17) - + to_hex(OpCode::RETURN) + // opcode RETURN - "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 - - auto bytecode = hex_to_bytes(bytecode_hex); - auto instructions = Deserialization::parse(bytecode); - - ASSERT_THAT(instructions, SizeIs(3)); - - // L2GASLEFT - EXPECT_THAT(instructions.at(1), - AllOf(Field(&Instruction::op_code, OpCode::L2GASLEFT), - Field(&Instruction::operands, ElementsAre(VariantWith(1), VariantWith(17))))); - - auto trace = gen_trace_from_instr(instructions); - - // Find the first row enabling the L2GASLEFT selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_l2gasleft == 1; }); - - uint32_t expected_rem_gas = DEFAULT_INITIAL_L2_GAS - - static_cast(GAS_COST_TABLE.at(OpCode::SET_8).base_l2_gas_fixed_table) - - static_cast(GAS_COST_TABLE.at(OpCode::L2GASLEFT).base_l2_gas_fixed_table); - - EXPECT_EQ(row->main_ia, expected_rem_gas); - EXPECT_EQ(row->main_mem_addr_a, 257); // Resolved direct address: 257 - - validate_trace(std::move(trace), public_inputs); -} - -// Positive test for DAGASLEFT opcode -TEST_F(AvmExecutionTests, daGasLeft) -{ - std::string bytecode_hex = to_hex(OpCode::ADD_16) + // opcode ADD - "00" // Indirect flag - + to_hex(AvmMemoryTag::U32) + - "0007" // addr a 7 - "0009" // addr b 9 - "0001" // addr c 1 - + to_hex(OpCode::DAGASLEFT) + // opcode DAGASLEFT - "00" // Indirect flag - "00000027" // dst_offset 39 - + to_hex(OpCode::RETURN) + // opcode RETURN - "00" // Indirect flag - "00000000" // ret offset 0 - "00000000"; // ret size 0 - - auto bytecode = hex_to_bytes(bytecode_hex); - auto instructions = Deserialization::parse(bytecode); - - ASSERT_THAT(instructions, SizeIs(3)); - - // DAGASLEFT - EXPECT_THAT(instructions.at(1), - AllOf(Field(&Instruction::op_code, OpCode::DAGASLEFT), - Field(&Instruction::operands, ElementsAre(VariantWith(0), VariantWith(39))))); - - auto trace = gen_trace_from_instr(instructions); - - // Find the first row enabling the DAGASLEFT selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_dagasleft == 1; }); - - uint32_t expected_rem_gas = DEFAULT_INITIAL_DA_GAS - - static_cast(GAS_COST_TABLE.at(OpCode::ADD_8).base_da_gas_fixed_table) - - static_cast(GAS_COST_TABLE.at(OpCode::DAGASLEFT).base_da_gas_fixed_table); - - EXPECT_EQ(row->main_ia, expected_rem_gas); - EXPECT_EQ(row->main_mem_addr_a, 39); - - validate_trace(std::move(trace), public_inputs); -} +// TEST_F(AvmExecutionTests, l2GasLeft) +// { +// std::string bytecode_hex = to_hex(OpCode::SET_16) + // opcode SET +// "00" // Indirect flag +// + to_hex(AvmMemoryTag::U32) + +// "0101" // val 257 +// "0011" // dst_offset 17 +// + to_hex(OpCode::L2GASLEFT) + // opcode L2GASLEFT +// "01" // Indirect flag +// "00000011" // dst_offset (indirect addr: 17) +// + to_hex(OpCode::RETURN) + // opcode RETURN +// "00" // Indirect flag +// "00000000" // ret offset 0 +// "00000000"; // ret size 0 + +// auto bytecode = hex_to_bytes(bytecode_hex); +// auto instructions = Deserialization::parse(bytecode); + +// ASSERT_THAT(instructions, SizeIs(3)); + +// // L2GASLEFT +// EXPECT_THAT(instructions.at(1), +// AllOf(Field(&Instruction::op_code, OpCode::L2GASLEFT), +// Field(&Instruction::operands, ElementsAre(VariantWith(1), +// VariantWith(17))))); + +// auto trace = gen_trace_from_instr(instructions); + +// // Find the first row enabling the L2GASLEFT selector +// auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_l2gasleft == 1; }); + +// uint32_t expected_rem_gas = DEFAULT_INITIAL_L2_GAS - +// static_cast(GAS_COST_TABLE.at(OpCode::SET_8).base_l2_gas_fixed_table) - +// static_cast(GAS_COST_TABLE.at(OpCode::L2GASLEFT).base_l2_gas_fixed_table); + +// EXPECT_EQ(row->main_ia, expected_rem_gas); +// EXPECT_EQ(row->main_mem_addr_a, 257); // Resolved direct address: 257 + +// validate_trace(std::move(trace), public_inputs); +// } + +// // Positive test for DAGASLEFT opcode +// TEST_F(AvmExecutionTests, daGasLeft) +// { +// std::string bytecode_hex = to_hex(OpCode::ADD_16) + // opcode ADD +// "00" // Indirect flag +// + to_hex(AvmMemoryTag::U32) + +// "0007" // addr a 7 +// "0009" // addr b 9 +// "0001" // addr c 1 +// + to_hex(OpCode::DAGASLEFT) + // opcode DAGASLEFT +// "00" // Indirect flag +// "00000027" // dst_offset 39 +// + to_hex(OpCode::RETURN) + // opcode RETURN +// "00" // Indirect flag +// "00000000" // ret offset 0 +// "00000000"; // ret size 0 + +// auto bytecode = hex_to_bytes(bytecode_hex); +// auto instructions = Deserialization::parse(bytecode); + +// ASSERT_THAT(instructions, SizeIs(3)); + +// // DAGASLEFT +// EXPECT_THAT(instructions.at(1), +// AllOf(Field(&Instruction::op_code, OpCode::DAGASLEFT), +// Field(&Instruction::operands, ElementsAre(VariantWith(0), +// VariantWith(39))))); + +// auto trace = gen_trace_from_instr(instructions); + +// // Find the first row enabling the DAGASLEFT selector +// auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_dagasleft == 1; }); + +// uint32_t expected_rem_gas = DEFAULT_INITIAL_DA_GAS - +// static_cast(GAS_COST_TABLE.at(OpCode::ADD_8).base_da_gas_fixed_table) - +// static_cast(GAS_COST_TABLE.at(OpCode::DAGASLEFT).base_da_gas_fixed_table); + +// EXPECT_EQ(row->main_ia, expected_rem_gas); +// EXPECT_EQ(row->main_mem_addr_a, 39); + +// validate_trace(std::move(trace), public_inputs); +// } // Should throw whenever the wrong number of public inputs are provided TEST_F(AvmExecutionTests, ExecutorThrowsWithIncorrectNumberOfPublicInputs) { - std::string bytecode_hex = to_hex(OpCode::SENDER) + // opcode SENDER - "00" // Indirect flag - "00000007"; // addr 7 + std::string bytecode_hex = to_hex(OpCode::GETENVVAR_16) + // opcode SENDER + "00" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::SENDER)) + "0007"; // addr 7 std::vector calldata = {}; std::vector returndata = {}; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp index 7ce66021c96..ea713ac51be 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp @@ -14,6 +14,7 @@ #include "barretenberg/vm/avm/trace/kernel_trace.hpp" #include "barretenberg/vm/avm/trace/opcode.hpp" #include "barretenberg/vm/avm/trace/trace.hpp" +#include "barretenberg/vm/aztec_constants.hpp" #include "barretenberg/vm/constants.hpp" #include "barretenberg/vm/stats.hpp" @@ -262,6 +263,7 @@ VmPublicInputs Execution::convert_public_inputs(std::vector const& public_in // kernel_inputs[ADDRESS_SELECTOR] = public_inputs_vec[ADDRESS_SELECTOR]; // Address kernel_inputs[STORAGE_ADDRESS_SELECTOR] = public_inputs_vec[STORAGE_ADDRESS_SELECTOR]; // Storage Address kernel_inputs[FUNCTION_SELECTOR_SELECTOR] = public_inputs_vec[FUNCTION_SELECTOR_SELECTOR]; + kernel_inputs[IS_STATIC_CALL_SELECTOR] = public_inputs_vec[IS_STATIC_CALL_SELECTOR]; // PublicCircuitPublicInputs - GlobalVariables kernel_inputs[CHAIN_ID_SELECTOR] = public_inputs_vec[CHAIN_ID_OFFSET]; // Chain ID diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/opcode.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/opcode.hpp index 97dd50c033b..02e88167768 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/opcode.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/opcode.hpp @@ -115,6 +115,25 @@ enum class OpCode : uint8_t { LAST_OPCODE_SENTINEL, }; +enum class EnvironmentVariable { + ADDRESS, + STORAGEADDRESS, + SENDER, + FUNCTIONSELECTOR, + TRANSACTIONFEE, + CHAINID, + VERSION, + BLOCKNUMBER, + TIMESTAMP, + FEEPERL2GAS, + FEEPERDAGAS, + ISSTATICCALL, + L2GASLEFT, + DAGASLEFT, + // sentinel + MAX_ENV_VAR +}; + class Bytecode { public: static bool is_valid(uint8_t byte); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp index a28b336c454..a9a1ee74476 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp @@ -291,24 +291,6 @@ class AvmTraceBuilder { uint32_t success_offset, [[maybe_unused]] uint32_t function_selector_offset); - enum class EnvironmentVariable { - ADDRESS, - STORAGEADDRESS, - SENDER, - FUNCTIONSELECTOR, - TRANSACTIONFEE, - CHAINID, - VERSION, - BLOCKNUMBER, - TIMESTAMP, - FEEPERL2GAS, - FEEPERDAGAS, - ISSTATICCALL, - L2GASLEFT, - DAGASLEFT, - // sentinel - MAX_ENV_VAR - }; void execute_gasleft(EnvironmentVariable var, uint8_t indirect, uint32_t dst_offset); void finalise_mem_trace_lookup_counts(); From 8ab4440c1aa285467229310dd987efb6d4b9c540 Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Mon, 23 Sep 2024 13:27:19 +0000 Subject: [PATCH 5/9] fix tests --- .../barretenberg/vm/avm/tests/kernel.test.cpp | 137 +++++++++++------- .../src/barretenberg/vm/avm/trace/trace.cpp | 2 +- 2 files changed, 83 insertions(+), 56 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/tests/kernel.test.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/tests/kernel.test.cpp index 8d62d9040dc..611e08dc34c 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/tests/kernel.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/tests/kernel.test.cpp @@ -4,6 +4,7 @@ #include "barretenberg/vm/avm/trace/common.hpp" #include "barretenberg/vm/avm/trace/kernel_trace.hpp" #include "barretenberg/vm/avm/trace/trace.hpp" +#include "barretenberg/vm/aztec_constants.hpp" #include "barretenberg/vm/constants.hpp" #include "common.test.hpp" @@ -192,15 +193,15 @@ TEST_F(AvmKernelPositiveTests, kernelSender) uint32_t indirect_dst_offset = 69; // We test that the sender opcode is included at index 0 in the public inputs auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_sender(/*indirect*/ false, dst_offset); + trace_builder.op_sender(/*indirect*/ 0, dst_offset); }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set( - /*indirect*/ false, + /*indirect*/ 0, /*value*/ dst_offset, /*dst_offset*/ indirect_dst_offset, AvmMemoryTag::U32); - trace_builder.op_sender(/*indirect*/ true, indirect_dst_offset); + trace_builder.op_sender(/*indirect*/ 1, indirect_dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { @@ -226,15 +227,15 @@ TEST_F(AvmKernelPositiveTests, kernelAddress) uint32_t dst_offset = 42; uint32_t indirect_dst_offset = 69; auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_address(/*indirect*/ false, dst_offset); + trace_builder.op_address(/*indirect*/ 0, dst_offset); }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set( - /*indirect*/ false, + /*indirect*/ 0, /*value*/ dst_offset, /*dst_offset*/ indirect_dst_offset, AvmMemoryTag::U32); - trace_builder.op_address(/*indirect*/ true, indirect_dst_offset); + trace_builder.op_address(/*indirect*/ 1, indirect_dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { @@ -259,15 +260,15 @@ TEST_F(AvmKernelPositiveTests, kernelStorageAddress) uint32_t dst_offset = 42; uint32_t indirect_dst_offset = 69; auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_storage_address(/*indirect*/ false, dst_offset); + trace_builder.op_storage_address(/*indirect*/ 0, dst_offset); }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set( - /*indirect*/ false, + /*indirect*/ 0, /*value*/ dst_offset, /*dst_offset*/ indirect_dst_offset, AvmMemoryTag::U32); - trace_builder.op_storage_address(/*indirect*/ true, indirect_dst_offset); + trace_builder.op_storage_address(/*indirect*/ 1, indirect_dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { @@ -295,15 +296,15 @@ TEST_F(AvmKernelPositiveTests, kernelFunctionSelector) uint32_t indirect_dst_offset = 69; // We test that the function selector opcode is included at index 0 in the public inputs auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_function_selector(/*indirect*/ false, dst_offset); + trace_builder.op_function_selector(/*indirect*/ 0, dst_offset); }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set( - /*indirect*/ false, + /*indirect*/ 0, /*value*/ dst_offset, /*dst_offset*/ indirect_dst_offset, AvmMemoryTag::U32); - trace_builder.op_function_selector(/*indirect*/ true, indirect_dst_offset); + trace_builder.op_function_selector(/*indirect*/ 1, indirect_dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { @@ -329,15 +330,15 @@ TEST_F(AvmKernelPositiveTests, kernelFeePerDa) uint32_t dst_offset = 42; uint32_t indirect_dst_offset = 69; auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_fee_per_da_gas(/*indirect*/ false, dst_offset); + trace_builder.op_fee_per_da_gas(/*indirect*/ 0, dst_offset); }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set( - /*indirect*/ false, + /*indirect*/ 0, /*value*/ dst_offset, /*dst_offset*/ indirect_dst_offset, AvmMemoryTag::U32); - trace_builder.op_fee_per_da_gas(/*indirect*/ true, indirect_dst_offset); + trace_builder.op_fee_per_da_gas(/*indirect*/ 1, indirect_dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { @@ -363,15 +364,15 @@ TEST_F(AvmKernelPositiveTests, kernelFeePerL2) uint32_t dst_offset = 42; uint32_t indirect_dst_offset = 69; auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_fee_per_l2_gas(/*indirect*/ false, dst_offset); + trace_builder.op_fee_per_l2_gas(/*indirect*/ 0, dst_offset); }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set( - /*indirect*/ false, + /*indirect*/ 0, /*value*/ dst_offset, /*dst_offset*/ indirect_dst_offset, AvmMemoryTag::U32); - trace_builder.op_fee_per_l2_gas(/*indirect*/ true, indirect_dst_offset); + trace_builder.op_fee_per_l2_gas(/*indirect*/ 1, indirect_dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { @@ -397,15 +398,15 @@ TEST_F(AvmKernelPositiveTests, kernelTransactionFee) uint32_t dst_offset = 42; uint32_t indirect_dst_offset = 69; auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_transaction_fee(/*indirect*/ false, dst_offset); + trace_builder.op_transaction_fee(/*indirect*/ 0, dst_offset); }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set( - /*indirect*/ false, + /*indirect*/ 0, /*value*/ dst_offset, /*dst_offset*/ indirect_dst_offset, AvmMemoryTag::U32); - trace_builder.op_transaction_fee(/*indirect*/ true, indirect_dst_offset); + trace_builder.op_transaction_fee(/*indirect*/ 1, indirect_dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { @@ -426,20 +427,54 @@ TEST_F(AvmKernelPositiveTests, kernelTransactionFee) test_kernel_lookup(true, indirect_apply_opcodes, checks); } +TEST_F(AvmKernelPositiveTests, kernelIsStaticCall) +{ + uint32_t dst_offset = 42; + uint32_t indirect_dst_offset = 69; + auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { + trace_builder.op_is_static_call(/*indirect*/ 0, dst_offset); + }; + auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { + trace_builder.op_set( + /*indirect*/ 0, + /*value*/ dst_offset, + /*dst_offset*/ indirect_dst_offset, + AvmMemoryTag::U32); + trace_builder.op_is_static_call(/*indirect*/ 1, indirect_dst_offset); + }; + + auto checks = [=](bool indirect, const std::vector& trace) { + auto row = std::ranges::find_if( + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_is_static_call == FF(1); }); + EXPECT_TRUE(row != trace.end()); + + expect_row(row, + /*kernel_in_offset=*/IS_STATIC_CALL_SELECTOR, + /*ia=*/IS_STATIC_CALL_SELECTOR + + 1, // Note the value generated above for public inputs is the same as the index read + 1 + /*ind_a*/ indirect ? indirect_dst_offset : 0, + /*mem_addr_a=*/dst_offset, + /*w_in_tag=*/AvmMemoryTag::FF); + }; + + test_kernel_lookup(false, direct_apply_opcodes, checks); + test_kernel_lookup(true, indirect_apply_opcodes, checks); +} + TEST_F(AvmKernelPositiveTests, kernelChainId) { uint32_t dst_offset = 42; uint32_t indirect_dst_offset = 69; auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_chain_id(/*indirect*/ false, dst_offset); + trace_builder.op_chain_id(/*indirect*/ 0, dst_offset); }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set( - /*indirect*/ false, + /*indirect*/ 0, /*value*/ dst_offset, /*dst_offset*/ indirect_dst_offset, AvmMemoryTag::U32); - trace_builder.op_chain_id(/*indirect*/ true, indirect_dst_offset); + trace_builder.op_chain_id(/*indirect*/ 1, indirect_dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { @@ -465,15 +500,15 @@ TEST_F(AvmKernelPositiveTests, kernelVersion) uint32_t dst_offset = 42; uint32_t indirect_dst_offset = 69; auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_version(/*indirect*/ false, dst_offset); + trace_builder.op_version(/*indirect*/ 0, dst_offset); }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set( - /*indirect*/ false, + /*indirect*/ 0, /*value*/ dst_offset, /*dst_offset*/ indirect_dst_offset, AvmMemoryTag::U32); - trace_builder.op_version(/*indirect*/ true, indirect_dst_offset); + trace_builder.op_version(/*indirect*/ 1, indirect_dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { @@ -499,15 +534,15 @@ TEST_F(AvmKernelPositiveTests, kernelBlockNumber) uint32_t dst_offset = 42; uint32_t indirect_dst_offset = 69; auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_block_number(/*indirect*/ false, dst_offset); + trace_builder.op_block_number(/*indirect*/ 0, dst_offset); }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set( - /*indirect*/ false, + /*indirect*/ 0, /*value*/ dst_offset, /*dst_offset*/ indirect_dst_offset, AvmMemoryTag::U32); - trace_builder.op_block_number(/*indirect*/ true, indirect_dst_offset); + trace_builder.op_block_number(/*indirect*/ 1, indirect_dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { @@ -533,15 +568,15 @@ TEST_F(AvmKernelPositiveTests, kernelTimestamp) uint32_t dst_offset = 42; uint32_t indirect_dst_offset = 69; auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_timestamp(/*indirect*/ false, dst_offset); + trace_builder.op_timestamp(/*indirect*/ 0, dst_offset); }; auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set( - /*indirect*/ false, + /*indirect*/ 0, /*value*/ dst_offset, /*dst_offset*/ indirect_dst_offset, AvmMemoryTag::U32); - trace_builder.op_timestamp(/*indirect*/ true, indirect_dst_offset); + trace_builder.op_timestamp(/*indirect*/ 1, indirect_dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { @@ -592,7 +627,7 @@ void negative_test_incorrect_ia_kernel_lookup(OpcodesFunc apply_opcodes, // memory trace should only have one row for these tests as well, so first row has looked-up val ta.mem_val = incorrect_ia; - check_trace(/*indirect*/ false, trace); + check_trace(/*indirect*/ 0, trace); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), expected_message); } @@ -603,9 +638,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaSender) FF incorrect_ia = FF(69); // We test that the sender opcode is inlcuded at index x in the public inputs - auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_sender(/*indirect*/ false, dst_offset); - }; + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_sender(/*indirect*/ 0, dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sender == FF(1); }); @@ -629,9 +662,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaAddress) FF incorrect_ia = FF(69); // We test that the sender opcode is inlcuded at index x in the public inputs - auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_address(/*indirect*/ false, dst_offset); - }; + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_address(/*indirect*/ 0, dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_address == FF(1); }); @@ -656,7 +687,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaStorageAddress) // We test that the sender opcode is inlcuded at index x in the public inputs auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_storage_address(/*indirect*/ false, dst_offset); + trace_builder.op_storage_address(/*indirect*/ 0, dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( @@ -682,7 +713,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaFunctionSelector) // We test that the sender opcode is inlcuded at index x in the public inputs auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_function_selector(/*indirect*/ false, dst_offset); + trace_builder.op_function_selector(/*indirect*/ 0, dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( @@ -708,7 +739,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaDaGas) // We test that the sender opcode is inlcuded at index x in the public inputs auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_fee_per_da_gas(/*indirect*/ false, dst_offset); + trace_builder.op_fee_per_da_gas(/*indirect*/ 0, dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( @@ -734,7 +765,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIal2Gas) // We test that the sender opcode is inlcuded at index x in the public inputs auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_fee_per_l2_gas(/*indirect*/ false, dst_offset); + trace_builder.op_fee_per_l2_gas(/*indirect*/ 0, dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( @@ -760,7 +791,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaTransactionFee) // We test that the sender opcode is inlcuded at index x in the public inputs auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_transaction_fee(/*indirect*/ false, dst_offset); + trace_builder.op_transaction_fee(/*indirect*/ 0, dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( @@ -785,9 +816,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaChainId) FF incorrect_ia = FF(69); // We test that the sender opcode is inlcuded at index x in the public inputs - auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_chain_id(/*indirect*/ false, dst_offset); - }; + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_chain_id(/*indirect*/ 0, dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_chain_id == FF(1); }); @@ -811,9 +840,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaVersion) FF incorrect_ia = FF(69); // We test that the sender opcode is inlcuded at index x in the public inputs - auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_version(/*indirect*/ false, dst_offset); - }; + auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_version(/*indirect*/ 0, dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_version == FF(1); }); @@ -838,7 +865,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaBlockNumber) // We test that the sender opcode is inlcuded at index x in the public inputs auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_block_number(/*indirect*/ false, dst_offset); + trace_builder.op_block_number(/*indirect*/ 0, dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = @@ -864,7 +891,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaTimestamp) // We test that the sender opcode is inlcuded at index x in the public inputs auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { - trace_builder.op_timestamp(/*indirect*/ false, dst_offset); + trace_builder.op_timestamp(/*indirect*/ 0, dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = @@ -1171,7 +1198,7 @@ TEST_F(AvmKernelOutputPositiveTests, kernelNoteHashExists) auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, value, value_offset, AvmMemoryTag::FF); // TODO(#8287): Leaf index isnt constrained properly so we just set it to 0 - trace_builder.op_note_hash_exists(/*indirect*/ false, value_offset, 0, metadata_offset); + trace_builder.op_note_hash_exists(/*indirect*/ 0, value_offset, 0, metadata_offset); }; // TODO: fix auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { @@ -1299,7 +1326,7 @@ TEST_F(AvmKernelOutputPositiveTests, kernelL1ToL2MsgExists) auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, value, value_offset, AvmMemoryTag::FF); // TODO(#8287): Leaf index isnt constrained properly so we just set it to 0 - trace_builder.op_l1_to_l2_msg_exists(/*indirect*/ false, value_offset, 0, metadata_offset); + trace_builder.op_l1_to_l2_msg_exists(/*indirect*/ 0, value_offset, 0, metadata_offset); }; auto checks = [=]([[maybe_unused]] bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp index a2e194027e5..9256389d67f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp @@ -1394,7 +1394,7 @@ void AvmTraceBuilder::op_is_static_call(uint8_t indirect, uint32_t dst_offset) { auto const clk = static_cast(main_trace.size()) + 1; FF ia_value = kernel_trace_builder.op_is_static_call(clk); - Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::U1); + Row row = create_kernel_lookup_opcode(indirect, dst_offset, ia_value, AvmMemoryTag::FF); row.main_sel_op_is_static_call = FF(1); // Constrain gas cost From bd60241ad102decab6ad9c5aa443019eae1e1274 Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Mon, 23 Sep 2024 13:37:42 +0000 Subject: [PATCH 6/9] fix execution tests --- .../vm/avm/tests/execution.test.cpp | 192 +++++++++--------- 1 file changed, 99 insertions(+), 93 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp index 52f69a41e02..7a8c3cb6a36 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp @@ -110,7 +110,7 @@ TEST_F(AvmExecutionTests, basicAddReturn) EXPECT_THAT(instructions.at(1), AllOf(Field(&Instruction::op_code, OpCode::RETURN), Field(&Instruction::operands, - ElementsAre(VariantWith(0), VariantWith(0), VariantWith(0))))); + ElementsAre(VariantWith(0), VariantWith(0), VariantWith(0))))); auto trace = gen_trace_from_instr(instructions); validate_trace(std::move(trace), public_inputs, {}, {}); @@ -247,7 +247,7 @@ TEST_F(AvmExecutionTests, powerWithMulOpcodes) EXPECT_THAT(instructions.at(14), AllOf(Field(&Instruction::op_code, OpCode::RETURN), Field(&Instruction::operands, - ElementsAre(VariantWith(0), VariantWith(0), VariantWith(0))))); + ElementsAre(VariantWith(0), VariantWith(0), VariantWith(0))))); auto trace = gen_trace_from_instr(instructions); @@ -305,7 +305,7 @@ TEST_F(AvmExecutionTests, simpleInternalCall) // INTERNALCALL EXPECT_THAT(instructions.at(1), AllOf(Field(&Instruction::op_code, OpCode::INTERNALCALL), - Field(&Instruction::operands, ElementsAre(VariantWith(4))))); + Field(&Instruction::operands, ElementsAre(VariantWith(4))))); // INTERNALRETURN EXPECT_EQ(instructions.at(5).op_code, OpCode::INTERNALRETURN); @@ -458,9 +458,9 @@ TEST_F(AvmExecutionTests, jumpAndCalldatacopy) AllOf(Field(&Instruction::op_code, OpCode::CALLDATACOPY), Field(&Instruction::operands, ElementsAre(VariantWith(0), - VariantWith(0), - VariantWith(1), - VariantWith(10))))); + VariantWith(0), + VariantWith(1), + VariantWith(10))))); // JUMP EXPECT_THAT(instructions.at(3), @@ -667,10 +667,10 @@ TEST_F(AvmExecutionTests, cmovOpcode) AllOf(Field(&Instruction::op_code, OpCode::CMOV), Field(&Instruction::operands, ElementsAre(VariantWith(0), - VariantWith(16), - VariantWith(17), - VariantWith(32), - VariantWith(18))))); + VariantWith(16), + VariantWith(17), + VariantWith(32), + VariantWith(18))))); auto trace = gen_trace_from_instr(instructions); @@ -1727,89 +1727,95 @@ TEST_F(AvmExecutionTests, kernelInputOpcodes) } // Positive test for L2GASLEFT opcode -// TEST_F(AvmExecutionTests, l2GasLeft) -// { -// std::string bytecode_hex = to_hex(OpCode::SET_16) + // opcode SET -// "00" // Indirect flag -// + to_hex(AvmMemoryTag::U32) + -// "0101" // val 257 -// "0011" // dst_offset 17 -// + to_hex(OpCode::L2GASLEFT) + // opcode L2GASLEFT -// "01" // Indirect flag -// "00000011" // dst_offset (indirect addr: 17) -// + to_hex(OpCode::RETURN) + // opcode RETURN -// "00" // Indirect flag -// "00000000" // ret offset 0 -// "00000000"; // ret size 0 - -// auto bytecode = hex_to_bytes(bytecode_hex); -// auto instructions = Deserialization::parse(bytecode); - -// ASSERT_THAT(instructions, SizeIs(3)); - -// // L2GASLEFT -// EXPECT_THAT(instructions.at(1), -// AllOf(Field(&Instruction::op_code, OpCode::L2GASLEFT), -// Field(&Instruction::operands, ElementsAre(VariantWith(1), -// VariantWith(17))))); - -// auto trace = gen_trace_from_instr(instructions); - -// // Find the first row enabling the L2GASLEFT selector -// auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_l2gasleft == 1; }); - -// uint32_t expected_rem_gas = DEFAULT_INITIAL_L2_GAS - -// static_cast(GAS_COST_TABLE.at(OpCode::SET_8).base_l2_gas_fixed_table) - -// static_cast(GAS_COST_TABLE.at(OpCode::L2GASLEFT).base_l2_gas_fixed_table); - -// EXPECT_EQ(row->main_ia, expected_rem_gas); -// EXPECT_EQ(row->main_mem_addr_a, 257); // Resolved direct address: 257 - -// validate_trace(std::move(trace), public_inputs); -// } - -// // Positive test for DAGASLEFT opcode -// TEST_F(AvmExecutionTests, daGasLeft) -// { -// std::string bytecode_hex = to_hex(OpCode::ADD_16) + // opcode ADD -// "00" // Indirect flag -// + to_hex(AvmMemoryTag::U32) + -// "0007" // addr a 7 -// "0009" // addr b 9 -// "0001" // addr c 1 -// + to_hex(OpCode::DAGASLEFT) + // opcode DAGASLEFT -// "00" // Indirect flag -// "00000027" // dst_offset 39 -// + to_hex(OpCode::RETURN) + // opcode RETURN -// "00" // Indirect flag -// "00000000" // ret offset 0 -// "00000000"; // ret size 0 - -// auto bytecode = hex_to_bytes(bytecode_hex); -// auto instructions = Deserialization::parse(bytecode); - -// ASSERT_THAT(instructions, SizeIs(3)); - -// // DAGASLEFT -// EXPECT_THAT(instructions.at(1), -// AllOf(Field(&Instruction::op_code, OpCode::DAGASLEFT), -// Field(&Instruction::operands, ElementsAre(VariantWith(0), -// VariantWith(39))))); - -// auto trace = gen_trace_from_instr(instructions); - -// // Find the first row enabling the DAGASLEFT selector -// auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_dagasleft == 1; }); - -// uint32_t expected_rem_gas = DEFAULT_INITIAL_DA_GAS - -// static_cast(GAS_COST_TABLE.at(OpCode::ADD_8).base_da_gas_fixed_table) - -// static_cast(GAS_COST_TABLE.at(OpCode::DAGASLEFT).base_da_gas_fixed_table); - -// EXPECT_EQ(row->main_ia, expected_rem_gas); -// EXPECT_EQ(row->main_mem_addr_a, 39); - -// validate_trace(std::move(trace), public_inputs); -// } +TEST_F(AvmExecutionTests, l2GasLeft) +{ + std::string bytecode_hex = to_hex(OpCode::SET_16) + // opcode SET + "00" // Indirect flag + + to_hex(AvmMemoryTag::U32) + + "0101" // val 257 + "0011" // dst_offset 17 + + to_hex(OpCode::GETENVVAR_16) + // opcode L2GASLEFT + "01" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::L2GASLEFT)) + + "0011" // dst_offset (indirect addr: 17) + + to_hex(OpCode::RETURN) + // opcode RETURN + "00" // Indirect flag + "00000000" // ret offset 0 + "00000000"; // ret size 0 + + auto bytecode = hex_to_bytes(bytecode_hex); + auto instructions = Deserialization::parse(bytecode); + + ASSERT_THAT(instructions, SizeIs(3)); + + // L2GASLEFT + EXPECT_THAT(instructions.at(1), + AllOf(Field(&Instruction::op_code, OpCode::GETENVVAR_16), + Field(&Instruction::operands, + ElementsAre(VariantWith(1), + VariantWith(static_cast(EnvironmentVariable::L2GASLEFT)), + VariantWith(17))))); + + auto trace = gen_trace_from_instr(instructions); + + // Find the first row enabling the L2GASLEFT selector + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_l2gasleft == 1; }); + + uint32_t expected_rem_gas = DEFAULT_INITIAL_L2_GAS - + static_cast(GAS_COST_TABLE.at(OpCode::SET_8).base_l2_gas_fixed_table) - + static_cast(GAS_COST_TABLE.at(OpCode::GETENVVAR_16).base_l2_gas_fixed_table); + + EXPECT_EQ(row->main_ia, expected_rem_gas); + EXPECT_EQ(row->main_mem_addr_a, 257); // Resolved direct address: 257 + + validate_trace(std::move(trace), public_inputs); +} + +// Positive test for DAGASLEFT opcode +TEST_F(AvmExecutionTests, daGasLeft) +{ + std::string bytecode_hex = to_hex(OpCode::ADD_16) + // opcode ADD + "00" // Indirect flag + + to_hex(AvmMemoryTag::U32) + + "0007" // addr a 7 + "0009" // addr b 9 + "0001" // addr c 1 + + to_hex(OpCode::GETENVVAR_16) + // opcode L2GASLEFT + "00" // Indirect flag + + to_hex(static_cast(EnvironmentVariable::DAGASLEFT)) + + "0027" // dst_offset (indirect addr: 17) + + to_hex(OpCode::RETURN) + // opcode RETURN + "00" // Indirect flag + "00000000" // ret offset 0 + "00000000"; // ret size 0 + + auto bytecode = hex_to_bytes(bytecode_hex); + auto instructions = Deserialization::parse(bytecode); + + ASSERT_THAT(instructions, SizeIs(3)); + + // DAGASLEFT + EXPECT_THAT(instructions.at(1), + AllOf(Field(&Instruction::op_code, OpCode::GETENVVAR_16), + Field(&Instruction::operands, + ElementsAre(VariantWith(0), + VariantWith(static_cast(EnvironmentVariable::DAGASLEFT)), + VariantWith(39))))); + + auto trace = gen_trace_from_instr(instructions); + + // Find the first row enabling the DAGASLEFT selector + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_dagasleft == 1; }); + + uint32_t expected_rem_gas = DEFAULT_INITIAL_DA_GAS - + static_cast(GAS_COST_TABLE.at(OpCode::ADD_8).base_da_gas_fixed_table) - + static_cast(GAS_COST_TABLE.at(OpCode::GETENVVAR_16).base_da_gas_fixed_table); + + EXPECT_EQ(row->main_ia, expected_rem_gas); + EXPECT_EQ(row->main_mem_addr_a, 39); + + validate_trace(std::move(trace), public_inputs); +} // Should throw whenever the wrong number of public inputs are provided TEST_F(AvmExecutionTests, ExecutorThrowsWithIncorrectNumberOfPublicInputs) From e079fcc3da6ef2b2bb6065fe0bfe411f635827be Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Mon, 23 Sep 2024 13:42:54 +0000 Subject: [PATCH 7/9] txe implementations --- yarn-project/txe/src/oracle/txe_oracle.ts | 5 +++++ yarn-project/txe/src/txe_service/txe_service.ts | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index 8c2a8de63e0..25bfdbe793a 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -281,6 +281,11 @@ export class TXE implements TypedOracle { return Promise.resolve(this.contractAddress); } + getIsStaticCall() { + // Fixed false value copied from getPublicContextInputs. + return Promise.resolve(false); + } + getRandomField() { return Fr.random(); } diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index 5d8edd2800b..527f7201e23 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -313,6 +313,11 @@ export class TXEService { return toForeignCallResult([toSingle(functionSelector.toField())]); } + avmOpcodeIsStaticCall() { + const isStaticCall = (this.typedOracle as TXE).getIsStaticCall(); + return toForeignCallResult([toSingle(isStaticCall.toField())]); + } + async avmOpcodeChainId() { const chainId = await (this.typedOracle as TXE).getChainId(); return toForeignCallResult([toSingle(chainId)]); From 566ddd5b6c13f9e7f8ac6909bb7b7650a99f10af Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Mon, 23 Sep 2024 14:43:45 +0000 Subject: [PATCH 8/9] fix txe again --- yarn-project/txe/src/oracle/txe_oracle.ts | 2 +- yarn-project/txe/src/txe_service/txe_service.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index 25bfdbe793a..f264af6322d 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -283,7 +283,7 @@ export class TXE implements TypedOracle { getIsStaticCall() { // Fixed false value copied from getPublicContextInputs. - return Promise.resolve(false); + return false; } getRandomField() { diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index 527f7201e23..37c5adb7e80 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -315,7 +315,7 @@ export class TXEService { avmOpcodeIsStaticCall() { const isStaticCall = (this.typedOracle as TXE).getIsStaticCall(); - return toForeignCallResult([toSingle(isStaticCall.toField())]); + return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]); } async avmOpcodeChainId() { From 8725339c8984498016689d67e958ab1007c3c0fd Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Mon, 23 Sep 2024 16:48:18 +0000 Subject: [PATCH 9/9] more txe --- .../aztec-nr/aztec/src/test/helpers/cheatcodes.nr | 7 +++++++ .../aztec-nr/aztec/src/test/helpers/test_environment.nr | 2 ++ noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr | 2 ++ yarn-project/txe/src/oracle/txe_oracle.ts | 8 ++++++-- yarn-project/txe/src/txe_service/txe_service.ts | 5 +++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr index d1a6e42d500..a483b0f8107 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr @@ -111,6 +111,10 @@ unconstrained pub fn set_fn_selector(selector: FunctionSelector) { oracle_set_function_selector(selector) } +unconstrained pub fn set_is_static_call(is_static: bool) { + oracle_set_is_static_call(is_static) +} + #[oracle(reset)] unconstrained fn oracle_reset() {} @@ -157,6 +161,9 @@ unconstrained fn oracle_get_msg_sender() -> AztecAddress {} #[oracle(setMsgSender)] unconstrained fn oracle_set_msg_sender(msg_sender: AztecAddress) {} +#[oracle(setIsStaticCall)] +unconstrained fn oracle_set_is_static_call(is_static: bool) {} + #[oracle(getSideEffectsCounter)] unconstrained fn oracle_get_side_effects_counter() -> u32 {} diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr index e654a5dd8f6..aa6e3641fed 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr @@ -153,6 +153,7 @@ impl TestEnvironment { cheatcodes::set_fn_selector(fn_selector); cheatcodes::set_contract_address(target_address); cheatcodes::set_msg_sender(original_contract_address); + cheatcodes::set_is_static_call(call_interface.get_is_static()); let mut inputs = cheatcodes::get_public_context_inputs(); inputs.calldata_length = call_interface.get_args().len() as Field; inputs.is_static_call = call_interface.get_is_static(); @@ -164,6 +165,7 @@ impl TestEnvironment { cheatcodes::set_contract_address(original_contract_address); cheatcodes::set_msg_sender(original_msg_sender); cheatcodes::set_calldata(calldata); + cheatcodes::set_is_static_call(call_interface.get_is_static()); result } diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr index 20661d24a8f..046c48e5473 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr @@ -86,6 +86,7 @@ impl Deployer { cheatcodes::set_fn_selector(call_interface.get_selector()); cheatcodes::set_contract_address(instance.to_address()); cheatcodes::set_msg_sender(original_contract_address); + cheatcodes::set_is_static_call(call_interface.get_is_static()); let mut inputs = cheatcodes::get_public_context_inputs(); inputs.calldata_length = call_interface.get_args().len() as Field; inputs.is_static_call = call_interface.get_is_static(); @@ -97,6 +98,7 @@ impl Deployer { cheatcodes::set_contract_address(original_contract_address); cheatcodes::set_msg_sender(original_msg_sender); cheatcodes::set_calldata(calldata); + cheatcodes::set_is_static_call(call_interface.get_is_static()); instance } diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index f264af6322d..9d13d795250 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -80,6 +80,7 @@ export class TXE implements TypedOracle { private contractAddress: AztecAddress; private msgSender: AztecAddress; private functionSelector = FunctionSelector.fromField(new Fr(0)); + private isStaticCall = false; // This will hold the _real_ calldata. That is, the one without the PublicContextInputs. // TODO: Remove this comment once PublicContextInputs are removed. private calldata: Fr[] = []; @@ -281,9 +282,12 @@ export class TXE implements TypedOracle { return Promise.resolve(this.contractAddress); } + setIsStaticCall(isStatic: boolean) { + this.isStaticCall = isStatic; + } + getIsStaticCall() { - // Fixed false value copied from getPublicContextInputs. - return false; + return this.isStaticCall; } getRandomField() { diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index 37c5adb7e80..9661d894cd6 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -313,6 +313,11 @@ export class TXEService { return toForeignCallResult([toSingle(functionSelector.toField())]); } + setIsStaticCall(isStaticCall: ForeignCallSingle) { + (this.typedOracle as TXE).setIsStaticCall(fromSingle(isStaticCall).toBool()); + return toForeignCallResult([]); + } + avmOpcodeIsStaticCall() { const isStaticCall = (this.typedOracle as TXE).getIsStaticCall(); return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);