redo transient keyword pr (#1019)

This commit is contained in:
The Dark Jester
2025-05-19 10:27:19 +01:00
committed by GitHub
parent d995d9d37e
commit 89e9c2cbca
9 changed files with 91 additions and 160 deletions

View File

@@ -49,7 +49,7 @@
"hardhat-storage-layout": "0.1.7",
"hardhat-tracer": "2.8.2",
"node-gyp": "10.1.0",
"prettier-plugin-solidity": "1.3.1",
"prettier-plugin-solidity": "1.4.2",
"solhint": "5.0.5",
"yargs": "17.7.2"
},

View File

@@ -1,53 +0,0 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.26;
/**
* @title Library that provides helper functions to interact with transient storage.
* @author ConsenSys Software Inc.
* @custom:security-contact security-report@linea.build
*/
library TransientStorageHelpers {
/**
* @notice Internal function that stores a uint256 value at a given key in the EVM's transient storage using the `tstore` opcode.
* @param _key The key in the EVM transient storage where the value should be stored.
* @param _value The uint256 value to be stored at the specified key in the EVM transient storage.
*/
function tstoreUint256(bytes32 _key, uint256 _value) internal {
assembly {
tstore(_key, _value)
}
}
/**
* @notice Internal function that retrieves a uint256 value from the EVM's transient storage using the `tload` opcode.
* @param _key The key in the EVM transient storage from which the value should be retrieved.
* @return value The uint256 value retrieved from the specified key in the EVM transient storage.
*/
function tloadUint256(bytes32 _key) internal view returns (uint256 value) {
assembly {
value := tload(_key)
}
}
/**
* @notice Internal function that stores an address at a given key in the EVM's transient storage using the `tstore` opcode.
* @param _key The key in the EVM transient storage where the value should be stored.
* @param _addr The address to be stored at the specified key in the EVM transient storage.
*/
function tstoreAddress(bytes32 _key, address _addr) internal {
assembly {
tstore(_key, _addr)
}
}
/**
* @notice Internal function that retrieves an address from the EVM's transient storage using the `tload` opcode.
* @param _key The key in the EVM transient storage from which the value should be retrieved.
* @return addr The address retrieved from the specified key in the EVM transient storage.
*/
function tloadAddress(bytes32 _key) internal view returns (address addr) {
assembly {
addr := tload(_key)
}
}
}

View File

@@ -7,7 +7,6 @@ import { L1MessageManager } from "./L1MessageManager.sol";
import { IL1MessageService } from "./interfaces/IL1MessageService.sol";
import { IGenericErrors } from "../../interfaces/IGenericErrors.sol";
import { SparseMerkleTreeVerifier } from "../libraries/SparseMerkleTreeVerifier.sol";
import { TransientStorageHelpers } from "../../libraries/TransientStorageHelpers.sol";
import { MessageHashing } from "../libraries/MessageHashing.sol";
/**
@@ -24,7 +23,6 @@ abstract contract L1MessageService is
{
using SparseMerkleTreeVerifier for *;
using MessageHashing for *;
using TransientStorageHelpers for *;
/// @dev This is currently not in use, but is reserved for future upgrades.
uint256 public systemMigrationBlock;
@@ -122,7 +120,7 @@ abstract contract L1MessageService is
revert InvalidMerkleProof();
}
TransientStorageHelpers.tstoreAddress(MESSAGE_SENDER_TRANSIENT_KEY, _params.from);
TRANSIENT_MESSAGE_SENDER = _params.from;
(bool callSuccess, bytes memory returnData) = _params.to.call{ value: _params.value }(_params.data);
if (!callSuccess) {
@@ -136,7 +134,7 @@ abstract contract L1MessageService is
}
}
TransientStorageHelpers.tstoreAddress(MESSAGE_SENDER_TRANSIENT_KEY, DEFAULT_MESSAGE_SENDER_TRANSIENT_VALUE);
TRANSIENT_MESSAGE_SENDER = DEFAULT_MESSAGE_SENDER_TRANSIENT_VALUE;
emit MessageClaimed(messageLeafHash);
}
@@ -147,6 +145,6 @@ abstract contract L1MessageService is
* @return originalSender The message sender address that is stored temporarily in the transient storage when claiming.
*/
function sender() external view returns (address originalSender) {
originalSender = TransientStorageHelpers.tloadAddress(MESSAGE_SENDER_TRANSIENT_KEY);
originalSender = TRANSIENT_MESSAGE_SENDER;
}
}

View File

