Skip to content

Commit

Permalink
[Feat] Readd missing tests (#106)
Browse files Browse the repository at this point in the history
* Use explicit time calculations and add test cover

* remove redundant comments

* use shared expectRevertWithCustomError

* remove .only and expectEvent
  • Loading branch information
thedarkjester authored Sep 27, 2024
1 parent 934d355 commit 405d683
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 54 deletions.
30 changes: 17 additions & 13 deletions contracts/contracts/LineaRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract LineaRollup is
uint256 internal constant POINT_EVALUATION_RETURN_DATA_LENGTH = 64;
uint256 internal constant POINT_EVALUATION_FIELD_ELEMENTS_LENGTH = 4096;

uint256 internal constant SIX_MONTHS_IN_SECONDS = 15768000; // 365 / 2 * 86400
uint256 internal constant SIX_MONTHS_IN_SECONDS = (365 / 2) * 24 * 60 * 60;

/// @dev DEPRECATED in favor of the single shnarfFinalBlockNumbers mapping.
mapping(bytes32 dataHash => bytes32 finalStateRootHash) public dataFinalStateRootHashes;
Expand Down Expand Up @@ -76,9 +76,9 @@ contract LineaRollup is
/// @dev Hash of the L2 computed L1 message number, rolling hash and finalized timestamp.
bytes32 public currentFinalizedState;

/// @dev The address of the gateway operator.
/// @dev The address of the fallback operator.
/// @dev This address is granted the OPERATOR_ROLE after six months of finalization inactivity by the current operators.
address public gatewayOperator;
address public fallbackOperator;

/// @dev Total contract storage is 11 slots.

Expand Down Expand Up @@ -107,7 +107,9 @@ contract LineaRollup is

verifiers[0] = _initializationData.defaultVerifier;

gatewayOperator = _initializationData.gatewayOperator;
fallbackOperator = _initializationData.fallbackOperator;
emit FallbackOperatorAddressSet(msg.sender, _initializationData.fallbackOperator);

currentL2BlockNumber = _initializationData.initialL2BlockNumber;
stateRootHashes[_initializationData.initialL2BlockNumber] = _initializationData.initialStateRootHash;

Expand All @@ -118,22 +120,24 @@ contract LineaRollup is
}

/**
* @notice Sets permissions for a list of addresses and their roles as well as initialises the PauseManager pauseType:role mappings and gateway operator.
* @notice Sets permissions for a list of addresses and their roles as well as initialises the PauseManager pauseType:role mappings and fallback operator.
* @dev This function is a reinitializer and can only be called once per version. Should be called using an upgradeAndCall transaction to the ProxyAdmin.
* @param _roleAddresses The list of addresses and their roles.
* @param _pauseTypeRoles The list of pause type roles.
* @param _unpauseTypeRoles The list of unpause type roles.
* @param _gatewayOperator The address of the gateway operator.
* @param _fallbackOperator The address of the fallback operator.
*/
function reinitializeLineaRollupV6(
RoleAddress[] calldata _roleAddresses,
PauseTypeRole[] calldata _pauseTypeRoles,
PauseTypeRole[] calldata _unpauseTypeRoles,
address _gatewayOperator
address _fallbackOperator
) external reinitializer(6) {
__Permissions_init(_roleAddresses);
__PauseManager_init(_pauseTypeRoles, _unpauseTypeRoles);
gatewayOperator = _gatewayOperator;

fallbackOperator = _fallbackOperator;
emit FallbackOperatorAddressSet(msg.sender, _fallbackOperator);

/// @dev using the constants requires string memory and more complex code.
emit LineaRollupVersionChanged(bytes8("5.0"), bytes8("6.0"));
Expand All @@ -156,13 +160,13 @@ contract LineaRollup is
}

/**
* @notice Sets the gateway operator role to the specified address if six months have passed since the last finalization.
* @notice Sets the fallback operator role to the specified address if six months have passed since the last finalization.
* @dev Reverts if six months have not passed since the last finalization.
* @param _messageNumber Last finalized L1 message number as part of the feedback loop.
* @param _rollingHash Last finalized L1 rolling hash as part of the feedback loop.
* @param _lastFinalizedTimestamp Last finalized L2 block timestamp.
*/
function setGatewayOperator(uint256 _messageNumber, bytes32 _rollingHash, uint256 _lastFinalizedTimestamp) external {
function setFallbackOperator(uint256 _messageNumber, bytes32 _rollingHash, uint256 _lastFinalizedTimestamp) external {
if (block.timestamp < _lastFinalizedTimestamp + SIX_MONTHS_IN_SECONDS) {
revert LastFinalizationTimeNotLapsed();
}
Expand All @@ -173,10 +177,10 @@ contract LineaRollup is
);
}

