diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp index c56cc0dfc547..8ee7560964f4 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp @@ -13,7 +13,7 @@ const size_t MAX_PUBLIC_DATA_READS_PER_CALL = 16; const size_t MAX_NOTE_HASH_READ_REQUESTS_PER_CALL = 32; const size_t MAX_NULLIFIER_READ_REQUESTS_PER_CALL = 2; const size_t MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL = 2; -const size_t MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL = 1; +const size_t MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL = 16; const size_t MAX_NOTE_ENCRYPTED_LOGS_PER_CALL = 16; const size_t MAX_ENCRYPTED_LOGS_PER_CALL = 4; const size_t MAX_UNENCRYPTED_LOGS_PER_CALL = 4; @@ -27,7 +27,7 @@ const size_t MAX_NEW_L2_TO_L1_MSGS_PER_TX = 2; const size_t MAX_NOTE_HASH_READ_REQUESTS_PER_TX = 128; const size_t MAX_NULLIFIER_READ_REQUESTS_PER_TX = 8; const size_t MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX = 8; -const size_t MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX = 4; +const size_t MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX = 64; const size_t MAX_NOTE_ENCRYPTED_LOGS_PER_TX = 64; const size_t MAX_ENCRYPTED_LOGS_PER_TX = 8; const size_t MAX_UNENCRYPTED_LOGS_PER_TX = 8; @@ -63,7 +63,7 @@ const size_t ARGS_HASH_CHUNK_COUNT = 64; const size_t MAX_ARGS_LENGTH = ARGS_HASH_CHUNK_COUNT * ARGS_HASH_CHUNK_LENGTH; const size_t INITIAL_L2_BLOCK_NUM = 1; const size_t BLOB_SIZE_IN_BYTES = 31 * 4096; -const size_t NESTED_CALL_L2_GAS_BUFFER = 20000; +const size_t NESTED_CALL_L2_GAS_BUFFER = 40000; const size_t MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 32000; const size_t MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 3000; const size_t MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS = 3000; diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 4aeefe97cccd..c50696d959ab 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -76,7 +76,7 @@ library Constants { uint256 internal constant INITIALIZATION_SLOT_SEPARATOR = 1000_000_000; uint256 internal constant INITIAL_L2_BLOCK_NUM = 1; uint256 internal constant BLOB_SIZE_IN_BYTES = 31 * 4096; - uint256 internal constant NESTED_CALL_L2_GAS_BUFFER = 20000; + uint256 internal constant NESTED_CALL_L2_GAS_BUFFER = 40000; uint256 internal constant MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 32000; uint256 internal constant MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 3000; uint256 internal constant MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS = 3000; 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 a39b851d2231..c628e8760a86 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -103,7 +103,7 @@ global INITIALIZATION_SLOT_SEPARATOR: Field = 1000_000_000; global INITIAL_L2_BLOCK_NUM: Field = 1; global BLOB_SIZE_IN_BYTES: Field = 31 * 4096; // How much gas is subtracted from L2GASLEFT when making a nested public call by default in the AVM -global NESTED_CALL_L2_GAS_BUFFER = 20000; +global NESTED_CALL_L2_GAS_BUFFER = 40000; // CONTRACT CLASS CONSTANTS global MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS: u64 = 32000; diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 563f1b3cb40d..ed6441827723 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -62,7 +62,7 @@ export const MAX_ARGS_LENGTH = ARGS_HASH_CHUNK_COUNT * ARGS_HASH_CHUNK_LENGTH; export const INITIALIZATION_SLOT_SEPARATOR = 1000_000_000; export const INITIAL_L2_BLOCK_NUM = 1; export const BLOB_SIZE_IN_BYTES = 31 * 4096; -export const NESTED_CALL_L2_GAS_BUFFER = 20000; +export const NESTED_CALL_L2_GAS_BUFFER = 40000; export const MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 32000; export const MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 3000; export const MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS = 3000; diff --git a/yarn-project/simulator/src/avm/fixtures/index.ts b/yarn-project/simulator/src/avm/fixtures/index.ts index 1ef3dadcc391..a867136dc47c 100644 --- a/yarn-project/simulator/src/avm/fixtures/index.ts +++ b/yarn-project/simulator/src/avm/fixtures/index.ts @@ -90,8 +90,8 @@ export function initGlobalVariables(overrides?: Partial): Globa */ export function initMachineState(overrides?: Partial): AvmMachineState { return AvmMachineState.fromState({ - l2GasLeft: overrides?.l2GasLeft ?? 100e6, - daGasLeft: overrides?.daGasLeft ?? 100e6, + l2GasLeft: overrides?.l2GasLeft ?? 1e8, + daGasLeft: overrides?.daGasLeft ?? 1e8, }); } diff --git a/yarn-project/simulator/src/avm/opcodes/external_calls.ts b/yarn-project/simulator/src/avm/opcodes/external_calls.ts index 21d96882ed9a..a7d46c9b0872 100644 --- a/yarn-project/simulator/src/avm/opcodes/external_calls.ts +++ b/yarn-project/simulator/src/avm/opcodes/external_calls.ts @@ -1,5 +1,8 @@ import { FunctionSelector, Gas } from '@aztec/circuits.js'; import { padArrayEnd } from '@aztec/foundation/collection'; +import { createDebugLogger } from '@aztec/foundation/log'; + +import { strict as assert } from 'assert'; import { convertAvmResultsToPxResult, createPublicExecution } from '../../public/transitional_adaptors.js'; import type { AvmContext } from '../avm_context.js'; @@ -57,16 +60,25 @@ abstract class ExternalCall extends Instruction { const callAddress = memory.getAs(addrOffset); const calldataSize = memory.get(argsSizeOffset).toNumber(); const calldata = memory.getSlice(argsOffset, calldataSize).map(f => f.toFr()); - const l2Gas = memory.get(gasOffset).toNumber(); - const daGas = memory.getAs(gasOffset + 1).toNumber(); + const allocatedL2Gas = memory.get(gasOffset).toNumber(); + const allocatedDaGas = memory.getAs(gasOffset + 1).toNumber(); const functionSelector = memory.getAs(this.functionSelectorOffset).toFr(); // If we are already in a static call, we propagate the environment. const callType = context.environment.isStaticCall ? 'STATICCALL' : this.type; - const allocatedGas = { l2Gas, daGas }; + assert( + allocatedL2Gas <= context.machineState.l2GasLeft, + `Allocated more L2 gas than available: ${allocatedL2Gas} allocated, ${context.machineState.l2GasLeft} available.`, + ); + assert( + allocatedDaGas <= context.machineState.daGasLeft, + `Allocated more DA gas than available: ${allocatedDaGas} allocated, ${context.machineState.daGasLeft} available.`, + ); + const memoryOperations = { reads: calldataSize + 5, writes: 1 + this.retSize, indirect: this.indirect }; - const totalGas = sumGas(this.gasCost(memoryOperations), allocatedGas); - context.machineState.consumeGas(totalGas); + const allocatedGas = { l2Gas: allocatedL2Gas, daGas: allocatedDaGas }; + const totalGasToConsume = sumGas(this.gasCost(memoryOperations), allocatedGas); + context.machineState.consumeGas(totalGasToConsume); // TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit const nestedContext = context.createNestedContractCallContext(