@@ -6,7 +6,6 @@ import { RateLimiter } from "../../../security/limiting/RateLimiter.sol";
import { L1MessageManagerV1 } from "./L1MessageManagerV1.sol";
import { TransientStorageReentrancyGuardUpgradeable } from "../../../security/reentrancy/TransientStorageReentrancyGuardUpgradeable.sol";
import { IMessageService } from "../../interfaces/IMessageService.sol";
import { TransientStorageHelpers } from "../../../libraries/TransientStorageHelpers.sol";
import { MessageHashing } from "../../libraries/MessageHashing.sol";
/**
@@ -23,6 +22,8 @@ abstract contract L1MessageServiceV1 is
{
using MessageHashing for *;
address transient TRANSIENT_MESSAGE_SENDER;
// @dev This is initialised to save user cost with existing slot.
uint256 public nextMessageNumber;
@@ -36,10 +37,6 @@ abstract contract L1MessageServiceV1 is
/// @dev adding these should not affect storage as they are constants and are stored in bytecode.
uint256 internal constant REFUND_OVERHEAD_IN_GAS = 48252;
/// @dev The transient storage key to set the message sender against while claiming.
bytes32 internal constant MESSAGE_SENDER_TRANSIENT_KEY =
bytes32(uint256(keccak256("eip1967.message.sender.transient.key")) - 1);
/// @notice The default value for the message sender reset to post claiming using the MESSAGE_SENDER_TRANSIENT_KEY.
address internal constant DEFAULT_MESSAGE_SENDER_TRANSIENT_VALUE = address(0);
@@ -49,12 +46,7 @@ abstract contract L1MessageServiceV1 is
* @param _to The recipient of the message and gas refund.
* @param _calldata The calldata of the message.
*/
modifier distributeFees(
uint256 _feeInWei,
address _to,
bytes calldata _calldata,
address _feeRecipient
) {
modifier distributeFees(uint256 _feeInWei, address _to, bytes calldata _calldata, address _feeRecipient) {
//pre-execution
uint256 startingGas = gasleft();
_;
@@ -120,7 +112,7 @@ abstract contract L1MessageServiceV1 is
_requireTypeAndGeneralNotPaused(PauseType.L2_L1);
/// @dev This is placed earlier to fix the stack issue by using these two earlier on.
TransientStorageHelpers.tstoreAddress(MESSAGE_SENDER_TRANSIENT_KEY, _from);
TRANSIENT_MESSAGE_SENDER = _from;
bytes32 messageHash = MessageHashing._hashMessage(_from, _to, _fee, _value, _nonce, _calldata);
@@ -141,7 +133,7 @@ abstract contract L1MessageServiceV1 is
}
}
TransientStorageHelpers.tstoreAddress(MESSAGE_SENDER_TRANSIENT_KEY, DEFAULT_MESSAGE_SENDER_TRANSIENT_VALUE);
TRANSIENT_MESSAGE_SENDER = DEFAULT_MESSAGE_SENDER_TRANSIENT_VALUE;
emit MessageClaimed(messageHash);
}

View File

@@ -173,12 +173,7 @@ abstract contract L2MessageServiceV1 is
* @param _to The recipient of the message and gas refund.
* @param _calldata The calldata of the message.
*/
modifier distributeFees(
uint256 _feeInWei,
address _to,
bytes calldata _calldata,
address _feeRecipient
) {
modifier distributeFees(uint256 _feeInWei, address _to, bytes calldata _calldata, address _feeRecipient) {
//pre-execution
uint256 startingGas = gasleft();
_;

View File

@@ -602,9 +602,7 @@ contract LineaRollup is AccessControlUpgradeable, ZkEvmV2, L1MessageService, Per
assembly {
for {
let i := _data.length
} gt(i, 0) {
} {
} gt(i, 0) {} {
i := sub(i, 0x20)
let chunk := calldataload(add(_data.offset, i))
if iszero(iszero(and(chunk, 0xFF00000000000000000000000000000000000000000000000000000000000000))) {

View File

@@ -1,19 +1,13 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.26;
import { TransientStorageHelpers } from "../../libraries/TransientStorageHelpers.sol";
/**
* @title Contract that helps prevent reentrant calls.
* @author ConsenSys Software Inc.
* @custom:security-contact security-report@linea.build
*/
abstract contract TransientStorageReentrancyGuardUpgradeable {
using TransientStorageHelpers for *;
bytes32 private constant REENTRANCY_GUARD_TRANSIENT_KEY =
bytes32(uint256(keccak256("eip1967.reentrancy.guard.transient.key")) - 1);
uint256 transient TRANSIENT_ENTERED;
uint256 private constant NOT_ENTERED = 0;
uint256 private constant ENTERED = 1;
@@ -22,29 +16,15 @@ abstract contract TransientStorageReentrancyGuardUpgradeable {
/// @dev This gap is used to not shift down the storage layout after removing the OpenZeppelin ReentrancyGuardUpgradeable contract.
uint256[50] private __gap_ReentrancyGuardUpgradeable;
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
/**
* @notice Checks reentrancy and if not reentrant sets the transient reentry flag.
* @dev This uses the TransientStorageHelpers library and REENTRANCY_GUARD_TRANSIENT_KEY.
*/
function _nonReentrantBefore() private {
if (TransientStorageHelpers.tloadUint256(REENTRANCY_GUARD_TRANSIENT_KEY) != NOT_ENTERED) {
modifier nonReentrant() {
if (TRANSIENT_ENTERED == ENTERED) {
revert ReentrantCall();
}
TransientStorageHelpers.tstoreUint256(REENTRANCY_GUARD_TRANSIENT_KEY, ENTERED);
}
/**
* @notice Clears reentry transient storage flag.
* @dev This uses the TransientStorageHelpers library and REENTRANCY_GUARD_TRANSIENT_KEY.
*/
function _nonReentrantAfter() private {
TransientStorageHelpers.tstoreUint256(REENTRANCY_GUARD_TRANSIENT_KEY, NOT_ENTERED);
TRANSIENT_ENTERED = ENTERED;
_;
TRANSIENT_ENTERED = NOT_ENTERED;
}
}

View File

@@ -1323,9 +1323,7 @@ contract PlonkVerifierDev {
mstore(add(mPtr, 0x80), e)
mstore(add(mPtr, 0xa0), R_MOD)
let check_staticcall := staticcall(gas(), MOD_EXP, mPtr, 0xc0, mPtr, 0x20)
if eq(check_staticcall, 0) {
}
if eq(check_staticcall, 0) {}
res := mload(mPtr)
}
}