Skip to content

Commit

Permalink
Sets global exit root duing forking process (#137)
Browse files Browse the repository at this point in the history
* Sets global exit root duing forking process

* linting

* update zkevm-contract deps
  • Loading branch information
josojo authored Dec 30, 2023
1 parent bfdc1a9 commit d30bc74
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 43 deletions.
39 changes: 9 additions & 30 deletions contracts/ForkableGlobalExitRoot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,21 @@ contract ForkableGlobalExitRoot is
ForkableStructure,
PolygonZkEVMGlobalExitRoot
{
/// @dev Initializting function
/// @param _forkmanager The address of the forkmanager
/// @param _parentContract The address of the parent contract
/// @param _rollupAddress The address of the rollup contract
/// @param _bridgeAddress The address of the bridge contract
/// @inheritdoc IForkableGlobalExitRoot
function initialize(
address _forkmanager,
address _parentContract,
address _rollupAddress,
address _bridgeAddress
address _bridgeAddress,
bytes32 _lastMainnetExitRoot,
bytes32 _lastRollupExitRoot
) public initializer {
ForkableStructure.initialize(_forkmanager, _parentContract);
PolygonZkEVMGlobalExitRoot.initialize(_rollupAddress, _bridgeAddress);
}

/// @dev Overrites the other initialize functions from ForkableStructure and PolygonZkEVMGlobalExitRoot
/// @notice If we would not do it, it would throw the following error:
/// "Derived contract must override function "initialize". Two or more base classes
/// define function with same name and parameter types."
function initialize(
address forkmanager,
address parentContract
)
public
virtual
override(ForkableStructure, PolygonZkEVMGlobalExitRoot)
onlyInitializing
{
revert(
string(
abi.encode(
"illicit call to initialize with arguments:",
forkmanager,
parentContract
)
)
PolygonZkEVMGlobalExitRoot.initialize(
_rollupAddress,
_bridgeAddress,
_lastMainnetExitRoot,
_lastRollupExitRoot
);
}

Expand Down
8 changes: 6 additions & 2 deletions contracts/ForkingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ contract ForkingManager is IForkingManager, ForkableStructure {
newInstances.forkingManager.one,
globalExitRoot,
newInstances.zkEVM.one,
newInstances.bridge.one
newInstances.bridge.one,
IForkableGlobalExitRoot(globalExitRoot).lastMainnetExitRoot(),
IForkableGlobalExitRoot(globalExitRoot).lastRollupExitRoot()
);
}

Expand Down Expand Up @@ -396,7 +398,9 @@ contract ForkingManager is IForkingManager, ForkableStructure {
newInstances.forkingManager.two,
globalExitRoot,
newInstances.zkEVM.two,
newInstances.bridge.two
newInstances.bridge.two,
IForkableGlobalExitRoot(globalExitRoot).lastMainnetExitRoot(),
IForkableGlobalExitRoot(globalExitRoot).lastRollupExitRoot()
);
}
}
11 changes: 10 additions & 1 deletion contracts/interfaces/IForkableGlobalExitRoot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ interface IForkableGlobalExitRoot is
IForkableStructure,
IPolygonZkEVMGlobalExitRoot
{
/// @dev Initializting function
/// @param _forkmanager The address of the forkmanager
/// @param _parentContract The address of the parent contract
/// @param _rollupAddress The address of the rollup contract
/// @param _bridgeAddress The address of the bridge contract
/// @param _lastMainnetExitRoot The last exit root on mainnet
/// @param _lastRollupExitRoot The last exit root on rollup
function initialize(
address _forkmanager,
address _parentContract,
address _rollupAddress,
address _bridgeAddress
address _bridgeAddress,
bytes32 _lastMainnetExitRoot,
bytes32 _lastRollupExitRoot
) external;

function createChildren(
Expand Down
4 changes: 3 additions & 1 deletion test/ForkableGlobalExitRoot.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ contract ForkableGlobalExitRootTest is Test {
forkmanager,
parentContract,
rollupAddress,
bridgeAddress
bridgeAddress,
bytes32(0),
bytes32(0)
);
}

Expand Down
70 changes: 64 additions & 6 deletions test/ForkingManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {ForkableBridge} from "../contracts/ForkableBridge.sol";
import {ForkableZkEVM} from "../contracts/ForkableZkEVM.sol";
import {ForkonomicToken} from "../contracts/ForkonomicToken.sol";
import {ForkableGlobalExitRoot} from "../contracts/ForkableGlobalExitRoot.sol";
import {IBasePolygonZkEVMGlobalExitRoot} from "@RealityETH/zkevm-contracts/contracts/interfaces/IPolygonZkEVMGlobalExitRoot.sol";
import {IPolygonZkEVMGlobalExitRoot} from "@RealityETH/zkevm-contracts/contracts/interfaces/IPolygonZkEVMGlobalExitRoot.sol";
import {IForkingManager} from "../contracts/interfaces/IForkingManager.sol";
import {IVerifierRollup} from "@RealityETH/zkevm-contracts/contracts/interfaces/IVerifierRollup.sol";
import {IPolygonZkEVMBridge} from "@RealityETH/zkevm-contracts/contracts/interfaces/IPolygonZkEVMBridge.sol";
Expand Down Expand Up @@ -37,10 +37,8 @@ contract ForkingManagerTest is Test {
bytes32 internal constant _IMPLEMENTATION_SLOT =
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

IBasePolygonZkEVMGlobalExitRoot public globalExitMock =
IBasePolygonZkEVMGlobalExitRoot(
0x1234567890123456789012345678901234567892
);
IPolygonZkEVMGlobalExitRoot public globalExitMock =
IPolygonZkEVMGlobalExitRoot(0x1234567890123456789012345678901234567892);
bytes32 public genesisRoot =
bytes32(
0x827a9240c96ccb855e4943cc9bc49a50b1e91ba087007441a1ae5f9df8d1c57c
Expand Down Expand Up @@ -142,7 +140,9 @@ contract ForkingManagerTest is Test {
address(forkmanager),
address(0x0),
address(zkevm),
address(bridge)
address(bridge),
bytes32(0),
bytes32(0)
);
bridge.initialize(
address(forkmanager),
Expand Down Expand Up @@ -797,4 +797,62 @@ contract ForkingManagerTest is Test {
})
);
}

function testSetsCorrectGlobalExitRoot() public {
// Set completely randcom exit hashes to make them non-zero
bytes32 lastMainnetExitRoot = keccak256(abi.encode(2));
bytes32 lastRollupExitRoot = keccak256(abi.encode(1));
vm.prank(address(bridge));
globalExitRoot.updateExitRoot(lastMainnetExitRoot);
vm.prank(address(zkevm));
globalExitRoot.updateExitRoot(lastRollupExitRoot);

// Mint and approve the arbitration fee for the test contract
forkonomicToken.approve(address(forkmanager), arbitrationFee);
vm.prank(address(this));
forkonomicToken.mint(address(this), arbitrationFee);

// Call the initiateFork function to create a new fork
uint256 testTimestamp = 12354234;
vm.warp(testTimestamp);
forkmanager.initiateFork(
disputeData,
IForkingManager.NewImplementations({
bridgeImplementation: newBridgeImplementation,
zkEVMImplementation: newZkevmImplementation,
forkonomicTokenImplementation: newForkonomicTokenImplementation,
forkingManagerImplementation: newForkmanagerImplementation,
globalExitRootImplementation: newGlobalExitRootImplementation,
verifier: newVerifierImplementation,
forkID: newForkID
})
);

vm.warp(testTimestamp + forkmanager.forkPreparationTime() + 1);
forkmanager.executeFork1();
(address child1, address child2) = globalExitRoot.getChildren();

assertEq(
IPolygonZkEVMGlobalExitRoot(globalExitRoot).lastMainnetExitRoot(),
IPolygonZkEVMGlobalExitRoot(child1).lastMainnetExitRoot()
);
assertEq(
IPolygonZkEVMGlobalExitRoot(globalExitRoot).lastRollupExitRoot(),
IPolygonZkEVMGlobalExitRoot(child1).lastRollupExitRoot(),
"lastRollupExitRoot not the same"
);
assertEq(
IPolygonZkEVMGlobalExitRoot(globalExitRoot).getLastGlobalExitRoot(),
IPolygonZkEVMGlobalExitRoot(child1).getLastGlobalExitRoot()
);
forkmanager.executeFork2();
assertEq(
IPolygonZkEVMGlobalExitRoot(globalExitRoot).lastMainnetExitRoot(),
IPolygonZkEVMGlobalExitRoot(child2).lastMainnetExitRoot()
);
assertEq(
IPolygonZkEVMGlobalExitRoot(globalExitRoot).lastRollupExitRoot(),
IPolygonZkEVMGlobalExitRoot(child2).lastRollupExitRoot()
);
}
}
4 changes: 3 additions & 1 deletion test/L1GlobalChainInfoPublisher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ contract L1GlobalChainInfoPublisherTest is Test {
address(forkmanager),
address(0x0),
address(zkevm),
address(bridge)
address(bridge),
bytes32(0),
bytes32(0)
);
bridge.initialize(
address(forkmanager),
Expand Down
4 changes: 3 additions & 1 deletion test/L1GlobalForkRequester.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ contract L1GlobalForkRequesterTest is Test {
address(forkmanager),
address(0x0),
address(zkevm),
address(bridge)
address(bridge),
bytes32(0),
bytes32(0)
);
bridge.initialize(
address(forkmanager),
Expand Down

0 comments on commit d30bc74

Please sign in to comment.