Skip to content

Commit

Permalink
Delayed fork proposals (#89)
Browse files Browse the repository at this point in the history
This PR allows to submit delayed/scheduled fork proposals.

I image that each adjudication framework will enforce its own delay and hence, we don't enforce a specific number.

The main concern about this implementation is that different delays might cause overlapping scheduled forks. This implementation copies the forkschedules then just to the new forking managers. This is okay, as different forks should be scheduled to remove different courts.(This could be enforced by outside non-core helper contracts at the submission time of the tx.
  • Loading branch information
josojo authored Nov 4, 2023
1 parent 46f9e35 commit 576c0fa
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 101 deletions.
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

0 comments on commit 576c0fa

Please sign in to comment.