Skip to content

Commit

Permalink
Merge pull request #82 from OffchainLabs/outbox-pui
Browse files Browse the repository at this point in the history
feat: outbox postUpgradeInit
  • Loading branch information
gzeoneth authored Oct 24, 2023
2 parents b22f93c + 0c1b1fc commit fbe8cef
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/bridge/AbsOutbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
UnknownRoot,
AlreadySpent,
BridgeCallFailed,
HadZeroInit
HadZeroInit,
BadPostUpgradeInit
} from "../libraries/Error.sol";
import "./IBridge.sol";
import "./IOutbox.sol";
Expand Down Expand Up @@ -76,6 +77,19 @@ abstract contract AbsOutbox is DelegateCallAware, IOutbox {
rollup = address(_bridge.rollup());
}

function postUpgradeInit() external onlyDelegated onlyProxyOwner {
// prevent postUpgradeInit within a withdrawal
if (context.l2Block != L2BLOCK_DEFAULT_CONTEXT) revert BadPostUpgradeInit();
context = L2ToL1Context({
l2Block: L2BLOCK_DEFAULT_CONTEXT,
l1Block: L1BLOCK_DEFAULT_CONTEXT,
timestamp: TIMESTAMP_DEFAULT_CONTEXT,
outputId: OUTPUTID_DEFAULT_CONTEXT,
sender: SENDER_DEFAULT_CONTEXT,
withdrawalAmount: _defaultContextAmount()
});
}

function updateSendRoot(bytes32 root, bytes32 l2BlockHash) external {
if (msg.sender != rollup) revert NotRollup(msg.sender, rollup);
roots[root] = l2BlockHash;
Expand Down
6 changes: 6 additions & 0 deletions src/bridge/IOutbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,10 @@ interface IOutbox {
uint256 path,
bytes32 item
) external pure returns (bytes32);

/**
* @dev function to be called one time during the outbox upgrade process
* this is used to fix the storage slots
*/
function postUpgradeInit() external;
}
5 changes: 4 additions & 1 deletion src/libraries/Error.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ pragma solidity ^0.8.4;
/// @dev Init was already called
error AlreadyInit();

/// Init was called with param set to zero that must be nonzero
/// @dev Init was called with param set to zero that must be nonzero
error HadZeroInit();

/// @dev Thrown when post upgrade init validation fails
error BadPostUpgradeInit();

/// @dev Thrown when non owner tries to access an only-owner function
/// @param sender The msg.sender who is not the owner
/// @param owner The owner address
Expand Down
2 changes: 2 additions & 0 deletions src/test-helpers/OutboxWithoutOptTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ contract OutboxWithoutOptTester is DelegateCallAware, IOutbox {
rollup = address(_bridge.rollup());
}

function postUpgradeInit() external {}

function updateSendRoot(bytes32 root, bytes32 l2BlockHash) external override {
//if (msg.sender != rollup) revert NotRollup(msg.sender, rollup); //test only!!!
roots[root] = l2BlockHash;
Expand Down

0 comments on commit fbe8cef

Please sign in to comment.