Skip to content

Commit

Permalink
finalize pubdata counter integration
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless committed Jan 24, 2024
1 parent 902e63c commit 3293947
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
29 changes: 15 additions & 14 deletions system-contracts/bootloader/bootloader.yul
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1403,6 +1409,8 @@ object "Bootloader" {
gasSpentOnExecute := add(gasSpentOnFactoryDeps, sub(gasBeforeExecute, gas()))
}

debugLog("notification", success)

notifyExecutionResult(success)
}

Expand Down Expand Up @@ -2689,19 +2697,21 @@ 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(
basePubdataSpent,
gasPerPubdata,
) -> ret {
let currentPubdataCounter := getPubdataSpent()
debugLog("basePubdata", basePubdataSpent)
debugLog("currentPubdata", currentPubdataCounter)
let spentPubdata := sub(currentPubdataCounter, basePubdataSpent)
if gt(basePubdataSpent, currentPubdataCounter) {
spentPubdata := 0
Expand All @@ -2719,26 +2729,17 @@ 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)
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3293947

Please sign in to comment.