Skip to content

Commit

Permalink
forkId should be updated only for one fork(if necessary) (#85)
Browse files Browse the repository at this point in the history
* forkId should be the same

* provide new forkId in parameters
  • Loading branch information
josojo authored Oct 25, 2023
1 parent 83266f9 commit 46f9e35
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 3 additions & 2 deletions contracts/ForkingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ contract ForkingManager is IForkingManager, ForkableStructure {
address forkingManagerImplementation;
address globalExitRootImplementation;
address verifier;
uint64 forkID;
}

// Struct that holds an address pair used to store the new child contracts
Expand Down Expand Up @@ -156,7 +157,7 @@ contract ForkingManager is IForkingManager, ForkableStructure {
.trustedAggregatorTimeout(),
chainID: ChainIdManager(chainIdManager)
.getNextUsableChainId(),
forkID: (IPolygonZkEVM(zkEVM).chainID() / 2) * 2 + 3
forkID: IPolygonZkEVM(zkEVM).forkID()
});
IForkableZkEVM(newInstances.zkEVM.one).initialize(
newInstances.forkingManager.one,
Expand All @@ -173,7 +174,7 @@ contract ForkingManager is IForkingManager, ForkableStructure {
);
initializePackedParameters.chainID = ChainIdManager(chainIdManager)
.getNextUsableChainId();
initializePackedParameters.forkID += 1;
initializePackedParameters.forkID = newImplementations.forkID;
IForkableZkEVM(newInstances.zkEVM.two).initialize(
newInstances.forkingManager.two,
zkEVM,
Expand Down
15 changes: 12 additions & 3 deletions test/ForkingManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ contract ForkingManagerTest is Test {
0x827a9240c96ccb855e4943cc9bc49a50b1e91ba087007441a1ae5f9df8d1c57c
);
uint64 public forkID = 3;
uint64 public newForkID = 4;
uint64 public chainID = 4;
uint32 public networkID = 10;
uint64 public pendingStateTimeout = 123;
Expand Down Expand Up @@ -208,7 +209,8 @@ contract ForkingManagerTest is Test {
forkonomicTokenImplementation: newForkonomicTokenImplementation,
forkingManagerImplementation: newForkmanagerImplementation,
globalExitRootImplementation: newGlobalExitRootImplementation,
verifier: newVerifierImplementation
verifier: newVerifierImplementation,
forkID: newForkID
})
);

Expand All @@ -235,7 +237,8 @@ contract ForkingManagerTest is Test {
forkonomicTokenImplementation: newForkonomicTokenImplementation,
forkingManagerImplementation: newForkmanagerImplementation,
globalExitRootImplementation: newGlobalExitRootImplementation,
verifier: newVerifierImplementation
verifier: newVerifierImplementation,
forkID: newForkID
})
);
}
Expand Down Expand Up @@ -281,7 +284,8 @@ contract ForkingManagerTest is Test {
forkonomicTokenImplementation: newForkonomicTokenImplementation,
forkingManagerImplementation: newForkmanagerImplementation,
globalExitRootImplementation: newGlobalExitRootImplementation,
verifier: newVerifierImplementation
verifier: newVerifierImplementation,
forkID: newForkID
})
);

Expand Down Expand Up @@ -349,6 +353,11 @@ contract ForkingManagerTest is Test {
);
assertEq(ForkableZkEVM(childZkevm1).chainID(), firstChainId);
assertEq(ForkableZkEVM(childZkevm2).chainID(), secondChainId);
assertEq(
ForkableZkEVM(childZkevm1).forkID(),
ForkableZkEVM(zkevm).forkID()
);
assertEq(ForkableZkEVM(childZkevm2).forkID(), newForkID);
}
{
// Fetch the children from the ForkonomicToken contract
Expand Down

0 comments on commit 46f9e35

Please sign in to comment.