diff --git a/barretenberg/cpp/src/barretenberg/vm2/common/aztec_constants.hpp b/barretenberg/cpp/src/barretenberg/vm2/common/aztec_constants.hpp index e320408eb05d..3890636f80b3 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/common/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/common/aztec_constants.hpp @@ -237,12 +237,12 @@ #define AVM_TORADIXBE_DYN_L2_GAS 3 #define AVM_BITWISE_DYN_L2_GAS 3 #define AVM_EMITPUBLICLOG_DYN_L2_GAS 3 -#define AVM_EMITNOTEHASH_BASE_DA_GAS 512 -#define AVM_EMITNULLIFIER_BASE_DA_GAS 512 -#define AVM_SENDL2TOL1MSG_BASE_DA_GAS 512 -#define AVM_EMITPUBLICLOG_BASE_DA_GAS 1024 -#define AVM_EMITPUBLICLOG_DYN_DA_GAS 512 -#define AVM_SSTORE_DYN_DA_GAS 1024 +#define AVM_EMITNOTEHASH_BASE_DA_GAS 32 +#define AVM_EMITNULLIFIER_BASE_DA_GAS 32 +#define AVM_SENDL2TOL1MSG_BASE_DA_GAS 32 +#define AVM_EMITPUBLICLOG_BASE_DA_GAS 64 +#define AVM_EMITPUBLICLOG_DYN_DA_GAS 32 +#define AVM_SSTORE_DYN_DA_GAS 64 #define AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_HEIGHT 6 #define AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_ROOT \ "0x2870b93163d4fd6ada360fe48ee1e8e8e69308af34cdfaeffacbbe5929e2466d" diff --git a/barretenberg/cpp/src/barretenberg/vm2/constraining/avm_fixed_vk.hpp b/barretenberg/cpp/src/barretenberg/vm2/constraining/avm_fixed_vk.hpp index d693bbc47d49..93e925fff4c8 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/constraining/avm_fixed_vk.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/constraining/avm_fixed_vk.hpp @@ -17,7 +17,7 @@ class AvmHardCodedVKAndHash { using FF = bb::curve::BN254::ScalarField; // Precomputed VK hash (hash of all commitments below). - static FF vk_hash() { return FF(uint256_t("0x1f47e68404e58fcde864ff61573d61acab5832efb230f9a32ae68044d31dfd19")); } + static FF vk_hash() { return FF(uint256_t("0x02296b934ced1a5cdacae120d2032d88a119bdb0738d4c4f3ada4f5a831a5153")); } static constexpr std::array get_all() { @@ -59,13 +59,13 @@ class AvmHardCodedVKAndHash { uint256_t( "0x09f2eef32136799118634a108531dc248506d5f58f64885575b245865b56d48e")), // precomputed_exec_opcode Commitment( - uint256_t("0x0188169f0225c14e925347c4f9f192d191b2ab6ca2fbc1d0453f48af5d9c667b"), + uint256_t("0x09bd44905d676585d8c7a91c8ba8fd6b1b598326cb80b95e80b4b39703c7e2c8"), uint256_t( - "0x25b997de6f92af3ea3b409b41437fea01980b344a12fabc6b833656f26d6e954")), // precomputed_exec_opcode_base_da_gas + "0x1bec3a67476715f88745bc09b1ea57859c8fe809fae4376efab6ba773ea7f6d4")), // precomputed_exec_opcode_base_da_gas Commitment( - uint256_t("0x1ddbbb27c627edafce021d5f332867ac9234c6f507442633bff9a5dbb4d02803"), + uint256_t("0x0f5b3fee86f9815eb0be052412de7f2a4c82f678604ba9e161c4412529810057"), uint256_t( - "0x10fda7a2360b21bbfbb1e815377adc0fa869bbcb4a46b29c31ae017893fdfb0d")), // precomputed_exec_opcode_dynamic_da_gas + "0x1ad065dec1d51664807b4d551d0eb8abe0b061b8380dde6d662e2df36a1f85c8")), // precomputed_exec_opcode_dynamic_da_gas Commitment( uint256_t("0x06c03e425e92d09aa8243220a0968b4d7d00c89e541a2b6095920883a8a6fa72"), uint256_t( diff --git a/barretenberg/cpp/src/barretenberg/vm2/testing/avm_inputs.testdata.bin b/barretenberg/cpp/src/barretenberg/vm2/testing/avm_inputs.testdata.bin index 9dd101b2fc02..44bfd7a9a088 100644 Binary files a/barretenberg/cpp/src/barretenberg/vm2/testing/avm_inputs.testdata.bin and b/barretenberg/cpp/src/barretenberg/vm2/testing/avm_inputs.testdata.bin differ diff --git a/barretenberg/cpp/src/barretenberg/vm2/testing/minimal_tx.testdata.bin b/barretenberg/cpp/src/barretenberg/vm2/testing/minimal_tx.testdata.bin index 1c556dc4487c..57ac06aafc7d 100644 Binary files a/barretenberg/cpp/src/barretenberg/vm2/testing/minimal_tx.testdata.bin and b/barretenberg/cpp/src/barretenberg/vm2/testing/minimal_tx.testdata.bin differ diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/gas_meter.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/gas_meter.nr index 8b0809bc4fc7..d598d9c99a5b 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/gas_meter.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/gas_meter.nr @@ -2,9 +2,8 @@ use types::{ abis::{gas::Gas, kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs}, constants::{ AVM_EMITNOTEHASH_BASE_L2_GAS, AVM_EMITNULLIFIER_BASE_L2_GAS, AVM_SENDL2TOL1MSG_BASE_L2_GAS, - DA_BYTES_PER_FIELD, DA_GAS_PER_BYTE, FIXED_AVM_STARTUP_L2_GAS, - L2_GAS_PER_CONTRACT_CLASS_LOG, L2_GAS_PER_L2_TO_L1_MSG, L2_GAS_PER_NOTE_HASH, - L2_GAS_PER_NULLIFIER, L2_GAS_PER_PRIVATE_LOG, + DA_GAS_PER_FIELD, FIXED_AVM_STARTUP_L2_GAS, L2_GAS_PER_CONTRACT_CLASS_LOG, + L2_GAS_PER_L2_TO_L1_MSG, L2_GAS_PER_NOTE_HASH, L2_GAS_PER_NULLIFIER, L2_GAS_PER_PRIVATE_LOG, }, traits::Empty, }; @@ -88,7 +87,7 @@ pub fn meter_gas_used(public_inputs: PrivateKernelCircuitPublicInputs, is_for_pu public_inputs.constants.tx_context.gas_settings.teardown_gas_limits }; - let metered_da_gas = metered_da_fields * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; + let metered_da_gas = metered_da_fields * DA_GAS_PER_FIELD; Gas::tx_overhead() + Gas::new(metered_da_gas, metered_l2_gas) + teardown_gas } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_tail/meter_gas_used_tests.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_tail/meter_gas_used_tests.nr index fb745543506f..619b3e5af792 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_tail/meter_gas_used_tests.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_tail/meter_gas_used_tests.nr @@ -2,18 +2,16 @@ use super::TestBuilder; use types::{ abis::gas::Gas, constants::{ - CONTRACT_CLASS_LOG_SIZE_IN_FIELDS, DA_BYTES_PER_FIELD, DA_GAS_PER_BYTE, - L2_GAS_PER_CONTRACT_CLASS_LOG, L2_GAS_PER_L2_TO_L1_MSG, L2_GAS_PER_NOTE_HASH, - L2_GAS_PER_NULLIFIER, L2_GAS_PER_PRIVATE_LOG, MAX_CONTRACT_CLASS_LOGS_PER_TX, - MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, - MAX_PRIVATE_LOGS_PER_TX, PRIVATE_LOG_SIZE_IN_FIELDS, + CONTRACT_CLASS_LOG_SIZE_IN_FIELDS, DA_GAS_PER_FIELD, L2_GAS_PER_CONTRACT_CLASS_LOG, + L2_GAS_PER_L2_TO_L1_MSG, L2_GAS_PER_NOTE_HASH, L2_GAS_PER_NULLIFIER, L2_GAS_PER_PRIVATE_LOG, + MAX_CONTRACT_CLASS_LOGS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, + MAX_NULLIFIERS_PER_TX, MAX_PRIVATE_LOGS_PER_TX, PRIVATE_LOG_SIZE_IN_FIELDS, }, }; /// A minimum (private) tx initialized in the TestBuilder contains a protocol nullifier, which must exist in every tx. fn get_minimum_private_tx_gas_used() -> Gas { - let nullifier_gas_used = - Gas { da_gas: DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE, l2_gas: L2_GAS_PER_NULLIFIER }; + let nullifier_gas_used = Gas { da_gas: DA_GAS_PER_FIELD, l2_gas: L2_GAS_PER_NULLIFIER }; Gas::tx_overhead() + nullifier_gas_used } @@ -30,7 +28,7 @@ fn with_note_hashes() { builder.previous_kernel.append_siloed_note_hashes(3); - let da_gas = 3 * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; + let da_gas = 3 * DA_GAS_PER_FIELD; let l2_gas = 3 * L2_GAS_PER_NOTE_HASH; let expected_gas_used = Gas::new(da_gas, l2_gas) + get_minimum_private_tx_gas_used(); @@ -44,7 +42,7 @@ fn with_nullifiers() { builder.previous_kernel.append_siloed_nullifiers(5); - let da_gas = 5 * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; + let da_gas = 5 * DA_GAS_PER_FIELD; let l2_gas = 5 * L2_GAS_PER_NULLIFIER; let expected_gas_used = Gas::new(da_gas, l2_gas) + get_minimum_private_tx_gas_used(); @@ -58,7 +56,7 @@ fn with_l2_to_l1_msgs() { builder.previous_kernel.append_l2_to_l1_msgs(3); - let da_gas = 3 * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; + let da_gas = 3 * DA_GAS_PER_FIELD; let l2_gas = 3 * L2_GAS_PER_L2_TO_L1_MSG; let expected_gas_used = Gas::new(da_gas, l2_gas) + get_minimum_private_tx_gas_used(); @@ -74,8 +72,7 @@ fn with_private_logs() { builder.previous_kernel.append_siloed_private_logs_with_lengths([2, 5, 1, 7]); let da_gas = (2 + 5 + 1 + 7 + 4) // +4 for the length field of each private log. - * DA_BYTES_PER_FIELD - * DA_GAS_PER_BYTE; + * DA_GAS_PER_FIELD; let l2_gas = 4 * L2_GAS_PER_PRIVATE_LOG; let expected_gas_used = Gas::new(da_gas, l2_gas) + get_minimum_private_tx_gas_used(); @@ -90,8 +87,7 @@ fn with_contract_class_logs() { builder.previous_kernel.append_contract_class_logs_with_lengths([11]); let da_gas = (11 + 1) // +1 for the contract address. - * DA_BYTES_PER_FIELD - * DA_GAS_PER_BYTE; + * DA_GAS_PER_FIELD; let l2_gas = 1 * L2_GAS_PER_CONTRACT_CLASS_LOG; let expected_gas_used = Gas::new(da_gas, l2_gas) + get_minimum_private_tx_gas_used(); @@ -108,19 +104,19 @@ fn full_side_effects() { // Note hashes. builder.previous_kernel.append_siloed_note_hashes(MAX_NOTE_HASHES_PER_TX); expected_gas_used += Gas { - da_gas: MAX_NOTE_HASHES_PER_TX * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE, + da_gas: MAX_NOTE_HASHES_PER_TX * DA_GAS_PER_FIELD, l2_gas: MAX_NOTE_HASHES_PER_TX * L2_GAS_PER_NOTE_HASH, }; // Nullifiers. builder.previous_kernel.append_siloed_nullifiers(MAX_NULLIFIERS_PER_TX - 1); // -1 for the pre-added protocol nullifier. expected_gas_used += Gas { - da_gas: MAX_NULLIFIERS_PER_TX * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE, + da_gas: MAX_NULLIFIERS_PER_TX * DA_GAS_PER_FIELD, l2_gas: MAX_NULLIFIERS_PER_TX * L2_GAS_PER_NULLIFIER, }; // L2 to L1 messages. builder.previous_kernel.append_l2_to_l1_msgs(MAX_L2_TO_L1_MSGS_PER_TX); expected_gas_used += Gas { - da_gas: MAX_L2_TO_L1_MSGS_PER_TX * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE, + da_gas: MAX_L2_TO_L1_MSGS_PER_TX * DA_GAS_PER_FIELD, l2_gas: MAX_L2_TO_L1_MSGS_PER_TX * L2_GAS_PER_L2_TO_L1_MSG, }; // Private logs. @@ -130,8 +126,7 @@ fn full_side_effects() { expected_gas_used += Gas { da_gas: (PRIVATE_LOG_SIZE_IN_FIELDS + 1) // +1 for the length field. * MAX_PRIVATE_LOGS_PER_TX - * DA_BYTES_PER_FIELD - * DA_GAS_PER_BYTE, + * DA_GAS_PER_FIELD, l2_gas: MAX_PRIVATE_LOGS_PER_TX * L2_GAS_PER_PRIVATE_LOG, }; // Contract class logs. @@ -143,8 +138,7 @@ fn full_side_effects() { expected_gas_used += Gas { da_gas: (CONTRACT_CLASS_LOG_SIZE_IN_FIELDS + 1) // +1 for the contract address. * MAX_CONTRACT_CLASS_LOGS_PER_TX - * DA_BYTES_PER_FIELD - * DA_GAS_PER_BYTE, + * DA_GAS_PER_FIELD, l2_gas: MAX_CONTRACT_CLASS_LOGS_PER_TX * L2_GAS_PER_CONTRACT_CLASS_LOG, }; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_tail_to_public/meter_gas_used_tests.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_tail_to_public/meter_gas_used_tests.nr index 1ed40c756dd4..fda045e1726b 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_tail_to_public/meter_gas_used_tests.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_kernel_tail_to_public/meter_gas_used_tests.nr @@ -3,11 +3,10 @@ use types::{ abis::gas::Gas, constants::{ AVM_EMITNOTEHASH_BASE_L2_GAS, AVM_EMITNULLIFIER_BASE_L2_GAS, AVM_SENDL2TOL1MSG_BASE_L2_GAS, - CONTRACT_CLASS_LOG_SIZE_IN_FIELDS, DA_BYTES_PER_FIELD, DA_GAS_PER_BYTE, - FIXED_AVM_STARTUP_L2_GAS, L2_GAS_PER_CONTRACT_CLASS_LOG, L2_GAS_PER_PRIVATE_LOG, - MAX_CONTRACT_CLASS_LOGS_PER_TX, MAX_ENQUEUED_CALLS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, - MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_PRIVATE_LOGS_PER_TX, - PRIVATE_LOG_SIZE_IN_FIELDS, + CONTRACT_CLASS_LOG_SIZE_IN_FIELDS, DA_GAS_PER_FIELD, FIXED_AVM_STARTUP_L2_GAS, + L2_GAS_PER_CONTRACT_CLASS_LOG, L2_GAS_PER_PRIVATE_LOG, MAX_CONTRACT_CLASS_LOGS_PER_TX, + MAX_ENQUEUED_CALLS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, + MAX_NULLIFIERS_PER_TX, MAX_PRIVATE_LOGS_PER_TX, PRIVATE_LOG_SIZE_IN_FIELDS, }, }; @@ -16,7 +15,7 @@ use types::{ /// - a public call request, that's what makes it a "public" tx. fn get_minimum_public_tx_gas_used() -> Gas { let nullifier_gas_used = - Gas { da_gas: DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE, l2_gas: AVM_EMITNULLIFIER_BASE_L2_GAS }; + Gas { da_gas: DA_GAS_PER_FIELD, l2_gas: AVM_EMITNULLIFIER_BASE_L2_GAS }; let public_call_gas_used = Gas { da_gas: 0, l2_gas: FIXED_AVM_STARTUP_L2_GAS }; Gas::tx_overhead() + nullifier_gas_used + public_call_gas_used } @@ -75,7 +74,7 @@ fn with_note_hashes() { let num_note_hashes = 2 /* non-revertible */ + 3 /* revertible */; - let da_gas = num_note_hashes * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; + let da_gas = num_note_hashes * DA_GAS_PER_FIELD; let l2_gas = num_note_hashes * AVM_EMITNOTEHASH_BASE_L2_GAS; let expected_gas_used = Gas::new(da_gas, l2_gas) + get_minimum_public_tx_gas_used(); @@ -93,7 +92,7 @@ fn with_nullifiers() { let num_nullifiers = 2 /* non-revertible */ + 3 /* revertible */; - let da_gas = num_nullifiers * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; + let da_gas = num_nullifiers * DA_GAS_PER_FIELD; let l2_gas = num_nullifiers * AVM_EMITNULLIFIER_BASE_L2_GAS; let expected_gas_used = Gas::new(da_gas, l2_gas) + get_minimum_public_tx_gas_used(); @@ -111,7 +110,7 @@ fn with_l2_to_l1_msgs() { let num_msgs = 2 /* non-revertible */ + 3 /* revertible */; - let da_gas = num_msgs * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; + let da_gas = num_msgs * DA_GAS_PER_FIELD; let l2_gas = num_msgs * AVM_SENDL2TOL1MSG_BASE_L2_GAS; let expected_gas_used = Gas::new(da_gas, l2_gas) + get_minimum_public_tx_gas_used(); @@ -133,7 +132,7 @@ fn with_private_logs() { let num_private_logs = 2 /* non-revertible */ + 3 /* revertible */; let num_fields = 4 + 3 + 2 + 6 + 1 + num_private_logs; // +num_private_logs for the length field of each private log. - let da_gas = num_fields * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; + let da_gas = num_fields * DA_GAS_PER_FIELD; let l2_gas = num_private_logs * L2_GAS_PER_PRIVATE_LOG; let expected_gas_used = Gas::new(da_gas, l2_gas) + get_minimum_public_tx_gas_used(); @@ -149,7 +148,7 @@ fn with_non_revertible_contract_class_logs() { let num_logs = 1; let num_fields = 12 + 1; // +1 for the contract address. - let da_gas = num_fields * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; + let da_gas = num_fields * DA_GAS_PER_FIELD; let l2_gas = num_logs * L2_GAS_PER_CONTRACT_CLASS_LOG; let expected_gas_used = Gas::new(da_gas, l2_gas) + get_minimum_public_tx_gas_used(); @@ -166,7 +165,7 @@ fn with_revertible_contract_class_logs() { let num_logs = 1; let num_fields = 12 + 1; // +1 for the contract address. - let da_gas = num_fields * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; + let da_gas = num_fields * DA_GAS_PER_FIELD; let l2_gas = num_logs * L2_GAS_PER_CONTRACT_CLASS_LOG; let expected_gas_used = Gas::new(da_gas, l2_gas) + get_minimum_public_tx_gas_used(); @@ -230,7 +229,7 @@ fn full_side_effects() { + MAX_L2_TO_L1_MSGS_PER_TX + (PRIVATE_LOG_SIZE_IN_FIELDS + 1) * MAX_PRIVATE_LOGS_PER_TX // +1 for the length field of each private log. + (CONTRACT_CLASS_LOG_SIZE_IN_FIELDS + 1) * MAX_CONTRACT_CLASS_LOGS_PER_TX; // +1 for the contract address. - let da_gas = num_da_fields * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; + let da_gas = num_da_fields * DA_GAS_PER_FIELD; let l2_gas = MAX_NOTE_HASHES_PER_TX * AVM_EMITNOTEHASH_BASE_L2_GAS + MAX_NULLIFIERS_PER_TX * AVM_EMITNULLIFIER_BASE_L2_GAS + MAX_L2_TO_L1_MSGS_PER_TX * AVM_SENDL2TOL1MSG_BASE_L2_GAS 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 cb4e3cfac8d1..c0ba749b920a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -1036,9 +1036,10 @@ pub global AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED: u32 = 1000; pub global AVM_MAX_PROCESSABLE_L2_GAS: u32 = 6_000_000; // Arbitrary. pub global DA_BYTES_PER_FIELD: u32 = 32; -pub global DA_GAS_PER_BYTE: u32 = 16; // TODO: Explain this, might be arbitrary? maybe make it one? and sync it wit the tx overhead constants? -// pays for preamble information in TX Effects -pub global FIXED_DA_GAS: u32 = 512; +pub global DA_GAS_PER_BYTE: u32 = 1; // Arbitrary. +pub global DA_GAS_PER_FIELD: u32 = DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; +// A tx always emits 3 fields: tx_start_marker, tx_hash, and tx_fee. +pub global FIXED_DA_GAS: u32 = 3 * DA_GAS_PER_FIELD; // TODO: take into account the cost of executing and proving the rollup circuits (if they can be attributed to this tx... eg the tx base rollup, half a tx merge). // We need a test suite to demonstrate these measurements // pays for fixed tx costs like validation, and updating state roots @@ -1047,7 +1048,7 @@ pub global FIXED_L2_GAS: u32 = 512; pub global FIXED_AVM_STARTUP_L2_GAS: u32 = 20_000; pub global MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT: u32 = - BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; + BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB * DA_GAS_PER_FIELD; // For gas estimation, we use the theoretical maximum amounts. // Since we split in teardown and total, teardown has the theoretical maximum and total is that times 2. @@ -1065,7 +1066,7 @@ pub global GAS_ESTIMATION_DA_GAS_LIMIT: u32 = // TODO: consider moving to typescript pub global DEFAULT_TEARDOWN_L2_GAS_LIMIT: u32 = 1_000_000; // Arbitrary default number. pub global DEFAULT_L2_GAS_LIMIT: u32 = AVM_MAX_PROCESSABLE_L2_GAS; // Arbitrary default number. -pub global DEFAULT_TEARDOWN_DA_GAS_LIMIT: u32 = 1_000_000; // Arbitrary default number. +pub global DEFAULT_TEARDOWN_DA_GAS_LIMIT: u32 = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT / 2; // Arbitrary default number. pub global DEFAULT_DA_GAS_LIMIT: u32 = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT; // Arbitrary default number. // Some tree insertions incur an additional cost associated with @@ -1156,16 +1157,16 @@ pub global AVM_BITWISE_DYN_L2_GAS: u32 = 3; // One row per byte pub global AVM_EMITPUBLICLOG_DYN_L2_GAS: u32 = 3; // Base DA Gas -pub global AVM_EMITNOTEHASH_BASE_DA_GAS: u32 = DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; -pub global AVM_EMITNULLIFIER_BASE_DA_GAS: u32 = DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; -pub global AVM_SENDL2TOL1MSG_BASE_DA_GAS: u32 = DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; -pub global AVM_EMITPUBLICLOG_BASE_DA_GAS: u32 = 2 * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; // length and address +pub global AVM_EMITNOTEHASH_BASE_DA_GAS: u32 = DA_GAS_PER_FIELD; +pub global AVM_EMITNULLIFIER_BASE_DA_GAS: u32 = DA_GAS_PER_FIELD; +pub global AVM_SENDL2TOL1MSG_BASE_DA_GAS: u32 = DA_GAS_PER_FIELD; +pub global AVM_EMITPUBLICLOG_BASE_DA_GAS: u32 = 2 * DA_GAS_PER_FIELD; // length and address // Dynamic DA Gas // a single increment here corresponds to an entire additional field (hence x32 bytes per field) -pub global AVM_EMITPUBLICLOG_DYN_DA_GAS: u32 = DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; +pub global AVM_EMITPUBLICLOG_DYN_DA_GAS: u32 = DA_GAS_PER_FIELD; // Gets multiplied by 1 if actually publishing, 0 if not. 2 because of it being (slot, value) pair -pub global AVM_SSTORE_DYN_DA_GAS: u32 = 2 * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; +pub global AVM_SSTORE_DYN_DA_GAS: u32 = 2 * DA_GAS_PER_FIELD; // BLOB PREFIXES // Used when decoding blobs of tightly packed effects diff --git a/yarn-project/constants/src/constants.gen.ts b/yarn-project/constants/src/constants.gen.ts index 9f5c2b759929..ddc691f25053 100644 --- a/yarn-project/constants/src/constants.gen.ts +++ b/yarn-project/constants/src/constants.gen.ts @@ -387,19 +387,20 @@ export const AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED = 16400; export const AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED = 1000; export const AVM_MAX_PROCESSABLE_L2_GAS = 6000000; export const DA_BYTES_PER_FIELD = 32; -export const DA_GAS_PER_BYTE = 16; -export const FIXED_DA_GAS = 512; +export const DA_GAS_PER_BYTE = 1; +export const DA_GAS_PER_FIELD = 32; +export const FIXED_DA_GAS = 96; export const FIXED_L2_GAS = 512; export const FIXED_AVM_STARTUP_L2_GAS = 20000; -export const MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT = 12582912; +export const MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT = 786432; export const GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT = 6000000; export const GAS_ESTIMATION_L2_GAS_LIMIT = 12000000; -export const GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT = 12582912; -export const GAS_ESTIMATION_DA_GAS_LIMIT = 25165824; +export const GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT = 786432; +export const GAS_ESTIMATION_DA_GAS_LIMIT = 1572864; export const DEFAULT_TEARDOWN_L2_GAS_LIMIT = 1000000; export const DEFAULT_L2_GAS_LIMIT = 6000000; -export const DEFAULT_TEARDOWN_DA_GAS_LIMIT = 1000000; -export const DEFAULT_DA_GAS_LIMIT = 12582912; +export const DEFAULT_TEARDOWN_DA_GAS_LIMIT = 393216; +export const DEFAULT_DA_GAS_LIMIT = 786432; export const L2_GAS_DISTRIBUTED_STORAGE_PREMIUM = 1024; export const AVM_PC_SIZE_IN_BITS = 32; export const AVM_MAX_OPERANDS = 7; @@ -463,12 +464,12 @@ export const AVM_RETURNDATACOPY_DYN_L2_GAS = 3; export const AVM_TORADIXBE_DYN_L2_GAS = 3; export const AVM_BITWISE_DYN_L2_GAS = 3; export const AVM_EMITPUBLICLOG_DYN_L2_GAS = 3; -export const AVM_EMITNOTEHASH_BASE_DA_GAS = 512; -export const AVM_EMITNULLIFIER_BASE_DA_GAS = 512; -export const AVM_SENDL2TOL1MSG_BASE_DA_GAS = 512; -export const AVM_EMITPUBLICLOG_BASE_DA_GAS = 1024; -export const AVM_EMITPUBLICLOG_DYN_DA_GAS = 512; -export const AVM_SSTORE_DYN_DA_GAS = 1024; +export const AVM_EMITNOTEHASH_BASE_DA_GAS = 32; +export const AVM_EMITNULLIFIER_BASE_DA_GAS = 32; +export const AVM_SENDL2TOL1MSG_BASE_DA_GAS = 32; +export const AVM_EMITPUBLICLOG_BASE_DA_GAS = 64; +export const AVM_EMITPUBLICLOG_DYN_DA_GAS = 32; +export const AVM_SSTORE_DYN_DA_GAS = 64; export const TX_START_PREFIX = 2624615704; export const BLOCK_END_PREFIX = 3951939007; export const CHECKPOINT_END_PREFIX = 2355328067; diff --git a/yarn-project/p2p/src/mem_pools/tx_pool_v2/tx_pool_v2.test.ts b/yarn-project/p2p/src/mem_pools/tx_pool_v2/tx_pool_v2.test.ts index 278cc846f162..54f557b26277 100644 --- a/yarn-project/p2p/src/mem_pools/tx_pool_v2/tx_pool_v2.test.ts +++ b/yarn-project/p2p/src/mem_pools/tx_pool_v2/tx_pool_v2.test.ts @@ -25,6 +25,11 @@ import { AztecKVTxPoolV2 } from './tx_pool_v2.js'; // Tx type alias for cleaner type annotations type MockTx = Awaited>; +// Default maxFeesPerGas used by mockTx is GasFees(10, 10). +// Fee limit per tx = DEFAULT_L2_GAS_LIMIT * 10 + DEFAULT_DA_GAS_LIMIT * 10. +const DEFAULT_MAX_FEES_PER_GAS = new GasFees(10, 10); +const DEFAULT_TX_FEE_LIMIT = GasSettings.default({ maxFeesPerGas: DEFAULT_MAX_FEES_PER_GAS }).getFeeLimit().toBigInt(); + /** A validator that accepts all transactions. Used in tests that don't need validation. */ const alwaysValidValidator: TxValidator = { validateTx: () => Promise.resolve({ result: 'valid' }), @@ -944,7 +949,7 @@ describe('TxPoolV2', () => { it('pre-protected tx does not trigger post-add eviction rules', async () => { const sharedFeePayer = AztecAddress.fromBigInt(999n); // Balance covers only one tx - setFeePayerBalanceForPreProtect(BigInt(2e8)); + setFeePayerBalanceForPreProtect(DEFAULT_TX_FEE_LIMIT + DEFAULT_TX_FEE_LIMIT / 2n); // Add a pending tx first const txPending = await mockTx(1, { @@ -2686,9 +2691,8 @@ describe('TxPoolV2', () => { it('high priority tx evicts lower priority tx from same fee payer', async () => { const sharedFeePayer = AztecAddress.fromBigInt(999n); - // Fee limit per tx is ~186M (DEFAULT_L2_GAS_LIMIT * 10 + DEFAULT_DA_GAS_LIMIT * 10) // Set balance to cover only one tx - setFeePayerBalance(BigInt(2e8)); + setFeePayerBalance(DEFAULT_TX_FEE_LIMIT + DEFAULT_TX_FEE_LIMIT / 2n); // Add low priority tx first const txLow = await mockTx(1, { @@ -2717,7 +2721,7 @@ describe('TxPoolV2', () => { it('low priority tx ignored when fee payer balance exhausted by existing tx', async () => { const sharedFeePayer = AztecAddress.fromBigInt(999n); // Balance covers only one tx - setFeePayerBalance(BigInt(2e8)); + setFeePayerBalance(DEFAULT_TX_FEE_LIMIT + DEFAULT_TX_FEE_LIMIT / 2n); // Add high priority tx first const txHigh = await mockTx(1, { @@ -2744,8 +2748,8 @@ describe('TxPoolV2', () => { it('batch from same fee payer - only top N by priority accepted', async () => { const sharedFeePayer = AztecAddress.fromBigInt(999n); - // Balance covers exactly 2 tx fee limits (~372M for 2 txs) - setFeePayerBalance(BigInt(4e8)); + // Balance covers exactly 2 tx fee limits + setFeePayerBalance(DEFAULT_TX_FEE_LIMIT * 2n + DEFAULT_TX_FEE_LIMIT / 2n); // Add 3 txs in one batch, all from same fee payer const tx1 = await mockTx(1, { @@ -2793,7 +2797,7 @@ describe('TxPoolV2', () => { it('evicts low-priority txs after BLOCK_MINED when balance is insufficient', async () => { const sharedFeePayer = AztecAddress.fromBigInt(999n); // Initial balance covers all 3 txs - setFeePayerBalance(BigInt(6e8)); + setFeePayerBalance(DEFAULT_TX_FEE_LIMIT * 3n + DEFAULT_TX_FEE_LIMIT / 2n); // Add three txs from same fee payer const txLow = await mockTx(1, { @@ -2817,7 +2821,7 @@ describe('TxPoolV2', () => { // Simulate block mined that reduced fee payer's balance // After mining txHigh, balance only covers one more tx - setFeePayerBalance(BigInt(2e8)); + setFeePayerBalance(DEFAULT_TX_FEE_LIMIT + DEFAULT_TX_FEE_LIMIT / 2n); // Mine the highest priority tx - this triggers balance check for sharedFeePayer // The fee payer balance rule will check remaining pending txs from this fee payer @@ -2834,7 +2838,7 @@ describe('TxPoolV2', () => { it('evicts low-priority txs after CHAIN_PRUNED when balance is insufficient', async () => { const sharedFeePayer = AztecAddress.fromBigInt(999n); // Initial balance covers both txs - setFeePayerBalance(BigInt(4e8)); + setFeePayerBalance(DEFAULT_TX_FEE_LIMIT * 2n + DEFAULT_TX_FEE_LIMIT / 2n); db.findLeafIndices.mockResolvedValue([1n]); // Anchor blocks valid @@ -2856,7 +2860,7 @@ describe('TxPoolV2', () => { expect(await pool.getTxStatus(txHigh.getTxHash())).toBe('mined'); // Simulate reorg - balance reduced (e.g., another tx was restored) - setFeePayerBalance(BigInt(2e8)); // Only enough for one tx + setFeePayerBalance(DEFAULT_TX_FEE_LIMIT + DEFAULT_TX_FEE_LIMIT / 2n); // Only enough for one tx await pool.handlePrunedBlocks(block0Id); @@ -2868,7 +2872,7 @@ describe('TxPoolV2', () => { it('priority ordering is correct - highest priority funded first', async () => { const sharedFeePayer = AztecAddress.fromBigInt(999n); // Initial balance covers all 3 txs - setFeePayerBalance(BigInt(6e8)); + setFeePayerBalance(DEFAULT_TX_FEE_LIMIT * 3n + DEFAULT_TX_FEE_LIMIT / 2n); db.findLeafIndices.mockResolvedValue([1n]); // Anchor blocks valid @@ -2894,7 +2898,7 @@ describe('TxPoolV2', () => { await pool.handleMinedBlock(makeBlock([txPriority1, txPriority5, txPriority10], slot1Header)); // Reduce balance to only cover 2 txs before reorg - setFeePayerBalance(BigInt(4e8)); + setFeePayerBalance(DEFAULT_TX_FEE_LIMIT * 2n + DEFAULT_TX_FEE_LIMIT / 2n); // Reorg - triggers balance eviction await pool.handlePrunedBlocks(block0Id); @@ -3881,7 +3885,11 @@ describe('TxPoolV2', () => { db.getLeafPreimage.mockImplementation((tree, index) => { if (tree === MerkleTreeId.PUBLIC_DATA_TREE) { return Promise.resolve( - new PublicDataTreeLeafPreimage(new PublicDataTreeLeaf(new Fr(index), new Fr(BigInt(2e8))), Fr.ONE, 1n), + new PublicDataTreeLeafPreimage( + new PublicDataTreeLeaf(new Fr(index), new Fr(DEFAULT_TX_FEE_LIMIT + DEFAULT_TX_FEE_LIMIT / 2n)), + Fr.ONE, + 1n, + ), ); } return Promise.resolve(undefined); diff --git a/yarn-project/pxe/src/contract_function_simulator/contract_function_simulator.ts b/yarn-project/pxe/src/contract_function_simulator/contract_function_simulator.ts index 219b459f7542..488fa554df73 100644 --- a/yarn-project/pxe/src/contract_function_simulator/contract_function_simulator.ts +++ b/yarn-project/pxe/src/contract_function_simulator/contract_function_simulator.ts @@ -2,8 +2,7 @@ import { AVM_EMITNOTEHASH_BASE_L2_GAS, AVM_EMITNULLIFIER_BASE_L2_GAS, AVM_SENDL2TOL1MSG_BASE_L2_GAS, - DA_BYTES_PER_FIELD, - DA_GAS_PER_BYTE, + DA_GAS_PER_FIELD, FIXED_AVM_STARTUP_L2_GAS, FIXED_DA_GAS, FIXED_L2_GAS, @@ -818,7 +817,7 @@ function meterGasUsed(data: PrivateToRollupAccumulatedData | PrivateToPublicAccu ); meteredL2Gas += numContractClassLogs * L2_GAS_PER_CONTRACT_CLASS_LOG; - const meteredDAGas = meteredDAFields * DA_BYTES_PER_FIELD * DA_GAS_PER_BYTE; + const meteredDAGas = meteredDAFields * DA_GAS_PER_FIELD; if ((data as PrivateToPublicAccumulatedData).publicCallRequests) { const dataForPublic = data as PrivateToPublicAccumulatedData;