From e65e8401040cf13a3a6de3329ab6a76bb79b4215 Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Thu, 28 Sep 2023 00:27:19 +0200 Subject: [PATCH] increase the number of bytes for calldata for L1Messenger --- SystemConfig.json | 2 +- bootloader/bootloader.yul | 13 ++++--------- scripts/process.ts | 9 +++++++++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/SystemConfig.json b/SystemConfig.json index ec966e1e..973e0dc0 100644 --- a/SystemConfig.json +++ b/SystemConfig.json @@ -9,7 +9,7 @@ "L1_TX_INTRINSIC_L2_GAS": 167157, "L1_TX_INTRINSIC_PUBDATA": 88, "MAX_GAS_PER_TRANSACTION": 80000000, - "BOOTLOADER_MEMORY_FOR_TXS": 485225, + "BOOTLOADER_MEMORY_FOR_TXS": 273132, "REFUND_GAS": 7343, "KECCAK_ROUND_COST_GAS": 40, "SHA256_ROUND_COST_GAS": 7, diff --git a/bootloader/bootloader.yul b/bootloader/bootloader.yul index 700887b7..be77edcc 100644 --- a/bootloader/bootloader.yul +++ b/bootloader/bootloader.yul @@ -80,12 +80,6 @@ object "Bootloader" { ret := {{MAX_GAS_PER_TRANSACTION}} } - /// @dev The maximum number of pubdata bytes that can be published with one - /// L1 batch - function MAX_PUBDATA_PER_BATCH() -> ret { - ret := {{MAX_PUBDATA_PER_BATCH}} - } - /// @dev The number of L1 gas needed to be spent for /// L1 byte. While a single pubdata byte costs `16` gas, /// we demand at least 17 to cover up for the costs of additional @@ -346,10 +340,11 @@ object "Bootloader" { } /// @dev Slots needed to store L1 Messenger pubdata. - /// There are 3 additional slots needed: one for L1Messengers' function signature, - /// one for such function input (calldata) array offset, one for length of the array + /// @dev Note that are many more these than the maximal pubdata in batch, since + /// it needs to also accomodate uncompressed state diffs that are required for the state diff + /// compression verification. function OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_SLOTS() -> ret { - ret := add(ceilDiv(MAX_PUBDATA_PER_BATCH(), 32), 3) + ret := {{OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_SLOTS}} } /// @dev The slot right after the last slot of the L1 Messenger pubdata memory area. diff --git a/scripts/process.ts b/scripts/process.ts index 6968b086..5088a3c1 100644 --- a/scripts/process.ts +++ b/scripts/process.ts @@ -125,6 +125,15 @@ let params = { FORBID_ZERO_GAS_PER_PUBDATA: 1, SYSTEM_CONTEXT_EXPECTED_CODE_HASH: getSystemContextExpectedHash(), UPGRADE_SYSTEM_CONTEXT_CALLDATA: upgradeSystemContextCalldata(), + // One of "worst case" scenarios for the number of state diffs in a batch is when 120kb of pubdata is spent + // on repeated writes, that are all zeroed out. In this case, the number of diffs is 120k / 5 = 24k. This means that they will have + // accoomdate 6528000 bytes of calldata for the uncompressed state diffs. Adding 120k on top leaves us with + // roughly 6650000 bytes needed for calldata. 207813 slots are needed to accomodate this amount of data. + // We round up to 208000 slots just in case. + // + // In theory though much more calldata could be used (if for instance 1 byte is used for enum index). It is the responsibility of the + // operator to ensure that it can form the correct calldata for the L1Messenger. + OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_SLOTS: 208000, ...SYSTEM_PARAMS };