diff --git a/contracts/v2/PolygonRollupManager.sol b/contracts/v2/PolygonRollupManager.sol index f02d203fe..eb5e2a15c 100644 --- a/contracts/v2/PolygonRollupManager.sol +++ b/contracts/v2/PolygonRollupManager.sol @@ -550,7 +550,6 @@ contract PolygonRollupManager is .accInputHash; // Do not copy state transitions since it was not used - _zkGasPrice = _legacyBatchFee / 1000; } } @@ -881,11 +880,10 @@ contract PolygonRollupManager is rollup.rollupTypeID = newRollupTypeID; // TODO Vulnerability fron running attack TT actually hard to handle - if ( - rollup.lastPendingState != rollup.lastPendingStateConsolidated - ) { - revert CannotUpdateWithNotConsolidatedPendingState() + if (rollup.lastPendingState != rollup.lastPendingStateConsolidated) { + revert CannotUpdateWithUnconsolidatedPendingState(); } + uint64 lastVerifiedSequence = getLastVerifiedSequence(rollupID); rollup.lastVerifiedSequenceBeforeUpgrade = lastVerifiedSequence; @@ -2083,13 +2081,9 @@ contract PolygonRollupManager is revert NewStateRootNotInsidePrime(); } - uint64 initBlobNum = rollup - .sequences[initSequenceNum] - .currentBlobNum; + uint64 initBlobNum = rollup.sequences[initSequenceNum].currentBlobNum; - uint64 finalBlobNum = rollup - .sequences[finalSequenceNum] - .currentBlobNum; + uint64 finalBlobNum = rollup.sequences[finalSequenceNum].currentBlobNum; uint256 ptr = ptrAccumulateInputSnarkBytes; @@ -2125,7 +2119,7 @@ contract PolygonRollupManager is mstore(ptr, newStateRoot) ptr := add(ptr, 32) - // store newBlobStateRoot + // store newBlobStateRoot // note this parameters is unused currently mstore(ptr, 0) ptr := add(ptr, 32) diff --git a/contracts/v2/PolygonZkEVMGlobalExitRootV2.sol b/contracts/v2/PolygonZkEVMGlobalExitRootV2.sol index 68d521861..aee80b8b8 100644 --- a/contracts/v2/PolygonZkEVMGlobalExitRootV2.sol +++ b/contracts/v2/PolygonZkEVMGlobalExitRootV2.sol @@ -6,13 +6,15 @@ import "./interfaces/IPolygonZkEVMGlobalExitRootV2.sol"; import "./lib/PolygonZkEVMGlobalExitRootBaseStorage.sol"; import "../lib/GlobalExitRootLib.sol"; import "./lib/DepositContractBase.sol"; +import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; /** * Contract responsible for managing the exit roots across multiple networks */ contract PolygonZkEVMGlobalExitRootV2 is PolygonZkEVMGlobalExitRootBaseStorage, - DepositContractBase + DepositContractBase, + Initializable { // PolygonZkEVMBridge address address public immutable bridgeAddress; @@ -37,6 +39,14 @@ contract PolygonZkEVMGlobalExitRootV2 is bridgeAddress = _bridgeAddress; } + // Reset the previous tree + function initialize() external virtual initializer { + for (uint256 i = 0; i < _DEPOSIT_CONTRACT_TREE_DEPTH; i++) { + delete _branch[i]; + } + depositCount = 0; + } + /** * @notice Update the exit root of one of the networks and the global exit root * @param newRoot new exit tree root @@ -71,9 +81,12 @@ contract PolygonZkEVMGlobalExitRootV2 is // save new leaf in L1InfoTree _addLeaf( getLeafValue( - newGlobalExitRoot, - lastBlockHash, - uint64(block.timestamp) + getL1InfoTreeHash( + newGlobalExitRoot, + lastBlockHash, + uint64(block.timestamp) + ), + getRoot() ) ); @@ -113,7 +126,7 @@ contract PolygonZkEVMGlobalExitRootV2 is * @param lastBlockHash Last accesible block hash * @param timestamp Ethereum timestamp in seconds */ - function getLeafValue( + function getL1InfoTreeHash( bytes32 newGlobalExitRoot, uint256 lastBlockHash, uint64 timestamp @@ -123,4 +136,16 @@ contract PolygonZkEVMGlobalExitRootV2 is abi.encodePacked(newGlobalExitRoot, lastBlockHash, timestamp) ); } + + /** + * @notice Given the leaf data returns the leaf hash + * @param l1InfoRoot Last global exit root + * @param l1InfoTreeHash Last accesible block hash + */ + function getLeafValue( + bytes32 l1InfoRoot, + bytes32 l1InfoTreeHash + ) public pure returns (bytes32) { + return keccak256(abi.encodePacked(l1InfoRoot, l1InfoTreeHash)); + } } diff --git a/contracts/v2/interfaces/IPolygonRollupManager.sol b/contracts/v2/interfaces/IPolygonRollupManager.sol index da7a5c4cc..7534e9ce7 100644 --- a/contracts/v2/interfaces/IPolygonRollupManager.sol +++ b/contracts/v2/interfaces/IPolygonRollupManager.sol @@ -227,4 +227,9 @@ interface IPolygonRollupManager { * @dev When a set a zkgasprice out of range */ error zkGasPriceOfRange(); + + /** + * @dev Cannot update from network admin with unconsolidated pending state + */ + error CannotUpdateWithUnconsolidatedPendingState(); }