Skip to content

Commit

Permalink
Fix issues from audit (#61)
Browse files Browse the repository at this point in the history
* fix: reject on incorrect fee, fix comment

* test: fix tests after adding fee check
  • Loading branch information
kfastov authored Sep 16, 2024
1 parent 039661c commit b02f9d2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/CrossDomainOwnableLinea.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { IMessageService } from "linea-contracts/interfaces/IMessageService.sol"
abstract contract CrossDomainOwnableLinea is Ownable {
IMessageService public messageService;

/// @notice If true, the contract uses the cross domain _checkOwner function override.
/// If false it uses the standard Ownable _checkOwner function.
/// @notice If true, the owner is on the same layer as this contract (L2).
/// If false, the owner is on a different layer (L1) and ownership checks use cross-layer messaging.
bool public isLocal = true;

/// @notice Emits when ownership of the contract is transferred. Includes the
Expand Down
23 changes: 23 additions & 0 deletions src/LineaStateBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ contract LineaStateBridge is Ownable2Step {
/// @notice Emitted when an attempt is made to set an address to zero
error AddressZero();

/// @notice Emitted when the incorrect message fee is sent
error IncorrectMessageFeeSent();

///////////////////////////////////////////////////////////////////
/// CONSTRUCTOR ///
///////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -126,6 +129,11 @@ contract LineaStateBridge is Ownable2Step {
function propagateRoot() external payable {
uint256 latestRoot = IWorldIDIdentityManager(worldIDAddress).latestRoot();

// Ensure that the correct fee is sent with the transaction
if (msg.value != _feePropagateRoot) {
revert IncorrectMessageFeeSent();
}

// The `encodeCall` function is strongly typed, so this checks that we are passing the
// correct data to the Linea message service.
bytes memory message = abi.encodeCall(ILineaWorldID.receiveRoot, (latestRoot));
Expand All @@ -149,6 +157,11 @@ contract LineaStateBridge is Ownable2Step {
revert AddressZero();
}

// Ensure that the correct fee is sent with the transaction
if (msg.value != _feeTransferOwnership) {
revert IncorrectMessageFeeSent();
}

// Encoding the call to transferOwnership on ICrossDomainOwnableLinea
bytes memory message = abi.encodeCall(ICrossDomainOwnableLinea.transferOwnership, (_owner, _isLocal));

Expand All @@ -167,6 +180,11 @@ contract LineaStateBridge is Ownable2Step {
revert AddressZero();
}

// Ensure that the correct fee is sent with the transaction
if (msg.value != _feeSetMessageService) {
revert IncorrectMessageFeeSent();
}

// Encoding the call to setMessageService on ICrossDomainOwnableLinea
bytes memory message = abi.encodeCall(ICrossDomainOwnableLinea.setMessageService, (_messageService));

Expand All @@ -181,6 +199,11 @@ contract LineaStateBridge is Ownable2Step {
/// @notice Adds functionality to the StateBridge to set the root history expiry on LineaWorldID
/// @param _rootHistoryExpiry new root history expiry
function setRootHistoryExpiry(uint256 _rootHistoryExpiry) external payable onlyOwner {
// Ensure that the correct fee is sent with the transaction
if (msg.value != _feeSetRootHistoryExpiry) {
revert IncorrectMessageFeeSent();
}

// The `encodeCall` function is strongly typed, so this checks that we are passing the
// correct data to the linea bridge.
bytes memory message = abi.encodeCall(IRootHistory.setRootHistoryExpiry, (_rootHistoryExpiry));
Expand Down
6 changes: 6 additions & 0 deletions test/LineaStateBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ contract LineaStateBridgeTest is PRBTest, StdCheats {
lineaStateBridge =
new LineaStateBridge(mockWorldIDAddress, lineaWorldIDAddress, lineaCrossDomainMessengerAddress);

// Set fee for every action to 1
lineaStateBridge.setFeePropagateRoot(1);
lineaStateBridge.setFeeSetRootHistoryExpiry(1);
lineaStateBridge.setFeeTransferOwnershipLinea(1);
lineaStateBridge.setFeeSetMessageServiceLinea(1);

owner = lineaStateBridge.owner();
}

Expand Down

0 comments on commit b02f9d2

Please sign in to comment.