Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const std::vector<ScopedL2ToL1Message> REVERTIBLE_ACCUMULATED_DATA_L2_TO_L1_MESS
const std::vector<PublicCallRequestWithCalldata> SETUP_ENQUEUED_CALLS = {};
const FF MSG_SENDER = 100;
const std::optional<PublicCallRequestWithCalldata> TEARDOWN_ENQUEUED_CALLS = std::nullopt;
const Gas GAS_USED_BY_PRIVATE = Gas{ .l2_gas = 0, .da_gas = 0 };
const Gas GAS_USED_BY_PRIVATE = Gas{ .l2_gas = PUBLIC_TX_L2_GAS_OVERHEAD, .da_gas = TX_DA_GAS_OVERHEAD };
const AztecAddress FEE_PAYER = AztecAddress{ 0 };
const FF CONTRACT_ADDRESS = 42;
const FF TRANSACTION_FEE = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void mutate_tx(Tx& tx, std::vector<AztecAddress>& contract_addresses, std::mt199
case TxMutationOptions::GasUsedByPrivate:
// Mutate gas_used_by_private
fuzz_info("Mutating gas used by private");
mutate_gas(tx.gas_used_by_private, rng, tx.gas_settings.gas_limits);
mutate_gas(tx.gas_used_by_private, rng, GAS_USED_BY_PRIVATE, tx.gas_settings.gas_limits);
break;
case TxMutationOptions::FeePayer:
// Mutate fee_payer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ uint128_t generate_u128(std::mt19937_64& rng, uint128_t min = 0, uint128_t max =

namespace bb::avm2::fuzzer {

Gas generate_gas(std::mt19937_64& rng)
Gas generate_gas(std::mt19937_64& rng, const Gas& min, const Gas& max)
{
uint32_t l2_gas = std::uniform_int_distribution<uint32_t>(MIN_GAS, AVM_MAX_PROCESSABLE_L2_GAS)(rng);
uint32_t da_gas = std::uniform_int_distribution<uint32_t>(MIN_GAS, AVM_MAX_PROCESSABLE_DA_GAS)(rng);
uint32_t l2_gas = std::uniform_int_distribution<uint32_t>(min.l2_gas, max.l2_gas)(rng);
uint32_t da_gas = std::uniform_int_distribution<uint32_t>(min.da_gas, max.da_gas)(rng);

return Gas{ l2_gas, da_gas };
}

void mutate_gas(Gas& gas, std::mt19937_64& rng, const Gas& max)
void mutate_gas(Gas& gas, std::mt19937_64& rng, const Gas& min, const Gas& max)
{
auto choice = std::uniform_int_distribution<uint8_t>(0, 1)(rng);

switch (choice) {
case 0:
// Mutate l2_gas
gas.l2_gas = std::uniform_int_distribution<uint32_t>(MIN_GAS, max.l2_gas)(rng);
gas.l2_gas = std::uniform_int_distribution<uint32_t>(min.l2_gas, max.l2_gas)(rng);
break;
case 1:
// Mutate da_gas
gas.da_gas = std::uniform_int_distribution<uint32_t>(MIN_GAS, max.da_gas)(rng);
gas.da_gas = std::uniform_int_distribution<uint32_t>(min.da_gas, max.da_gas)(rng);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ constexpr uint128_t MIN_FEE = 1;
constexpr uint128_t MAX_FEE = 1000;
//
// Gas bounds for mutation
constexpr uint32_t MIN_GAS = 0;
constexpr uint32_t AVM_MAX_PROCESSABLE_DA_GAS = (MAX_NOTE_HASHES_PER_TX * AVM_EMITNOTEHASH_BASE_DA_GAS) +
(MAX_NULLIFIERS_PER_TX * AVM_EMITNULLIFIER_BASE_DA_GAS) +
(MAX_L2_TO_L1_MSGS_PER_TX * AVM_SENDL2TOL1MSG_BASE_DA_GAS) +
(MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * AVM_SSTORE_DYN_DA_GAS) +
(PUBLIC_LOGS_LENGTH * AVM_EMITPUBLICLOG_BASE_DA_GAS);
constexpr uint32_t MAX_PROCESSABLE_DA_GAS = TX_DA_GAS_OVERHEAD +
(MAX_NOTE_HASHES_PER_TX * AVM_EMITNOTEHASH_BASE_DA_GAS) +
(MAX_NULLIFIERS_PER_TX * AVM_EMITNULLIFIER_BASE_DA_GAS) +
(MAX_L2_TO_L1_MSGS_PER_TX * AVM_SENDL2TOL1MSG_BASE_DA_GAS) +
(MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * AVM_SSTORE_DYN_DA_GAS) +
(PUBLIC_LOGS_LENGTH * AVM_EMITPUBLICLOG_BASE_DA_GAS);
constexpr Gas MAX_GAS_LIMIT = Gas{ .l2_gas = MAX_PROCESSABLE_L2_GAS, .da_gas = MAX_PROCESSABLE_DA_GAS };

enum class GasSettingsMutationOptions : uint8_t {
GasLimits,
Expand All @@ -38,10 +39,8 @@ constexpr GasSettingsMutationConfig GAS_SETTINGS_MUTATION_CONFIGURATION = GasSet
{ GasSettingsMutationOptions::MaxPriorityFeesPerGas, 5 },
});

Gas generate_gas(std::mt19937_64& rng);
void mutate_gas(Gas& gas,
std::mt19937_64& rng,
const Gas& max = Gas{ AVM_MAX_PROCESSABLE_L2_GAS, AVM_MAX_PROCESSABLE_DA_GAS });
Gas generate_gas(std::mt19937_64& rng, const Gas& min = {}, const Gas& max = MAX_GAS_LIMIT);
void mutate_gas(Gas& gas, std::mt19937_64& rng, const Gas& min = {}, const Gas& max = MAX_GAS_LIMIT);

GasSettings generate_gas_settings(std::mt19937_64& rng);
void mutate_gas_settings(GasSettings& data, std::mt19937_64& rng);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@
#define AVM_PUBLIC_INPUTS_COLUMNS_COMBINED_LENGTH 18740
#define AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED 16400
#define AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED 1000
#define TX_DA_GAS_OVERHEAD 96
#define PUBLIC_TX_L2_GAS_OVERHEAD 540000
#define AVM_MAX_PROCESSABLE_L2_GAS 6000000
#define MAX_PROCESSABLE_L2_GAS 6540000
#define AVM_PC_SIZE_IN_BITS 32
#define AVM_MAX_OPERANDS 7
#define AVM_MAX_REGISTERS 6
Expand Down Expand Up @@ -221,7 +224,7 @@
#define AVM_L1TOL2MSGEXISTS_BASE_L2_GAS 540
#define AVM_GETCONTRACTINSTANCE_BASE_L2_GAS 6108
#define AVM_EMITPUBLICLOG_BASE_L2_GAS 15
#define AVM_SENDL2TOL1MSG_BASE_L2_GAS 478
#define AVM_SENDL2TOL1MSG_BASE_L2_GAS 5239
#define AVM_CALL_BASE_L2_GAS 9936
#define AVM_STATICCALL_BASE_L2_GAS 9936
#define AVM_RETURN_BASE_L2_GAS 9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("0x02296b934ced1a5cdacae120d2032d88a119bdb0738d4c4f3ada4f5a831a5153")); }
static FF vk_hash() { return FF(uint256_t("0x18952f5711d5f7a6e29c980f1077eecd2ec45e80ba0ae78d5a4ae08e50428cab")); }

static constexpr std::array<Commitment, NUM_PRECOMPUTED_ENTITIES> get_all()
{
Expand Down Expand Up @@ -71,9 +71,9 @@ class AvmHardCodedVKAndHash {
uint256_t(
"0x090dda25e7d64ab5cabe09fd80fbb731af2a98de7a608157dc10394b4fc022a4")), // precomputed_exec_opcode_dynamic_l2_gas
Commitment(
uint256_t("0x2216a1693dcb1cc83f57ea8058f681d71bdf0e6cfc839502cf16fb0a88a5f673"),
uint256_t("0x26086b5fb31a24f236f0441d5b922b94ca141e861b9cc640184681c518cd68d3"),
uint256_t(
"0x255e6760ed9adda61aca7d0b7d4bb28bb62e3cca6e860009461a9a1708184be2")), // precomputed_exec_opcode_opcode_gas
"0x0bab134bb4e25ff33584c1094847e762ce6573054bae27715d0e4eb2b7278d80")), // precomputed_exec_opcode_opcode_gas
Commitment(
uint256_t("0x296def9415d1c96b4d8ab91df5f59ad8522a726f98461b1ab5c4d4c5b22471a4"),
uint256_t(
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,11 @@ pub fn meter_gas_used(public_inputs: PrivateKernelCircuitPublicInputs, is_for_pu

let metered_da_gas = metered_da_fields * DA_GAS_PER_FIELD;

Gas::tx_overhead() + Gas::new(metered_da_gas, metered_l2_gas) + teardown_gas
let overhead = if is_for_public {
Gas::public_tx_overhead()
} else {
Gas::private_tx_overhead()
};

overhead + Gas::new(metered_da_gas, metered_l2_gas) + teardown_gas
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use types::{
/// 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_GAS_PER_FIELD, l2_gas: L2_GAS_PER_NULLIFIER };
Gas::tx_overhead() + nullifier_gas_used
Gas::private_tx_overhead() + nullifier_gas_used
}

#[test]
Expand Down Expand Up @@ -100,7 +100,7 @@ fn full_side_effects() {
let mut builder = TestBuilder::new();

// Fill the tx with side effects and compute the expected gas used.
let mut expected_gas_used = Gas::tx_overhead();
let mut expected_gas_used = Gas::private_tx_overhead();
// Note hashes.
builder.previous_kernel.append_siloed_note_hashes(MAX_NOTE_HASHES_PER_TX);
expected_gas_used += Gas {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn get_minimum_public_tx_gas_used() -> Gas {
let nullifier_gas_used =
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
Gas::public_tx_overhead() + nullifier_gas_used + public_call_gas_used
}

#[test]
Expand Down Expand Up @@ -236,7 +236,8 @@ fn full_side_effects() {
+ MAX_PRIVATE_LOGS_PER_TX * L2_GAS_PER_PRIVATE_LOG
+ MAX_CONTRACT_CLASS_LOGS_PER_TX * L2_GAS_PER_CONTRACT_CLASS_LOG
+ MAX_ENQUEUED_CALLS_PER_TX * FIXED_AVM_STARTUP_L2_GAS;
let expected_gas_used = Gas::tx_overhead() + Gas::new(da_gas, l2_gas) + teardown_gas_limits;
let expected_gas_used =
Gas::public_tx_overhead() + Gas::new(da_gas, l2_gas) + teardown_gas_limits;

let public_inputs = builder.execute();
assert_eq(public_inputs.gas_used, expected_gas_used);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use types::{
log_hash::LogHash, tx_constant_data::TxConstantData,
},
constants::{
ARCHIVE_HEIGHT, AVM_MAX_PROCESSABLE_L2_GAS, CONTRACT_CLASS_LOG_SIZE_IN_FIELDS,
MAX_CONTRACT_CLASS_LOGS_PER_TX,
ARCHIVE_HEIGHT, CONTRACT_CLASS_LOG_SIZE_IN_FIELDS, MAX_CONTRACT_CLASS_LOGS_PER_TX,
MAX_PROCESSABLE_L2_GAS,
},
hash::compute_contract_class_log_hash,
merkle_tree::{check_membership, MembershipWitness},
Expand Down Expand Up @@ -101,10 +101,9 @@ pub fn validate_tx_constant_data(
);

// Ensure that the l2 gas limit is within the max processable l2 gas.
// The constant is prefixed with `AVM_` but it applies to both private-only and public-inclusive txs.
// TODO: This should be moved to the private kernels once they are not used for gas estimation anymore.
assert(
tx_gas_settings.gas_limits.l2_gas <= AVM_MAX_PROCESSABLE_L2_GAS,
tx_gas_settings.gas_limits.l2_gas <= MAX_PROCESSABLE_L2_GAS,
"l2 gas limit exceeds max processable l2 gas",
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::TestBuilder;
use types::{constants::AVM_MAX_PROCESSABLE_L2_GAS, tests::fixture_builder::FixtureBuilder};
use types::{constants::MAX_PROCESSABLE_L2_GAS, tests::fixture_builder::FixtureBuilder};

#[test(should_fail_with = "Membership check failed: anchor block header hash not found in archive tree")]
unconstrained fn anchor_block_header_not_in_archive() {
Expand Down Expand Up @@ -62,7 +62,7 @@ unconstrained fn gas_settings_l2_gas_limit_exceeds_max_processable_l2_gas() {
let mut builder = TestBuilder::new();

builder.private_tail.constants.tx_context.gas_settings.gas_limits.l2_gas =
AVM_MAX_PROCESSABLE_L2_GAS + 1;
MAX_PROCESSABLE_L2_GAS + 1;

builder.execute_and_fail();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::TestBuilder;
use types::{constants::AVM_MAX_PROCESSABLE_L2_GAS, tests::fixture_builder::FixtureBuilder};
use types::{constants::MAX_PROCESSABLE_L2_GAS, tests::fixture_builder::FixtureBuilder};

#[test(should_fail_with = "Membership check failed: anchor block header hash not found in archive tree")]
unconstrained fn anchor_block_header_not_in_archive() {
Expand Down Expand Up @@ -53,7 +53,7 @@ unconstrained fn gas_settings_l2_gas_limit_exceeds_max_processable_l2_gas() {
let mut builder = TestBuilder::new();

builder.private_tail.constants.tx_context.gas_settings.gas_limits.l2_gas =
AVM_MAX_PROCESSABLE_L2_GAS + 1;
MAX_PROCESSABLE_L2_GAS + 1;

builder.execute_and_fail();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
abis::gas_fees::GasFees,
constants::{FIXED_DA_GAS, FIXED_L2_GAS},
constants::{PRIVATE_TX_L2_GAS_OVERHEAD, PUBLIC_TX_L2_GAS_OVERHEAD, TX_DA_GAS_OVERHEAD},
traits::{Deserialize, Empty, Serialize},
};
use std::{meta::derive, ops::{Add, Sub}};
Expand All @@ -16,8 +16,12 @@ impl Gas {
Self { da_gas, l2_gas }
}

pub fn tx_overhead() -> Self {
Self { da_gas: FIXED_DA_GAS, l2_gas: FIXED_L2_GAS }
pub fn private_tx_overhead() -> Self {
Self { da_gas: TX_DA_GAS_OVERHEAD, l2_gas: PRIVATE_TX_L2_GAS_OVERHEAD }
}

pub fn public_tx_overhead() -> Self {
Self { da_gas: TX_DA_GAS_OVERHEAD, l2_gas: PUBLIC_TX_L2_GAS_OVERHEAD }
}

pub fn compute_fee(self, fees: GasFees) -> Field {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,31 +1032,32 @@ pub global AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED: u32 = 16400;
pub global AVM_V2_VERIFICATION_KEY_LENGTH_IN_FIELDS_PADDED: u32 = 1000;

// GAS DEFAULTS
// The maximum amount of l2 gas that the AVM can process safely.
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 = 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
pub global FIXED_L2_GAS: u32 = 512;
pub global TX_DA_GAS_OVERHEAD: u32 = 3 * DA_GAS_PER_FIELD;
// Computed taking into account simulation time metrics.
pub global PUBLIC_TX_L2_GAS_OVERHEAD: u32 = 540000;
pub global PRIVATE_TX_L2_GAS_OVERHEAD: u32 = 440000;
// base cost for a single public call
pub global FIXED_AVM_STARTUP_L2_GAS: u32 = 20_000;

// The maximum amount of l2 gas that the AVM can process safely.
pub global AVM_MAX_PROCESSABLE_L2_GAS: u32 = 6_000_000; // Arbitrary.
// The following limit assumes that a private only tx will always be cheaper than a tx with a full public component.
pub global MAX_PROCESSABLE_L2_GAS: u32 = PUBLIC_TX_L2_GAS_OVERHEAD + AVM_MAX_PROCESSABLE_L2_GAS;

pub global MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT: u32 =
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.
// After gas estimation, we tune it down to the actual amount necessary.
// TODO: this is a wallet concern; it should not be part of the protocol
pub global GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT: u32 = AVM_MAX_PROCESSABLE_L2_GAS;
pub global GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT: u32 = MAX_PROCESSABLE_L2_GAS;
pub global GAS_ESTIMATION_L2_GAS_LIMIT: u32 =
GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT + AVM_MAX_PROCESSABLE_L2_GAS;
GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT + MAX_PROCESSABLE_L2_GAS;

pub global GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT: u32 = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT;
pub global GAS_ESTIMATION_DA_GAS_LIMIT: u32 =
Expand All @@ -1065,7 +1066,7 @@ pub global GAS_ESTIMATION_DA_GAS_LIMIT: u32 =
// Default gas limits. Users should use gas estimation, or they will overpay gas fees.
// 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_L2_GAS_LIMIT: u32 = MAX_PROCESSABLE_L2_GAS; // 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.

Expand All @@ -1089,14 +1090,12 @@ pub global AVM_ADDRESSING_INDIRECT_L2_GAS: u32 = 3; // One mem access
pub global AVM_ADDRESSING_RELATIVE_L2_GAS: u32 = 3; // One range check

// Base L2 GAS
// TODO: Decide what the following constants should be.
pub global L2_GAS_PER_NOTE_HASH: u32 = 0;
pub global L2_GAS_PER_NULLIFIER: u32 = 0;
// Gas for writing message to L1 portal
pub global L2_GAS_PER_L2_TO_L1_MSG: u32 = 200; // TODO: Update and explain this.
// Zero gas because we don't have to hash and validate the private logs
pub global L2_GAS_PER_PRIVATE_LOG: u32 = 0;
pub global L2_GAS_PER_CONTRACT_CLASS_LOG: u32 = 0; // TODO: this should be nonzero, because the sequencer is doing work to hash this, as part of tx validation
// Based on simulation time metrics
pub global L2_GAS_PER_NOTE_HASH: u32 = 2700;
pub global L2_GAS_PER_NULLIFIER: u32 = 16000;
pub global L2_GAS_PER_L2_TO_L1_MSG: u32 = 5200;
pub global L2_GAS_PER_PRIVATE_LOG: u32 = 2500;
pub global L2_GAS_PER_CONTRACT_CLASS_LOG: u32 = 73000;
// Note: magic numbers here are derived from each op's AVM circuit trace area
// https://docs.google.com/spreadsheets/d/1FPyLfJFPOfZTmZC-T6b_4yB5dSrOAofz3dufte23_TA/edit?usp=sharing
// Some have a "SLOW_SIM_MUL" multiplier because they are slower to simulate and their trace-area-derived gas cost
Expand Down Expand Up @@ -1136,7 +1135,7 @@ pub global AVM_EMITNULLIFIER_BASE_L2_GAS: u32 = (516 + L2_GAS_DISTRIBUTED_STORAG
pub global AVM_L1TOL2MSGEXISTS_BASE_L2_GAS: u32 = 108 * 5; // SLOW_SIM_MUL = 4 (+1 for slow proving)
pub global AVM_GETCONTRACTINSTANCE_BASE_L2_GAS: u32 = 1527 * 4; // SLOW_SIM_MUL = 4
pub global AVM_EMITPUBLICLOG_BASE_L2_GAS: u32 = 15;
pub global AVM_SENDL2TOL1MSG_BASE_L2_GAS: u32 = (39 + L2_GAS_PER_L2_TO_L1_MSG) * 2; // SLOW_SIM_MUL = 2
pub global AVM_SENDL2TOL1MSG_BASE_L2_GAS: u32 = 39 + L2_GAS_PER_L2_TO_L1_MSG;
// See PR https://github.com/AztecProtocol/aztec-packages/pull/15495 on why we need this buffer.
pub global AVM_CALL_BASE_L2_GAS: u32 = 3312 * 3; // SLOW_SIM_MUL = 3
pub global AVM_STATICCALL_BASE_L2_GAS: u32 = 3312 * 3; // SLOW_SIM_MUL = 3
Expand Down
16 changes: 8 additions & 8 deletions yarn-project/aztec.js/src/contract/get_gas_limits.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
import { MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
import { Gas } from '@aztec/stdlib/gas';
import { mockSimulatedTx, mockTxForRollup } from '@aztec/stdlib/testing';
import type { TxSimulationResult } from '@aztec/stdlib/tx';
Expand Down Expand Up @@ -50,19 +50,19 @@ describe('getGasLimits', () => {
it('should fail if gas exceeds max processable gas', () => {
// Consumes all of processable gas
txSimulationResult.publicOutput!.gasUsed = {
totalGas: Gas.from({ daGas: 140, l2Gas: AVM_MAX_PROCESSABLE_L2_GAS }),
billedGas: Gas.from({ daGas: 150, l2Gas: AVM_MAX_PROCESSABLE_L2_GAS }),
teardownGas: Gas.from({ daGas: 10, l2Gas: AVM_MAX_PROCESSABLE_L2_GAS * 0.2 }),
publicGas: Gas.from({ daGas: 50, l2Gas: AVM_MAX_PROCESSABLE_L2_GAS }),
totalGas: Gas.from({ daGas: 140, l2Gas: MAX_PROCESSABLE_L2_GAS }),
billedGas: Gas.from({ daGas: 150, l2Gas: MAX_PROCESSABLE_L2_GAS }),
teardownGas: Gas.from({ daGas: 10, l2Gas: MAX_PROCESSABLE_L2_GAS * 0.2 }),
publicGas: Gas.from({ daGas: 50, l2Gas: MAX_PROCESSABLE_L2_GAS }),
};
// Does not fail without padding since it's at the limit
expect(getGasLimits(txSimulationResult, 0)).toEqual({
gasLimits: Gas.from({ daGas: 140, l2Gas: AVM_MAX_PROCESSABLE_L2_GAS }),
teardownGasLimits: Gas.from({ daGas: 10, l2Gas: AVM_MAX_PROCESSABLE_L2_GAS * 0.2 }),
gasLimits: Gas.from({ daGas: 140, l2Gas: MAX_PROCESSABLE_L2_GAS }),
teardownGasLimits: Gas.from({ daGas: 10, l2Gas: Math.ceil(MAX_PROCESSABLE_L2_GAS * 0.2) }),
});
// Fails with padding since it's over the limit
expect(() => getGasLimits(txSimulationResult, 0.1)).toThrow(
'Transaction consumes more gas than the AVM maximum processable gas',
'Transaction consumes more l2 gas than the maximum processable gas',
);
});
});
6 changes: 3 additions & 3 deletions yarn-project/aztec.js/src/contract/get_gas_limits.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AVM_MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
import { MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
import { Gas } from '@aztec/stdlib/gas';
import type { TxSimulationResult } from '@aztec/stdlib/tx';

Expand All @@ -23,8 +23,8 @@ export function getGasLimits(
const gasLimits = simulationResult.gasUsed.totalGas.mul(1 + pad);
const teardownGasLimits = simulationResult.gasUsed.teardownGas.mul(1 + pad);

if (gasLimits.l2Gas > AVM_MAX_PROCESSABLE_L2_GAS) {
throw new Error('Transaction consumes more gas than the AVM maximum processable gas');
if (gasLimits.l2Gas > MAX_PROCESSABLE_L2_GAS) {
throw new Error('Transaction consumes more l2 gas than the maximum processable gas');
}
return {
gasLimits,
Expand Down
Loading
Loading