From 3293947acd742deef14d697bcd02c23c9c168837 Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Wed, 24 Jan 2024 11:39:20 +0100 Subject: [PATCH] finalize pubdata counter integration --- system-contracts/bootloader/bootloader.yul | 29 ++++++++++--------- .../libraries/SystemContractHelper.sol | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/system-contracts/bootloader/bootloader.yul b/system-contracts/bootloader/bootloader.yul index 79d24274a..6491e33b8 100644 --- a/system-contracts/bootloader/bootloader.yul +++ b/system-contracts/bootloader/bootloader.yul @@ -998,7 +998,10 @@ object "Bootloader" { txDataOffset, sub(gasLimitForTx, gasUsedOnPreparation), basePubdataSpent, - reservedGas, + // Note, that for L1->L2 transactions the reserved gas is used to protect the operator from + // transactions that might accidentally cause to publish too many pubdata. + // FIXME: maybe a more elegant approach can be chosen here. + 0, gasPerPubdata, ) @@ -1169,6 +1172,9 @@ object "Bootloader" { gasPerPubdata ) { let basePubdataSpent := getPubdataSpent() + + debugLog("baseSepnt", basePubdataSpent) + let innerTxDataOffset := add(txDataOffset, 32) // Firsly, we publish all the bytecodes needed. This is needed to be done separately, since @@ -1403,6 +1409,8 @@ object "Bootloader" { gasSpentOnExecute := add(gasSpentOnFactoryDeps, sub(gasBeforeExecute, gas())) } + debugLog("notification", success) + notifyExecutionResult(success) } @@ -2689,12 +2697,12 @@ object "Bootloader" { callSystemContext({{RIGHT_PADDED_INCREMENT_TX_NUMBER_IN_BLOCK_SELECTOR}}) } - function getMeta() -> ret { + function $llvm_NoInline_llvm$_getMeta() -> ret { ret := verbatim_0i_1o("meta") } function getPubdataSpent() -> ret { - ret := and(getMeta(), 0xFFFFFFFF) + ret := and($llvm_NoInline_llvm$_getMeta(), 0xFFFFFFFF) } function getErgsSpentForPubdata( @@ -2702,6 +2710,8 @@ object "Bootloader" { gasPerPubdata, ) -> ret { let currentPubdataCounter := getPubdataSpent() + debugLog("basePubdata", basePubdataSpent) + debugLog("currentPubdata", currentPubdataCounter) let spentPubdata := sub(currentPubdataCounter, basePubdataSpent) if gt(basePubdataSpent, currentPubdataCounter) { spentPubdata := 0 @@ -2719,9 +2729,10 @@ object "Bootloader" { rejectTransaction ) { let spentErgs := getErgsSpentForPubdata(basePubdataSpent, gasPerPubdata) + debugLog("spentErgsPubdata", spentErgs) let allowedGasLimit := add(computeGas, reservedGas) - if gt(allowedGasLimit, spentErgs) { + if lt(allowedGasLimit, spentErgs) { if rejectTransaction { // TODO: use better code revertWithReason(ACCOUNT_TX_VALIDATION_ERR_CODE(), 0) @@ -2729,16 +2740,6 @@ object "Bootloader" { nearCallPanic() } - - // switch gt(spentErgs, newReservedGas) - // case 0 { - // newReservedGas := sub(newReservedGas, spentErgs) - // newComputeGas := computeGas - // } - // default { - // newReservedGas := 0 - // newComputeGas := sub(computeGas, sub(spentErgs, newReservedGas)) - // } } /// @dev Set the new value for the tx origin context value diff --git a/system-contracts/contracts/libraries/SystemContractHelper.sol b/system-contracts/contracts/libraries/SystemContractHelper.sol index fd7206bb6..544312c15 100644 --- a/system-contracts/contracts/libraries/SystemContractHelper.sol +++ b/system-contracts/contracts/libraries/SystemContractHelper.sol @@ -149,7 +149,7 @@ library SystemContractHelper { function unsafePrecompileCall(uint256 _rawParams, uint32 _gasToBurn, uint32 _pubdataToSpend) internal view returns (bool success) { address callAddr = PRECOMPILE_CALL_ADDRESS; - uint256 params = uint256(_gasToBurn) * (uint256(_pubdataToSpend) << 32); + uint256 params = uint256(_gasToBurn) + (uint256(_pubdataToSpend) << 32); uint256 cleanupMask = UINT64_MASK; assembly {