Skip to content

Commit

Permalink
fix mini problems
Browse files Browse the repository at this point in the history
  • Loading branch information
invocamanman committed Mar 28, 2024
1 parent 19a413f commit c70368d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
18 changes: 6 additions & 12 deletions contracts/v2/PolygonRollupManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ contract PolygonRollupManager is
.accInputHash;

// Do not copy state transitions since it was not used

_zkGasPrice = _legacyBatchFee / 1000;
}
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
35 changes: 30 additions & 5 deletions contracts/v2/PolygonZkEVMGlobalExitRootV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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()
)
);

Expand Down Expand Up @@ -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
Expand All @@ -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));
}
}
5 changes: 5 additions & 0 deletions contracts/v2/interfaces/IPolygonRollupManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit c70368d

Please sign in to comment.