address gatewayOperatorAddress = gatewayOperator;
address fallbackOperatorAddress = fallbackOperator;

_grantRole(OPERATOR_ROLE, gatewayOperatorAddress);
emit GatewayOperatorRoleGranted(msg.sender, gatewayOperatorAddress);
_grantRole(OPERATOR_ROLE, fallbackOperatorAddress);
emit FallbackOperatorRoleGranted(msg.sender, fallbackOperatorAddress);
}

/**
Expand Down
23 changes: 15 additions & 8 deletions contracts/contracts/interfaces/l1/ILineaRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ILineaRollup {
* @param roleAddresses The list of role addresses.
* @param pauseTypeRoles The list of pause type roles.
* @param unpauseTypeRoles The list of unpause type roles.
* @param gatewayOperator The account to be given OPERATOR_ROLE when.
* @param fallbackOperator The account to be given OPERATOR_ROLE on when the time since last finalization lapses.
*/
struct InitializationData {
bytes32 initialStateRootHash;
Expand All @@ -33,7 +33,7 @@ interface ILineaRollup {
IPermissionsManager.RoleAddress[] roleAddresses;
IPauseManager.PauseTypeRole[] pauseTypeRoles;
IPauseManager.PauseTypeRole[] unpauseTypeRoles;
address gatewayOperator;
address fallbackOperator;
}

/**
Expand Down Expand Up @@ -140,11 +140,18 @@ interface ILineaRollup {
event LineaRollupVersionChanged(bytes8 indexed previousVersion, bytes8 indexed newVersion);

/**
* @notice Emitted when the gateway operator role is granted.
* @notice Emitted when the fallback operator role is granted.
* @param caller The address that granted the role.
* @param gatewayOperatorAddress The gateway operator address that received the operator role.
* @param fallbackOperator The fallback operator address that received the operator role.
*/
event GatewayOperatorRoleGranted(address indexed caller, address indexed gatewayOperatorAddress);
event FallbackOperatorRoleGranted(address indexed caller, address indexed fallbackOperator);

/**
* @notice Emitted when the fallback operator role is set on the contract.
* @param caller The address that set the fallback operator address.
* @param fallbackOperator The fallback operator address.
*/
event FallbackOperatorAddressSet(address indexed caller, address indexed fallbackOperator);

/**
* @notice Emitted when a verifier is set for a particular proof type.
Expand Down Expand Up @@ -186,7 +193,7 @@ interface ILineaRollup {
);

/**
* @dev Thrown when the last finalization time has not lapsed when trying to grant the OPERATOR_ROLE to the gateway operator address.
* @dev Thrown when the last finalization time has not lapsed when trying to grant the OPERATOR_ROLE to the fallback operator address.
*/
error LastFinalizationTimeNotLapsed();

Expand Down Expand Up @@ -330,13 +337,13 @@ interface ILineaRollup {
function setVerifierAddress(address _newVerifierAddress, uint256 _proofType) external;

/**
* @notice Sets the gateway operator role to the specified address if six months have passed since the last finalization.
* @notice Sets the fallback operator role to the specified address if six months have passed since the last finalization.
* @dev Reverts if six months have not passed since the last finalization.
* @param _messageNumber Last finalized L1 message number as part of the feedback loop.
* @param _rollingHash Last finalized L1 rolling hash as part of the feedback loop.
* @param _lastFinalizedTimestamp Last finalized L2 block timestamp.
*/
function setGatewayOperator(uint256 _messageNumber, bytes32 _rollingHash, uint256 _lastFinalizedTimestamp) external;
function setFallbackOperator(uint256 _messageNumber, bytes32 _rollingHash, uint256 _lastFinalizedTimestamp) external;

/**
* @notice Unset the verifier contract address for a proof type.
Expand Down
2 changes: 1 addition & 1 deletion contracts/deploy/03_deploy_LineaRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
roleAddresses: roleAddresses,
pauseTypeRoles: pauseTypeRoles,
unpauseTypeRoles: unpauseTypeRoles,
gatewayOperator: MultiCallAddress,
fallbackOperator: MultiCallAddress,
},
],
{
Expand Down
Loading

0 comments on commit 405d683

Please sign in to comment.