diff --git a/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp b/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp index 04ae906b1d5..a0297450023 100644 --- a/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/aztec_constants.hpp @@ -19,7 +19,6 @@ #define MAX_L2_TO_L1_MSGS_PER_TX 8 #define MAX_UNENCRYPTED_LOGS_PER_TX 8 #define MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS 3000 -#define MAX_L2_GAS_PER_TX_PUBLIC_PORTION 12000000 #define CANONICAL_AUTH_REGISTRY_ADDRESS 1 #define DEPLOYER_CONTRACT_ADDRESS 2 #define REGISTERER_CONTRACT_ADDRESS 3 @@ -47,7 +46,7 @@ #define TOTAL_FEES_LENGTH 1 #define PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH 867 #define AVM_ACCUMULATED_DATA_LENGTH 320 -#define AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH 1008 +#define AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH 1009 #define AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS 86 #define AVM_PROOF_LENGTH_IN_FIELDS 4155 #define AVM_PUBLIC_COLUMN_MAX_SIZE 1024 @@ -83,62 +82,63 @@ #define START_EMIT_NULLIFIER_WRITE_OFFSET 208 #define START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET 224 #define START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET 226 -#define AVM_ADD_BASE_L2_GAS 32 -#define AVM_SUB_BASE_L2_GAS 32 -#define AVM_MUL_BASE_L2_GAS 33 -#define AVM_DIV_BASE_L2_GAS 43 -#define AVM_FDIV_BASE_L2_GAS 32 -#define AVM_EQ_BASE_L2_GAS 32 -#define AVM_LT_BASE_L2_GAS 64 -#define AVM_LTE_BASE_L2_GAS 64 -#define AVM_AND_BASE_L2_GAS 33 -#define AVM_OR_BASE_L2_GAS 33 -#define AVM_XOR_BASE_L2_GAS 33 -#define AVM_NOT_BASE_L2_GAS 27 -#define AVM_SHL_BASE_L2_GAS 32 -#define AVM_SHR_BASE_L2_GAS 32 -#define AVM_CAST_BASE_L2_GAS 30 -#define AVM_GETENVVAR_BASE_L2_GAS 20 -#define AVM_CALLDATACOPY_BASE_L2_GAS 29 -#define AVM_RETURNDATASIZE_BASE_L2_GAS 20 -#define AVM_RETURNDATACOPY_BASE_L2_GAS 29 -#define AVM_JUMP_BASE_L2_GAS 12 -#define AVM_JUMPI_BASE_L2_GAS 18 -#define AVM_INTERNALCALL_BASE_L2_GAS 18 -#define AVM_INTERNALRETURN_BASE_L2_GAS 18 -#define AVM_SET_BASE_L2_GAS 18 -#define AVM_MOV_BASE_L2_GAS 23 -#define AVM_SLOAD_BASE_L2_GAS 1218 -#define AVM_SSTORE_BASE_L2_GAS 2642 -#define AVM_NOTEHASHEXISTS_BASE_L2_GAS 1226 -#define AVM_EMITNOTEHASH_BASE_L2_GAS 2650 -#define AVM_NULLIFIEREXISTS_BASE_L2_GAS 2426 -#define AVM_EMITNULLIFIER_BASE_L2_GAS 4250 -#define AVM_L1TOL2MSGEXISTS_BASE_L2_GAS 1196 -#define AVM_GETCONTRACTINSTANCE_BASE_L2_GAS 2448 -#define AVM_EMITUNENCRYPTEDLOG_BASE_L2_GAS 18 -#define AVM_SENDL2TOL1MSG_BASE_L2_GAS 226 -#define AVM_CALL_BASE_L2_GAS 4845 -#define AVM_STATICCALL_BASE_L2_GAS 4845 -#define AVM_RETURN_BASE_L2_GAS 28 -#define AVM_REVERT_BASE_L2_GAS 28 -#define AVM_DEBUGLOG_BASE_L2_GAS 12 -#define AVM_DEBUGLOG_DYN_L2_GAS 3 -#define AVM_POSEIDON2_BASE_L2_GAS 78 -#define AVM_SHA256COMPRESSION_BASE_L2_GAS 261 -#define AVM_KECCAKF1600_BASE_L2_GAS 300 -#define AVM_ECADD_BASE_L2_GAS 62 -#define AVM_MSM_BASE_L2_GAS 1000 -#define AVM_TORADIXBE_BASE_L2_GAS 46 -#define AVM_CALLDATACOPY_DYN_L2_GAS 6 -#define AVM_RETURNDATACOPY_DYN_L2_GAS 6 -#define AVM_EMITUNENCRYPTEDLOG_DYN_L2_GAS 146 +#define MAX_L2_GAS_PER_TX_PUBLIC_PORTION 12000000 +#define AVM_POSEIDON2_BASE_L2_GAS 36 +#define AVM_ADD_BASE_L2_GAS 27 +#define AVM_SUB_BASE_L2_GAS 27 +#define AVM_MUL_BASE_L2_GAS 27 +#define AVM_DIV_BASE_L2_GAS 27 +#define AVM_FDIV_BASE_L2_GAS 27 +#define AVM_EQ_BASE_L2_GAS 27 +#define AVM_LT_BASE_L2_GAS 30 +#define AVM_LTE_BASE_L2_GAS 30 +#define AVM_AND_BASE_L2_GAS 51 +#define AVM_OR_BASE_L2_GAS 51 +#define AVM_XOR_BASE_L2_GAS 51 +#define AVM_NOT_BASE_L2_GAS 18 +#define AVM_SHL_BASE_L2_GAS 27 +#define AVM_SHR_BASE_L2_GAS 27 +#define AVM_CAST_BASE_L2_GAS 18 +#define AVM_GETENVVAR_BASE_L2_GAS 9 +#define AVM_CALLDATACOPY_BASE_L2_GAS 24 +#define AVM_RETURNDATASIZE_BASE_L2_GAS 9 +#define AVM_RETURNDATACOPY_BASE_L2_GAS 24 +#define AVM_JUMP_BASE_L2_GAS 3 +#define AVM_JUMPI_BASE_L2_GAS 9 +#define AVM_INTERNALCALL_BASE_L2_GAS 3 +#define AVM_INTERNALRETURN_BASE_L2_GAS 3 +#define AVM_SET_BASE_L2_GAS 9 +#define AVM_MOV_BASE_L2_GAS 18 +#define AVM_SLOAD_BASE_L2_GAS 1458 +#define AVM_SSTORE_BASE_L2_GAS 6802 +#define AVM_NOTEHASHEXISTS_BASE_L2_GAS 1467 +#define AVM_EMITNOTEHASH_BASE_L2_GAS 3913 +#define AVM_NULLIFIEREXISTS_BASE_L2_GAS 1467 +#define AVM_EMITNULLIFIER_BASE_L2_GAS 5353 +#define AVM_L1TOL2MSGEXISTS_BASE_L2_GAS 1431 +#define AVM_GETCONTRACTINSTANCE_BASE_L2_GAS 1467 +#define AVM_EMITUNENCRYPTEDLOG_BASE_L2_GAS 15 +#define AVM_SENDL2TOL1MSG_BASE_L2_GAS 218 +#define AVM_CALL_BASE_L2_GAS 2925 +#define AVM_STATICCALL_BASE_L2_GAS 2925 +#define AVM_RETURN_BASE_L2_GAS 15 +#define AVM_REVERT_BASE_L2_GAS 15 +#define AVM_DEBUGLOG_BASE_L2_GAS 21 +#define AVM_SHA256COMPRESSION_BASE_L2_GAS 114 +#define AVM_KECCAKF1600_BASE_L2_GAS 162 +#define AVM_ECADD_BASE_L2_GAS 69 +#define AVM_MSM_BASE_L2_GAS 36 +#define AVM_TORADIXBE_BASE_L2_GAS 24 +#define AVM_CALLDATACOPY_DYN_L2_GAS 3 +#define AVM_RETURNDATACOPY_DYN_L2_GAS 3 +#define AVM_EMITUNENCRYPTEDLOG_DYN_L2_GAS 131 #define AVM_CALL_DYN_L2_GAS 4 #define AVM_STATICCALL_DYN_L2_GAS 4 -#define AVM_RETURN_DYN_L2_GAS 6 -#define AVM_REVERT_DYN_L2_GAS 6 -#define AVM_MSM_DYN_L2_GAS 100 -#define AVM_TORADIXBE_DYN_L2_GAS 20 +#define AVM_RETURN_DYN_L2_GAS 3 +#define AVM_REVERT_DYN_L2_GAS 3 +#define AVM_DEBUGLOG_DYN_L2_GAS 6 +#define AVM_MSM_DYN_L2_GAS 6 +#define AVM_TORADIXBE_DYN_L2_GAS 3 #define AVM_SSTORE_BASE_DA_GAS 512 #define AVM_EMITNOTEHASH_BASE_DA_GAS 512 #define AVM_EMITNULLIFIER_BASE_DA_GAS 512 diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 56ab2bd79cb..5c827dbabb4 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -110,27 +110,6 @@ library Constants { 24399338136397901754495080759185489776044879232766421623673792970137; uint256 internal constant DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = 14061769416655647708490531650437236735160113654556896985372298487345; - uint256 internal constant DEFAULT_GAS_LIMIT = 1000000000; - uint256 internal constant DEFAULT_TEARDOWN_GAS_LIMIT = 12000000; - uint256 internal constant MAX_L2_GAS_PER_TX_PUBLIC_PORTION = 12000000; - uint256 internal constant DA_BYTES_PER_FIELD = 32; - uint256 internal constant DA_GAS_PER_BYTE = 16; - uint256 internal constant FIXED_DA_GAS = 512; - uint256 internal constant FIXED_L2_GAS = 512; - uint256 internal constant FIXED_AVM_STARTUP_L2_GAS = 20000; - uint256 internal constant L2_GAS_DISTRIBUTED_STORAGE_PREMIUM = 1024; - uint256 internal constant L2_GAS_PER_READ_MERKLE_HASH = 30; - uint256 internal constant L2_GAS_PER_WRITE_MERKLE_HASH = 40; - uint256 internal constant L2_GAS_PER_PUBLIC_DATA_UPDATE = 2624; - uint256 internal constant L2_GAS_PER_NOTE_HASH = 2624; - uint256 internal constant L2_GAS_PER_NULLIFIER = 4224; - uint256 internal constant L2_GAS_PER_PUBLIC_DATA_READ = 1200; - uint256 internal constant L2_GAS_PER_NOTE_HASH_READ_REQUEST = 1200; - uint256 internal constant L2_GAS_PER_NULLIFIER_READ_REQUEST = 2400; - uint256 internal constant L2_GAS_PER_L1_TO_L2_MSG_READ_REQUEST = 1170; - uint256 internal constant L2_GAS_PER_LOG_BYTE = 4; - uint256 internal constant L2_GAS_PER_PRIVATE_LOG = 0; - uint256 internal constant L2_GAS_PER_L2_TO_L1_MSG = 200; uint256 internal constant MAX_PROTOCOL_CONTRACTS = 7; uint256 internal constant CANONICAL_AUTH_REGISTRY_ADDRESS = 1; uint256 internal constant DEPLOYER_CONTRACT_ADDRESS = 2; @@ -271,6 +250,28 @@ library Constants { uint256 internal constant START_EMIT_NULLIFIER_WRITE_OFFSET = 208; uint256 internal constant START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET = 224; uint256 internal constant START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET = 226; + uint256 internal constant DEFAULT_GAS_LIMIT = 1000000000; + uint256 internal constant DEFAULT_TEARDOWN_GAS_LIMIT = 12000000; + uint256 internal constant MAX_L2_GAS_PER_TX_PUBLIC_PORTION = 12000000; + uint256 internal constant MAX_L2_GAS_PER_ENQUEUED_CALL = 12000000; + uint256 internal constant DA_BYTES_PER_FIELD = 32; + uint256 internal constant DA_GAS_PER_BYTE = 16; + uint256 internal constant FIXED_DA_GAS = 512; + uint256 internal constant FIXED_L2_GAS = 512; + uint256 internal constant FIXED_AVM_STARTUP_L2_GAS = 20000; + uint256 internal constant L2_GAS_DISTRIBUTED_STORAGE_PREMIUM = 1024; + uint256 internal constant L2_GAS_PER_READ_MERKLE_HASH = 36; + uint256 internal constant L2_GAS_PER_WRITE_MERKLE_HASH = 36; + uint256 internal constant L2_GAS_PER_PUBLIC_DATA_UPDATE = 6784; + uint256 internal constant L2_GAS_PER_NOTE_HASH = 3904; + uint256 internal constant L2_GAS_PER_NULLIFIER = 5344; + uint256 internal constant L2_GAS_PER_PUBLIC_DATA_READ = 1440; + uint256 internal constant L2_GAS_PER_NOTE_HASH_READ_REQUEST = 1440; + uint256 internal constant L2_GAS_PER_NULLIFIER_READ_REQUEST = 1440; + uint256 internal constant L2_GAS_PER_L1_TO_L2_MSG_READ_REQUEST = 1404; + uint256 internal constant L2_GAS_PER_LOG_BYTE = 4; + uint256 internal constant L2_GAS_PER_PRIVATE_LOG = 0; + uint256 internal constant L2_GAS_PER_L2_TO_L1_MSG = 200; uint256 internal constant PROOF_TYPE_PLONK = 0; uint256 internal constant PROOF_TYPE_HONK = 1; uint256 internal constant PROOF_TYPE_OINK = 2; 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 0669849f1d5..1eccf5c8554 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -168,56 +168,6 @@ pub global REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE: Field = pub global DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE: Field = 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631; -// GAS DEFAULTS -pub global DEFAULT_GAS_LIMIT: u32 = 1_000_000_000; -pub global DEFAULT_TEARDOWN_GAS_LIMIT: u32 = 12_000_000; -pub global MAX_L2_GAS_PER_TX_PUBLIC_PORTION: u32 = 12_000_000; -pub global DA_BYTES_PER_FIELD: u32 = 32; -pub global DA_GAS_PER_BYTE: u32 = 16; -// pays for preamble information in TX Effects -pub global FIXED_DA_GAS: u32 = 512; -// pays for fixed tx costs like validation, and updating state roots -pub global FIXED_L2_GAS: u32 = 512; -// base cost for a single public call -pub global FIXED_AVM_STARTUP_L2_GAS: u32 = 20_000; - -// Some tree insertions incur an additional cost associated with -// the new database entry to be stored by all network participants. -pub global L2_GAS_DISTRIBUTED_STORAGE_PREMIUM: u32 = 1024; - -// Kernel and/or rollup circuits perform a hash per tree-level for insertions and reads. -// All network participants need to perform tree insertions. -// Not _all_ network participants need to perform membership checks, so they're cheaper. -pub global L2_GAS_PER_READ_MERKLE_HASH: u32 = 30; -pub global L2_GAS_PER_WRITE_MERKLE_HASH: u32 = 40; - -// Gas for tree insertions and associated storage -pub global L2_GAS_PER_PUBLIC_DATA_UPDATE: u32 = - L2_GAS_DISTRIBUTED_STORAGE_PREMIUM + (PUBLIC_DATA_TREE_HEIGHT * L2_GAS_PER_WRITE_MERKLE_HASH); -pub global L2_GAS_PER_NOTE_HASH: u32 = - L2_GAS_DISTRIBUTED_STORAGE_PREMIUM + (NOTE_HASH_TREE_HEIGHT * L2_GAS_PER_WRITE_MERKLE_HASH); -// 2x because insertion into indexed tree requires a low-leaf membership check and a standard insertion -pub global L2_GAS_PER_NULLIFIER: u32 = - L2_GAS_DISTRIBUTED_STORAGE_PREMIUM + (2 * NULLIFIER_TREE_HEIGHT * L2_GAS_PER_WRITE_MERKLE_HASH); - -// Gas for tree read requests -pub global L2_GAS_PER_PUBLIC_DATA_READ: u32 = PUBLIC_DATA_TREE_HEIGHT * L2_GAS_PER_READ_MERKLE_HASH; -pub global L2_GAS_PER_NOTE_HASH_READ_REQUEST: u32 = - NOTE_HASH_TREE_HEIGHT * L2_GAS_PER_READ_MERKLE_HASH; -// 2x because non-membership checks are really 2 membership checks -pub global L2_GAS_PER_NULLIFIER_READ_REQUEST: u32 = - 2 * NULLIFIER_TREE_HEIGHT * L2_GAS_PER_READ_MERKLE_HASH; -pub global L2_GAS_PER_L1_TO_L2_MSG_READ_REQUEST: u32 = - L1_TO_L2_MSG_TREE_HEIGHT * L2_GAS_PER_READ_MERKLE_HASH; - -// Gas for hashing and validating logs -pub global L2_GAS_PER_LOG_BYTE: u32 = 4; -// Zero gas because we don't have to hash and validate the private logs -pub global L2_GAS_PER_PRIVATE_LOG: u32 = 0; - -// Gas for writing message to L1 portal -pub global L2_GAS_PER_L2_TO_L1_MSG: u32 = 200; - // CANONICAL CONTRACT ADDRESSES pub global MAX_PROTOCOL_CONTRACTS: u32 = (1 << PROTOCOL_CONTRACT_TREE_HEIGHT as u8) - 1; // Index 0 can't be used. pub global CANONICAL_AUTH_REGISTRY_ADDRESS: AztecAddress = AztecAddress::from_field(1); @@ -630,72 +580,131 @@ pub global START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET: u32 = pub global START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET: u32 = START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET + MAX_L2_TO_L1_MSGS_PER_CALL; +// GAS DEFAULTS +pub global DEFAULT_GAS_LIMIT: u32 = 1_000_000_000; +pub global DEFAULT_TEARDOWN_GAS_LIMIT: u32 = 12_000_000; +pub global MAX_L2_GAS_PER_TX_PUBLIC_PORTION: u32 = 12_000_000; +pub global MAX_L2_GAS_PER_ENQUEUED_CALL: u32 = 12_000_000; +pub global DA_BYTES_PER_FIELD: u32 = 32; +pub global DA_GAS_PER_BYTE: u32 = 16; +// pays for preamble information in TX Effects +pub global FIXED_DA_GAS: u32 = 512; +// pays for fixed tx costs like validation, and updating state roots +pub global FIXED_L2_GAS: u32 = 512; +// base cost for a single public call +pub global FIXED_AVM_STARTUP_L2_GAS: u32 = 20_000; + +// Some tree insertions incur an additional cost associated with +// the new database entry to be stored by all network participants. +pub global L2_GAS_DISTRIBUTED_STORAGE_PREMIUM: u32 = 1024; + +// All AVM opcode gas costs are below except this one because it is needed for Merkle tree related constants. +pub global AVM_POSEIDON2_BASE_L2_GAS: u32 = 36; + +// Kernel and/or rollup circuits perform a hash per tree-level for insertions and reads. +// All network participants need to perform tree insertions. +// Not _all_ network participants need to perform membership checks, so they're cheaper. +pub global L2_GAS_PER_READ_MERKLE_HASH: u32 = AVM_POSEIDON2_BASE_L2_GAS; +pub global L2_GAS_PER_WRITE_MERKLE_HASH: u32 = AVM_POSEIDON2_BASE_L2_GAS; + +// Gas for tree insertions and associated storage +// For public data tree update, we account for the worst case scenario which is a new insertion +// takes 4 Merkle path checks while an update would need 3 Merkle path checks. +pub global L2_GAS_PER_PUBLIC_DATA_UPDATE: u32 = L2_GAS_DISTRIBUTED_STORAGE_PREMIUM + + (4 * PUBLIC_DATA_TREE_HEIGHT * L2_GAS_PER_WRITE_MERKLE_HASH); +pub global L2_GAS_PER_NOTE_HASH: u32 = + L2_GAS_DISTRIBUTED_STORAGE_PREMIUM + (2 * NOTE_HASH_TREE_HEIGHT * L2_GAS_PER_WRITE_MERKLE_HASH); +// 2x because insertion into indexed tree requires a low-leaf membership check and a standard insertion +pub global L2_GAS_PER_NULLIFIER: u32 = + L2_GAS_DISTRIBUTED_STORAGE_PREMIUM + (3 * NULLIFIER_TREE_HEIGHT * L2_GAS_PER_WRITE_MERKLE_HASH); + +// Gas for tree read requests +pub global L2_GAS_PER_PUBLIC_DATA_READ: u32 = PUBLIC_DATA_TREE_HEIGHT * L2_GAS_PER_READ_MERKLE_HASH; +pub global L2_GAS_PER_NOTE_HASH_READ_REQUEST: u32 = + NOTE_HASH_TREE_HEIGHT * L2_GAS_PER_READ_MERKLE_HASH; +// 2x because non-membership checks are really 2 membership checks +pub global L2_GAS_PER_NULLIFIER_READ_REQUEST: u32 = + NULLIFIER_TREE_HEIGHT * L2_GAS_PER_READ_MERKLE_HASH; +pub global L2_GAS_PER_L1_TO_L2_MSG_READ_REQUEST: u32 = + L1_TO_L2_MSG_TREE_HEIGHT * L2_GAS_PER_READ_MERKLE_HASH; + +// Gas for hashing and validating logs +pub global L2_GAS_PER_LOG_BYTE: u32 = 4; +// Zero gas because we don't have to hash and validate the private logs +pub global L2_GAS_PER_PRIVATE_LOG: u32 = 0; + +// Gas for writing message to L1 portal +pub global L2_GAS_PER_L2_TO_L1_MSG: u32 = 200; + /** * GAS COSTS FOR AVM OPCODES * They are used in TS and C++ */ + +// Exception for AVM_POSEIDON2_BASE_L2_GAS which needed to be defined above. + // Base L2 GAS // Note: magic numbers here are derived from each op's AVM circuit trace area -pub global AVM_ADD_BASE_L2_GAS: u32 = 32; -pub global AVM_SUB_BASE_L2_GAS: u32 = 32; -pub global AVM_MUL_BASE_L2_GAS: u32 = 33; -pub global AVM_DIV_BASE_L2_GAS: u32 = 43; -pub global AVM_FDIV_BASE_L2_GAS: u32 = 32; -pub global AVM_EQ_BASE_L2_GAS: u32 = 32; -pub global AVM_LT_BASE_L2_GAS: u32 = 64; -pub global AVM_LTE_BASE_L2_GAS: u32 = 64; -pub global AVM_AND_BASE_L2_GAS: u32 = 33; -pub global AVM_OR_BASE_L2_GAS: u32 = 33; -pub global AVM_XOR_BASE_L2_GAS: u32 = 33; -pub global AVM_NOT_BASE_L2_GAS: u32 = 27; -pub global AVM_SHL_BASE_L2_GAS: u32 = 32; -pub global AVM_SHR_BASE_L2_GAS: u32 = 32; -pub global AVM_CAST_BASE_L2_GAS: u32 = 30; -pub global AVM_GETENVVAR_BASE_L2_GAS: u16 = 20; -pub global AVM_CALLDATACOPY_BASE_L2_GAS: u32 = 29; -pub global AVM_RETURNDATASIZE_BASE_L2_GAS: u32 = 20; -pub global AVM_RETURNDATACOPY_BASE_L2_GAS: u32 = 29; -pub global AVM_JUMP_BASE_L2_GAS: u32 = 12; -pub global AVM_JUMPI_BASE_L2_GAS: u32 = 18; -pub global AVM_INTERNALCALL_BASE_L2_GAS: u32 = 18; -pub global AVM_INTERNALRETURN_BASE_L2_GAS: u32 = 18; -pub global AVM_SET_BASE_L2_GAS: u32 = 18; -pub global AVM_MOV_BASE_L2_GAS: u32 = 23; +pub global AVM_ADD_BASE_L2_GAS: u32 = 27; +pub global AVM_SUB_BASE_L2_GAS: u32 = 27; +pub global AVM_MUL_BASE_L2_GAS: u32 = 27; +pub global AVM_DIV_BASE_L2_GAS: u32 = 27; +pub global AVM_FDIV_BASE_L2_GAS: u32 = 27; +pub global AVM_EQ_BASE_L2_GAS: u32 = 27; +pub global AVM_LT_BASE_L2_GAS: u32 = 30; +pub global AVM_LTE_BASE_L2_GAS: u32 = 30; +pub global AVM_AND_BASE_L2_GAS: u32 = 51; +pub global AVM_OR_BASE_L2_GAS: u32 = 51; +pub global AVM_XOR_BASE_L2_GAS: u32 = 51; +pub global AVM_NOT_BASE_L2_GAS: u32 = 18; +pub global AVM_SHL_BASE_L2_GAS: u32 = 27; +pub global AVM_SHR_BASE_L2_GAS: u32 = 27; +pub global AVM_CAST_BASE_L2_GAS: u32 = 18; +pub global AVM_GETENVVAR_BASE_L2_GAS: u16 = 9; +pub global AVM_CALLDATACOPY_BASE_L2_GAS: u32 = 24; +pub global AVM_RETURNDATASIZE_BASE_L2_GAS: u32 = 9; +pub global AVM_RETURNDATACOPY_BASE_L2_GAS: u32 = 24; +pub global AVM_JUMP_BASE_L2_GAS: u32 = 3; +pub global AVM_JUMPI_BASE_L2_GAS: u32 = 9; +pub global AVM_INTERNALCALL_BASE_L2_GAS: u32 = 3; +pub global AVM_INTERNALRETURN_BASE_L2_GAS: u32 = 3; +pub global AVM_SET_BASE_L2_GAS: u32 = 9; +pub global AVM_MOV_BASE_L2_GAS: u32 = 18; pub global AVM_SLOAD_BASE_L2_GAS: u32 = 18 + L2_GAS_PER_PUBLIC_DATA_READ; pub global AVM_SSTORE_BASE_L2_GAS: u32 = 18 + L2_GAS_PER_PUBLIC_DATA_UPDATE; -pub global AVM_NOTEHASHEXISTS_BASE_L2_GAS: u32 = 26 + L2_GAS_PER_NOTE_HASH_READ_REQUEST; -pub global AVM_EMITNOTEHASH_BASE_L2_GAS: u32 = 26 + L2_GAS_PER_NOTE_HASH; -pub global AVM_NULLIFIEREXISTS_BASE_L2_GAS: u32 = 26 + L2_GAS_PER_NULLIFIER_READ_REQUEST; -pub global AVM_EMITNULLIFIER_BASE_L2_GAS: u32 = 26 + L2_GAS_PER_NULLIFIER; -pub global AVM_L1TOL2MSGEXISTS_BASE_L2_GAS: u32 = 26 + L2_GAS_PER_L1_TO_L2_MSG_READ_REQUEST; -pub global AVM_GETCONTRACTINSTANCE_BASE_L2_GAS: u32 = 48 + L2_GAS_PER_NULLIFIER_READ_REQUEST; // does a nullifier check -pub global AVM_EMITUNENCRYPTEDLOG_BASE_L2_GAS: u32 = 18; -pub global AVM_SENDL2TOL1MSG_BASE_L2_GAS: u32 = 26 + L2_GAS_PER_L2_TO_L1_MSG; +pub global AVM_NOTEHASHEXISTS_BASE_L2_GAS: u32 = 27 + L2_GAS_PER_NOTE_HASH_READ_REQUEST; +pub global AVM_EMITNOTEHASH_BASE_L2_GAS: u32 = 9 + L2_GAS_PER_NOTE_HASH; +pub global AVM_NULLIFIEREXISTS_BASE_L2_GAS: u32 = 27 + L2_GAS_PER_NULLIFIER_READ_REQUEST; +pub global AVM_EMITNULLIFIER_BASE_L2_GAS: u32 = 9 + L2_GAS_PER_NULLIFIER; +pub global AVM_L1TOL2MSGEXISTS_BASE_L2_GAS: u32 = 27 + L2_GAS_PER_L1_TO_L2_MSG_READ_REQUEST; +pub global AVM_GETCONTRACTINSTANCE_BASE_L2_GAS: u32 = 27 + L2_GAS_PER_NULLIFIER_READ_REQUEST; // does a nullifier check +pub global AVM_EMITUNENCRYPTEDLOG_BASE_L2_GAS: u32 = 15; +pub global AVM_SENDL2TOL1MSG_BASE_L2_GAS: u32 = 18 + L2_GAS_PER_L2_TO_L1_MSG; // On CALL, AVM performs nullifier checks for contract address & contract class ID pub global AVM_CALL_BASE_L2_GAS: u32 = 45 + (2 * L2_GAS_PER_NULLIFIER_READ_REQUEST); pub global AVM_STATICCALL_BASE_L2_GAS: u32 = 45 + (2 * L2_GAS_PER_NULLIFIER_READ_REQUEST); -pub global AVM_RETURN_BASE_L2_GAS: u32 = 28; -pub global AVM_REVERT_BASE_L2_GAS: u32 = 28; -pub global AVM_DEBUGLOG_BASE_L2_GAS: u32 = 12; -pub global AVM_DEBUGLOG_DYN_L2_GAS: u32 = 3; -pub global AVM_POSEIDON2_BASE_L2_GAS: u32 = 78; -pub global AVM_SHA256COMPRESSION_BASE_L2_GAS: u32 = 261; -pub global AVM_KECCAKF1600_BASE_L2_GAS: u32 = 300; -pub global AVM_ECADD_BASE_L2_GAS: u32 = 62; -pub global AVM_MSM_BASE_L2_GAS: u32 = 1000; -pub global AVM_TORADIXBE_BASE_L2_GAS: u32 = 46; +pub global AVM_RETURN_BASE_L2_GAS: u32 = 15; +pub global AVM_REVERT_BASE_L2_GAS: u32 = 15; +pub global AVM_DEBUGLOG_BASE_L2_GAS: u32 = 21; +// For POSEIDON2 see above (constant needed to be set before L2_GAS_PER_READ_MERKLE_HASH) +pub global AVM_SHA256COMPRESSION_BASE_L2_GAS: u32 = 114; +pub global AVM_KECCAKF1600_BASE_L2_GAS: u32 = 162; +pub global AVM_ECADD_BASE_L2_GAS: u32 = 69; +pub global AVM_MSM_BASE_L2_GAS: u32 = 36; +pub global AVM_TORADIXBE_BASE_L2_GAS: u32 = 24; // Dynamic L2 GAS -pub global AVM_CALLDATACOPY_DYN_L2_GAS: u32 = 6; -pub global AVM_RETURNDATACOPY_DYN_L2_GAS: u32 = 6; +pub global AVM_CALLDATACOPY_DYN_L2_GAS: u32 = 3; +pub global AVM_RETURNDATACOPY_DYN_L2_GAS: u32 = 3; // a single increment here corresponds to an entire additional field (hence x32 bytes per field) -pub global AVM_EMITUNENCRYPTEDLOG_DYN_L2_GAS: u32 = 18 + (DA_BYTES_PER_FIELD * L2_GAS_PER_LOG_BYTE); +pub global AVM_EMITUNENCRYPTEDLOG_DYN_L2_GAS: u32 = 3 + (DA_BYTES_PER_FIELD * L2_GAS_PER_LOG_BYTE); pub global AVM_CALL_DYN_L2_GAS: u32 = 4; pub global AVM_STATICCALL_DYN_L2_GAS: u32 = 4; -pub global AVM_RETURN_DYN_L2_GAS: u32 = 6; -pub global AVM_REVERT_DYN_L2_GAS: u32 = 6; -pub global AVM_MSM_DYN_L2_GAS: u32 = 100; -pub global AVM_TORADIXBE_DYN_L2_GAS: u32 = 20; +pub global AVM_RETURN_DYN_L2_GAS: u32 = 3; +pub global AVM_REVERT_DYN_L2_GAS: u32 = 3; +pub global AVM_DEBUGLOG_DYN_L2_GAS: u32 = 6; +pub global AVM_MSM_DYN_L2_GAS: u32 = 6; +pub global AVM_TORADIXBE_DYN_L2_GAS: u32 = 3; // Base DA Gas pub global AVM_SSTORE_BASE_DA_GAS: u32 = DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index a85bced40ad..684c4093d3a 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -96,27 +96,6 @@ export const REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = 24399338136397901754495080759185489776044879232766421623673792970137n; export const DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = 14061769416655647708490531650437236735160113654556896985372298487345n; -export const DEFAULT_GAS_LIMIT = 1000000000; -export const DEFAULT_TEARDOWN_GAS_LIMIT = 12000000; -export const MAX_L2_GAS_PER_TX_PUBLIC_PORTION = 12000000; -export const DA_BYTES_PER_FIELD = 32; -export const DA_GAS_PER_BYTE = 16; -export const FIXED_DA_GAS = 512; -export const FIXED_L2_GAS = 512; -export const FIXED_AVM_STARTUP_L2_GAS = 20000; -export const L2_GAS_DISTRIBUTED_STORAGE_PREMIUM = 1024; -export const L2_GAS_PER_READ_MERKLE_HASH = 30; -export const L2_GAS_PER_WRITE_MERKLE_HASH = 40; -export const L2_GAS_PER_PUBLIC_DATA_UPDATE = 2624; -export const L2_GAS_PER_NOTE_HASH = 2624; -export const L2_GAS_PER_NULLIFIER = 4224; -export const L2_GAS_PER_PUBLIC_DATA_READ = 1200; -export const L2_GAS_PER_NOTE_HASH_READ_REQUEST = 1200; -export const L2_GAS_PER_NULLIFIER_READ_REQUEST = 2400; -export const L2_GAS_PER_L1_TO_L2_MSG_READ_REQUEST = 1170; -export const L2_GAS_PER_LOG_BYTE = 4; -export const L2_GAS_PER_PRIVATE_LOG = 0; -export const L2_GAS_PER_L2_TO_L1_MSG = 200; export const MAX_PROTOCOL_CONTRACTS = 7; export const CANONICAL_AUTH_REGISTRY_ADDRESS = 1; export const DEPLOYER_CONTRACT_ADDRESS = 2; @@ -198,7 +177,7 @@ export const NUM_PRIVATE_TO_AVM_ACCUMULATED_DATA_ARRAYS = 3; export const AVM_ACCUMULATED_DATA_LENGTH = 320; export const PRIVATE_TO_PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1845; export const KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 958; -export const AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1008; +export const AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1009; export const CONSTANT_ROLLUP_DATA_LENGTH = 13; export const BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 31; export const BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH = 90; @@ -255,62 +234,84 @@ export const START_EMIT_NOTE_HASH_WRITE_OFFSET = 192; export const START_EMIT_NULLIFIER_WRITE_OFFSET = 208; export const START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET = 224; export const START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET = 226; -export const AVM_ADD_BASE_L2_GAS = 32; -export const AVM_SUB_BASE_L2_GAS = 32; -export const AVM_MUL_BASE_L2_GAS = 33; -export const AVM_DIV_BASE_L2_GAS = 43; -export const AVM_FDIV_BASE_L2_GAS = 32; -export const AVM_EQ_BASE_L2_GAS = 32; -export const AVM_LT_BASE_L2_GAS = 64; -export const AVM_LTE_BASE_L2_GAS = 64; -export const AVM_AND_BASE_L2_GAS = 33; -export const AVM_OR_BASE_L2_GAS = 33; -export const AVM_XOR_BASE_L2_GAS = 33; -export const AVM_NOT_BASE_L2_GAS = 27; -export const AVM_SHL_BASE_L2_GAS = 32; -export const AVM_SHR_BASE_L2_GAS = 32; -export const AVM_CAST_BASE_L2_GAS = 30; -export const AVM_GETENVVAR_BASE_L2_GAS = 20; -export const AVM_CALLDATACOPY_BASE_L2_GAS = 29; -export const AVM_RETURNDATASIZE_BASE_L2_GAS = 20; -export const AVM_RETURNDATACOPY_BASE_L2_GAS = 29; -export const AVM_JUMP_BASE_L2_GAS = 12; -export const AVM_JUMPI_BASE_L2_GAS = 18; -export const AVM_INTERNALCALL_BASE_L2_GAS = 18; -export const AVM_INTERNALRETURN_BASE_L2_GAS = 18; -export const AVM_SET_BASE_L2_GAS = 18; -export const AVM_MOV_BASE_L2_GAS = 23; -export const AVM_SLOAD_BASE_L2_GAS = 1218; -export const AVM_SSTORE_BASE_L2_GAS = 2642; -export const AVM_NOTEHASHEXISTS_BASE_L2_GAS = 1226; -export const AVM_EMITNOTEHASH_BASE_L2_GAS = 2650; -export const AVM_NULLIFIEREXISTS_BASE_L2_GAS = 2426; -export const AVM_EMITNULLIFIER_BASE_L2_GAS = 4250; -export const AVM_L1TOL2MSGEXISTS_BASE_L2_GAS = 1196; -export const AVM_GETCONTRACTINSTANCE_BASE_L2_GAS = 2448; -export const AVM_EMITUNENCRYPTEDLOG_BASE_L2_GAS = 18; -export const AVM_SENDL2TOL1MSG_BASE_L2_GAS = 226; -export const AVM_CALL_BASE_L2_GAS = 4845; -export const AVM_STATICCALL_BASE_L2_GAS = 4845; -export const AVM_RETURN_BASE_L2_GAS = 28; -export const AVM_REVERT_BASE_L2_GAS = 28; -export const AVM_DEBUGLOG_BASE_L2_GAS = 12; -export const AVM_DEBUGLOG_DYN_L2_GAS = 3; -export const AVM_POSEIDON2_BASE_L2_GAS = 78; -export const AVM_SHA256COMPRESSION_BASE_L2_GAS = 261; -export const AVM_KECCAKF1600_BASE_L2_GAS = 300; -export const AVM_ECADD_BASE_L2_GAS = 62; -export const AVM_MSM_BASE_L2_GAS = 1000; -export const AVM_TORADIXBE_BASE_L2_GAS = 46; -export const AVM_CALLDATACOPY_DYN_L2_GAS = 6; -export const AVM_RETURNDATACOPY_DYN_L2_GAS = 6; -export const AVM_EMITUNENCRYPTEDLOG_DYN_L2_GAS = 146; +export const DEFAULT_GAS_LIMIT = 1000000000; +export const DEFAULT_TEARDOWN_GAS_LIMIT = 12000000; +export const MAX_L2_GAS_PER_TX_PUBLIC_PORTION = 12000000; +export const MAX_L2_GAS_PER_ENQUEUED_CALL = 12000000; +export const DA_BYTES_PER_FIELD = 32; +export const DA_GAS_PER_BYTE = 16; +export const FIXED_DA_GAS = 512; +export const FIXED_L2_GAS = 512; +export const FIXED_AVM_STARTUP_L2_GAS = 20000; +export const L2_GAS_DISTRIBUTED_STORAGE_PREMIUM = 1024; +export const AVM_POSEIDON2_BASE_L2_GAS = 36; +export const L2_GAS_PER_READ_MERKLE_HASH = 36; +export const L2_GAS_PER_WRITE_MERKLE_HASH = 36; +export const L2_GAS_PER_PUBLIC_DATA_UPDATE = 6784; +export const L2_GAS_PER_NOTE_HASH = 3904; +export const L2_GAS_PER_NULLIFIER = 5344; +export const L2_GAS_PER_PUBLIC_DATA_READ = 1440; +export const L2_GAS_PER_NOTE_HASH_READ_REQUEST = 1440; +export const L2_GAS_PER_NULLIFIER_READ_REQUEST = 1440; +export const L2_GAS_PER_L1_TO_L2_MSG_READ_REQUEST = 1404; +export const L2_GAS_PER_LOG_BYTE = 4; +export const L2_GAS_PER_PRIVATE_LOG = 0; +export const L2_GAS_PER_L2_TO_L1_MSG = 200; +export const AVM_ADD_BASE_L2_GAS = 27; +export const AVM_SUB_BASE_L2_GAS = 27; +export const AVM_MUL_BASE_L2_GAS = 27; +export const AVM_DIV_BASE_L2_GAS = 27; +export const AVM_FDIV_BASE_L2_GAS = 27; +export const AVM_EQ_BASE_L2_GAS = 27; +export const AVM_LT_BASE_L2_GAS = 30; +export const AVM_LTE_BASE_L2_GAS = 30; +export const AVM_AND_BASE_L2_GAS = 51; +export const AVM_OR_BASE_L2_GAS = 51; +export const AVM_XOR_BASE_L2_GAS = 51; +export const AVM_NOT_BASE_L2_GAS = 18; +export const AVM_SHL_BASE_L2_GAS = 27; +export const AVM_SHR_BASE_L2_GAS = 27; +export const AVM_CAST_BASE_L2_GAS = 18; +export const AVM_GETENVVAR_BASE_L2_GAS = 9; +export const AVM_CALLDATACOPY_BASE_L2_GAS = 24; +export const AVM_RETURNDATASIZE_BASE_L2_GAS = 9; +export const AVM_RETURNDATACOPY_BASE_L2_GAS = 24; +export const AVM_JUMP_BASE_L2_GAS = 3; +export const AVM_JUMPI_BASE_L2_GAS = 9; +export const AVM_INTERNALCALL_BASE_L2_GAS = 3; +export const AVM_INTERNALRETURN_BASE_L2_GAS = 3; +export const AVM_SET_BASE_L2_GAS = 9; +export const AVM_MOV_BASE_L2_GAS = 18; +export const AVM_SLOAD_BASE_L2_GAS = 1458; +export const AVM_SSTORE_BASE_L2_GAS = 6802; +export const AVM_NOTEHASHEXISTS_BASE_L2_GAS = 1467; +export const AVM_EMITNOTEHASH_BASE_L2_GAS = 3913; +export const AVM_NULLIFIEREXISTS_BASE_L2_GAS = 1467; +export const AVM_EMITNULLIFIER_BASE_L2_GAS = 5353; +export const AVM_L1TOL2MSGEXISTS_BASE_L2_GAS = 1431; +export const AVM_GETCONTRACTINSTANCE_BASE_L2_GAS = 1467; +export const AVM_EMITUNENCRYPTEDLOG_BASE_L2_GAS = 15; +export const AVM_SENDL2TOL1MSG_BASE_L2_GAS = 218; +export const AVM_CALL_BASE_L2_GAS = 2925; +export const AVM_STATICCALL_BASE_L2_GAS = 2925; +export const AVM_RETURN_BASE_L2_GAS = 15; +export const AVM_REVERT_BASE_L2_GAS = 15; +export const AVM_DEBUGLOG_BASE_L2_GAS = 21; +export const AVM_SHA256COMPRESSION_BASE_L2_GAS = 114; +export const AVM_KECCAKF1600_BASE_L2_GAS = 162; +export const AVM_ECADD_BASE_L2_GAS = 69; +export const AVM_MSM_BASE_L2_GAS = 36; +export const AVM_TORADIXBE_BASE_L2_GAS = 24; +export const AVM_CALLDATACOPY_DYN_L2_GAS = 3; +export const AVM_RETURNDATACOPY_DYN_L2_GAS = 3; +export const AVM_EMITUNENCRYPTEDLOG_DYN_L2_GAS = 131; export const AVM_CALL_DYN_L2_GAS = 4; export const AVM_STATICCALL_DYN_L2_GAS = 4; -export const AVM_RETURN_DYN_L2_GAS = 6; -export const AVM_REVERT_DYN_L2_GAS = 6; -export const AVM_MSM_DYN_L2_GAS = 100; -export const AVM_TORADIXBE_DYN_L2_GAS = 20; +export const AVM_RETURN_DYN_L2_GAS = 3; +export const AVM_REVERT_DYN_L2_GAS = 3; +export const AVM_DEBUGLOG_DYN_L2_GAS = 6; +export const AVM_MSM_DYN_L2_GAS = 6; +export const AVM_TORADIXBE_DYN_L2_GAS = 3; export const AVM_SSTORE_BASE_DA_GAS = 512; export const AVM_EMITNOTEHASH_BASE_DA_GAS = 512; export const AVM_EMITNULLIFIER_BASE_DA_GAS = 512;