Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delayed fork proposals #89

Merged
merged 3 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 27 additions & 39 deletions contracts/ForkingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,12 @@ contract ForkingManager is IForkingManager, ForkableStructure {
// Fee that needs to be paid to initiate a fork
uint256 public arbitrationFee;

// Dispute contract and call to identify the dispute
// that will be used to initiate/justify the fork
struct DisputeData {
address disputeContract;
bytes disputeCall;
}

// Following variables are defined during the fork proposal
DisputeData public disputeData;
NewImplementations public proposedImplementations;
uint256 public executionTimeForProposal = 0;

// Struct containing the addresses of the new implementations
struct NewImplementations {
address bridgeImplementation;
address zkEVMImplementation;
address forkonomicTokenImplementation;
address forkingManagerImplementation;
address globalExitRootImplementation;
address verifier;
uint64 forkID;
}

// Struct that holds an address pair used to store the new child contracts
struct AddressPair {
address one;
address two;
}

// Struct containing the addresses of the new instances
struct NewInstances {
AddressPair forkingManager;
AddressPair bridge;
AddressPair zkEVM;
AddressPair forkonomicToken;
AddressPair globalExitRoot;
}
uint256 public immutable forkPreparationTime = 1 weeks;

/// @inheritdoc IForkingManager
function initialize(
Expand All @@ -93,21 +65,40 @@ contract ForkingManager is IForkingManager, ForkableStructure {
}

/**
* @notice function to initiate and execute the fork
* @notice function to initiate and schedule the fork
* @param _disputeData the dispute contract and call to identify the dispute
* @param newImplementations the addresses of the new implementations that will
* be used to create the second children of the contracts
* @param _newImplementations the addresses of the new implementations that will
*/
function initiateFork(
DisputeData memory _disputeData,
NewImplementations calldata newImplementations
NewImplementations calldata _newImplementations
) external onlyBeforeForking {
require(executionTimeForProposal == 0, "ForkingManager: fork pending");
// Charge the forking fee
IERC20(forkonomicToken).safeTransferFrom(
msg.sender,
address(this),
arbitrationFee
);

disputeData = _disputeData;
proposedImplementations = _newImplementations;
// solhint-disable-next-line not-rely-on-time
executionTimeForProposal = (block.timestamp + forkPreparationTime);
}

/**
* @dev function that executes a fork proposal
*/
function executeFork() external onlyBeforeForking {
require(
executionTimeForProposal != 0 &&
// solhint-disable-next-line not-rely-on-time
executionTimeForProposal <= block.timestamp,
"ForkingManager: fork not ready"
);
NewImplementations memory newImplementations = proposedImplementations;

// Create the children of each contract
NewInstances memory newInstances;
(
Expand Down Expand Up @@ -268,8 +259,5 @@ contract ForkingManager is IForkingManager, ForkableStructure {
newInstances.zkEVM.two,
newInstances.bridge.two
);

// Store the dispute contract and call to identify the dispute
disputeData = _disputeData;
}
}
33 changes: 33 additions & 0 deletions contracts/interfaces/IForkingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@ pragma solidity ^0.8.20;
import {IForkableStructure} from "./IForkableStructure.sol";

interface IForkingManager is IForkableStructure {
// Dispute contract and call to identify the dispute
// that will be used to initiate/justify the fork
struct DisputeData {
address disputeContract;
bytes disputeCall;
}

// Struct containing the addresses of the new implementations
struct NewImplementations {
address bridgeImplementation;
address zkEVMImplementation;
address forkonomicTokenImplementation;
address forkingManagerImplementation;
address globalExitRootImplementation;
address verifier;
uint64 forkID;
}

// Struct that holds an address pair used to store the new child contracts
struct AddressPair {
address one;
address two;
}

// Struct containing the addresses of the new instances
struct NewInstances {
AddressPair forkingManager;
AddressPair bridge;
AddressPair zkEVM;
AddressPair forkonomicToken;
AddressPair globalExitRoot;
}

function initialize(
address _zkEVM,
address _bridge,
Expand Down
Loading
Loading