Skip to content

Commit

Permalink
very first draft(to be worked on)
Browse files Browse the repository at this point in the history
  • Loading branch information
josojo committed Nov 6, 2023
1 parent f7e5806 commit d9b60dd
Show file tree
Hide file tree
Showing 14 changed files with 279 additions and 97 deletions.
8 changes: 5 additions & 3 deletions contracts/ChainIdManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ contract ChainIdManager is Owned {
// Fee to use up a Chain ID
uint256 public immutable gasBurnAmount = 1000000;

constructor(uint64 _chainIdCounter) Owned() {chainIdCounter = _chainIdCounter;}
constructor(uint64 _chainIdCounter) Owned() {
chainIdCounter = _chainIdCounter;
}

/**
* @dev Adds a Chain ID to the deny list, this can be done if the chainId is used by another project
Expand All @@ -37,7 +39,7 @@ contract ChainIdManager is Owned {
* @return chainId The next usable Chain ID
*/
function getNextUsableChainId() public returns (uint64 chainId) {
// The burnGas function introduces a cost to use up chainIds.
// The burnGas function introduces a cost to use up chainIds.
// There are uint64(2**63=9.223372e+18) chainIds minus the publicly used chainIds available.
// Using all of the chainIds would cost 9.223372e+18 * gasBurnAmount = 9.223372e+24 gas = 6.1489147e+17 blocks = 237226647377 years
burnGas();
Expand All @@ -51,6 +53,6 @@ contract ChainIdManager is Owned {
function burnGas() public view {
uint256 counter = 0;
uint256 _lowestLimit = gasleft() - gasBurnAmount;
while(gasleft() > _lowestLimit) counter++;
while (gasleft() > _lowestLimit) counter++;
}
}
24 changes: 20 additions & 4 deletions contracts/ForkableBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ contract ForkableBridge is
PolygonZkEVMBridge._setAndCheckClaimed(index);
}

// @inheritdoc IForkableBridge
function createChild1() external onlyForkManger returns (address) {
// process all pending deposits/messages before coping over the state root.
updateGlobalExitRoot();
return _createChild1();
}

// @inheritdoc IForkableBridge
function createChild2(
address implementation
) external onlyForkManger returns (address) {
// process all pending deposits/messages before coping over the state root.
updateGlobalExitRoot();
return _createChild2(implementation);
}

// @inheritdoc IForkableBridge
function createChildren(
address implementation
Expand Down Expand Up @@ -200,7 +216,7 @@ contract ForkableBridge is
public
payable
override(PolygonZkEVMBridge, IPolygonZkEVMBridge)
onlyBeforeForking
onlyBeforeCreatingChild1
{
PolygonZkEVMBridge.bridgeAsset(
destinationNetwork,
Expand All @@ -222,7 +238,7 @@ contract ForkableBridge is
payable
virtual
override(PolygonZkEVMBridge, IPolygonZkEVMBridge)
onlyBeforeForking
onlyBeforeCreatingChild1
{
PolygonZkEVMBridge.bridgeMessage(
destinationNetwork,
Expand All @@ -246,7 +262,7 @@ contract ForkableBridge is
)
public
override(IPolygonZkEVMBridge, PolygonZkEVMBridge)
onlyBeforeForking
onlyBeforeCreatingChild1
{
PolygonZkEVMBridge.claimMessage(
smtProof,
Expand Down Expand Up @@ -276,7 +292,7 @@ contract ForkableBridge is
)
public
override(IPolygonZkEVMBridge, PolygonZkEVMBridge)
onlyBeforeForking
onlyBeforeCreatingChild1
{
PolygonZkEVMBridge.claimAsset(
smtProof,
Expand Down
15 changes: 15 additions & 0 deletions contracts/ForkableGlobalExitRoot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ contract ForkableGlobalExitRoot is
);
}

/// @dev Public interface to create children. This can only be done by the forkmanager
/// @return The addresses of the two children
function createChild1() external onlyForkManger returns (address) {
return _createChild1();
}

/// @dev Public interface to create children. This can only be done by the forkmanager
/// @param implementation Allows to pass a different implementation contract for the second proxied child.
/// @return The addresses of the two children
function createChild2(
address implementation
) external onlyForkManger returns (address) {
return _createChild2(implementation);
}

/// @dev Public interface to create children. This can only be done by the forkmanager
/// @param implementation Allows to pass a different implementation contract for the second proxied child.
/// @return The addresses of the two children
Expand Down
24 changes: 18 additions & 6 deletions contracts/ForkableZkEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ contract ForkableZkEVM is ForkableStructure, IForkableZkEVM, PolygonZkEVM {
);
}

// @inheritdoc IForkableZkEVM
function createChild1() external onlyForkManger returns (address) {
return _createChild1();
}

// @inheritdoc IForkableZkEVM
function createChild2(
address implementation
) external onlyForkManger returns (address) {
return _createChild2(implementation);
}

// @inheritdoc IForkableZkEVM
function createChildren(
address implementation
Expand All @@ -48,7 +60,7 @@ contract ForkableZkEVM is ForkableStructure, IForkableZkEVM, PolygonZkEVM {
}

////////////////////////////////////////////////////////////////////////////
// For the following functions a modifier called: onlyBeforeForking is added.
// For the following functions a modifier called: onlyBeforeCreatingChild1 is added.
// This ensure that the functions do not change the consolidated state after forking.
///////////////////////////////////////////////////////////////////////////

Expand All @@ -59,7 +71,7 @@ contract ForkableZkEVM is ForkableStructure, IForkableZkEVM, PolygonZkEVM {
bytes32 newLocalExitRoot,
bytes32 newStateRoot,
bytes32[24] calldata proof
) public override onlyBeforeForking {
) public override onlyBeforeCreatingChild1 {
PolygonZkEVM.verifyBatches(
pendingStateNum,
initNumBatch,
Expand All @@ -77,7 +89,7 @@ contract ForkableZkEVM is ForkableStructure, IForkableZkEVM, PolygonZkEVM {
bytes32 newLocalExitRoot,
bytes32 newStateRoot,
bytes32[24] calldata proof
) public override onlyBeforeForking {
) public override onlyBeforeCreatingChild1 {
PolygonZkEVM.verifyBatchesTrustedAggregator(
pendingStateNum,
initNumBatch,
Expand All @@ -90,7 +102,7 @@ contract ForkableZkEVM is ForkableStructure, IForkableZkEVM, PolygonZkEVM {

function consolidatePendingState(
uint64 pendingStateNum
) public override onlyBeforeForking {
) public override onlyBeforeCreatingChild1 {
PolygonZkEVM.consolidatePendingState(pendingStateNum);
}

Expand All @@ -102,7 +114,7 @@ contract ForkableZkEVM is ForkableStructure, IForkableZkEVM, PolygonZkEVM {
bytes32 newLocalExitRoot,
bytes32 newStateRoot,
bytes32[24] calldata proof
) public override onlyBeforeForking {
) public override onlyBeforeCreatingChild1 {
PolygonZkEVM.overridePendingState(
initPendingStateNum,
finalPendingStateNum,
Expand All @@ -119,7 +131,7 @@ contract ForkableZkEVM is ForkableStructure, IForkableZkEVM, PolygonZkEVM {
function sequenceBatches(
BatchData[] calldata batches,
address l2Coinbase
) public override onlyBeforeForking {
) public override onlyBeforeCreatingChild1 {
PolygonZkEVM.sequenceBatches(batches, l2Coinbase);
}

Expand Down
Loading

0 comments on commit d9b60dd

Please sign in to comment.