Skip to content

Commit

Permalink
chore: revert formatting to avoid unnecessary diff
Browse files Browse the repository at this point in the history
Signed-off-by: JDawg287 <sjcool420@hotmail.co.uk>
  • Loading branch information
JDawg287 committed Feb 24, 2025
1 parent 0cf729a commit 8faa01c
Show file tree
Hide file tree
Showing 55 changed files with 9,232 additions and 2,250 deletions.
55 changes: 41 additions & 14 deletions contracts/PolygonZkEVMGlobalExitRootV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
/**
* Contract responsible for managing the exit roots across multiple networks
*/
contract PolygonZkEVMGlobalExitRootV2 is PolygonZkEVMGlobalExitRootBaseStorage, DepositContractBase, Initializable {
contract PolygonZkEVMGlobalExitRootV2 is
PolygonZkEVMGlobalExitRootBaseStorage,
DepositContractBase,
Initializable
{
// PolygonZkEVMBridge address
address public immutable bridgeAddress;

Expand All @@ -24,13 +28,19 @@ contract PolygonZkEVMGlobalExitRootV2 is PolygonZkEVMGlobalExitRootBaseStorage,
/**
* @dev Emitted when the global exit root is updated
*/
event UpdateL1InfoTree(bytes32 indexed mainnetExitRoot, bytes32 indexed rollupExitRoot);
event UpdateL1InfoTree(
bytes32 indexed mainnetExitRoot,
bytes32 indexed rollupExitRoot
);

/**
* @dev Emitted when the global exit root is updated with the L1InfoTree leaf information
*/
event UpdateL1InfoTreeV2(
bytes32 currentL1InfoRoot, uint32 indexed leafCount, uint256 blockhash, uint64 minTimestamp
bytes32 currentL1InfoRoot,
uint32 indexed leafCount,
uint256 blockhash,
uint64 minTimestamp
);

/**
Expand Down Expand Up @@ -84,8 +94,10 @@ contract PolygonZkEVMGlobalExitRootV2 is PolygonZkEVMGlobalExitRootBaseStorage,
revert OnlyAllowedContracts();
}

bytes32 newGlobalExitRoot =
GlobalExitRootLib.calculateGlobalExitRoot(cacheLastMainnetExitRoot, cacheLastRollupExitRoot);
bytes32 newGlobalExitRoot = GlobalExitRootLib.calculateGlobalExitRoot(
cacheLastMainnetExitRoot,
cacheLastRollupExitRoot
);

// If it already exists, do not modify the blockhash
if (globalExitRootMap[newGlobalExitRoot] == 0) {
Expand All @@ -105,7 +117,10 @@ contract PolygonZkEVMGlobalExitRootV2 is PolygonZkEVMGlobalExitRootBaseStorage,
// Store L1InfoRoot
l1InfoRootMap[uint32(depositCount)] = currentL1InfoRoot;

emit UpdateL1InfoTree(cacheLastMainnetExitRoot, cacheLastRollupExitRoot);
emit UpdateL1InfoTree(
cacheLastMainnetExitRoot,
cacheLastRollupExitRoot
);

emit UpdateL1InfoTreeV2(
currentL1InfoRoot,
Expand All @@ -120,13 +135,22 @@ contract PolygonZkEVMGlobalExitRootV2 is PolygonZkEVMGlobalExitRootBaseStorage,
* @notice Return last global exit root
*/
function getLastGlobalExitRoot() public view returns (bytes32) {
return GlobalExitRootLib.calculateGlobalExitRoot(lastMainnetExitRoot, lastRollupExitRoot);
return
GlobalExitRootLib.calculateGlobalExitRoot(
lastMainnetExitRoot,
lastRollupExitRoot
);
}

/**
* @notice Computes and returns the merkle root of the L1InfoTree
*/
function getRoot() public view override(DepositContractBase, IPolygonZkEVMGlobalExitRootV2) returns (bytes32) {
function getRoot()
public
view
override(DepositContractBase, IPolygonZkEVMGlobalExitRootV2)
returns (bytes32)
{
return super.getRoot();
}

Expand All @@ -136,11 +160,14 @@ contract PolygonZkEVMGlobalExitRootV2 is PolygonZkEVMGlobalExitRootBaseStorage,
* @param lastBlockHash Last accessible block hash
* @param timestamp Ethereum timestamp in seconds
*/
function getLeafValue(bytes32 newGlobalExitRoot, uint256 lastBlockHash, uint64 timestamp)
public
pure
returns (bytes32)
{
return keccak256(abi.encodePacked(newGlobalExitRoot, lastBlockHash, timestamp));
function getLeafValue(
bytes32 newGlobalExitRoot,
uint256 lastBlockHash,
uint64 timestamp
) public pure returns (bytes32) {
return
keccak256(
abi.encodePacked(newGlobalExitRoot, lastBlockHash, timestamp)
);
}
}
5 changes: 4 additions & 1 deletion contracts/PolygonZkEVMTimelock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ contract PolygonZkEVMTimelock is TimelockController {
* If Polygon ZK-EVM is on emergency state the minDelay will be 0 instead.
*/
function getMinDelay() public view override returns (uint256 duration) {
if (address(polygonZkEVM) != address(0) && polygonZkEVM.isEmergencyState()) {
if (
address(polygonZkEVM) != address(0) &&
polygonZkEVM.isEmergencyState()
) {
return 0;
} else {
return super.getMinDelay();
Expand Down
41 changes: 30 additions & 11 deletions contracts/consensus/validium/PolygonDataCommittee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
* Contract responsible managing the data committee that will verify that the data sent for a validium is singed by a committee
* It is advised to give the owner of the contract to a timelock contract once the data committee is set
*/
contract PolygonDataCommittee is IDataAvailabilityProtocol, IPolygonDataCommitteeErrors, OwnableUpgradeable {
contract PolygonDataCommittee is
IDataAvailabilityProtocol,
IPolygonDataCommitteeErrors,
OwnableUpgradeable
{
/**
* @notice Struct which will store all the data of the committee members
* @param url string that represents the URL of the member to be used to access the data
Expand Down Expand Up @@ -66,10 +70,11 @@ contract PolygonDataCommittee is IDataAvailabilityProtocol, IPolygonDataCommitte
* @param urls List of urls of the members of the committee
* @param addrsBytes Byte array that contains the addressess of the members of the committee
*/
function setupCommittee(uint256 _requiredAmountOfSignatures, string[] calldata urls, bytes calldata addrsBytes)
external
onlyOwner
{
function setupCommittee(
uint256 _requiredAmountOfSignatures,
string[] calldata urls,
bytes calldata addrsBytes
) external onlyOwner {
uint256 membersLength = urls.length;
if (membersLength < _requiredAmountOfSignatures) {
revert TooManyRequiredSignatures();
Expand All @@ -84,8 +89,12 @@ contract PolygonDataCommittee is IDataAvailabilityProtocol, IPolygonDataCommitte
address lastAddr;
for (uint256 i = 0; i < membersLength; i++) {
uint256 currentAddresStartingByte = i * _ADDR_SIZE;
address currentMemberAddr =
address(bytes20(addrsBytes[currentAddresStartingByte:currentAddresStartingByte + _ADDR_SIZE]));
address currentMemberAddr = address(
bytes20(
addrsBytes[currentAddresStartingByte:currentAddresStartingByte +
_ADDR_SIZE]
)
);

// Check url is not empty
if (bytes(urls[i]).length == 0) {
Expand Down Expand Up @@ -113,13 +122,19 @@ contract PolygonDataCommittee is IDataAvailabilityProtocol, IPolygonDataCommitte
* [signature 0, ..., signature requiredAmountOfSignatures -1, address 0, ... address N]
* note that each ECDSA signatures are used, therefore each one must be 65 bytes
*/
function verifyMessage(bytes32 signedHash, bytes calldata signaturesAndAddrs) external view {
function verifyMessage(
bytes32 signedHash,
bytes calldata signaturesAndAddrs
) external view {
// Save storage variable on cache since will be used multiple times
uint256 cacheRequiredAmountOfSignatures = requiredAmountOfSignatures;

// pre-check: byte array size
uint256 splitByte = _SIGNATURE_SIZE * cacheRequiredAmountOfSignatures;
if (signaturesAndAddrs.length < splitByte || (signaturesAndAddrs.length - splitByte) % _ADDR_SIZE != 0) {
if (
signaturesAndAddrs.length < splitByte ||
(signaturesAndAddrs.length - splitByte) % _ADDR_SIZE != 0
) {
revert UnexpectedAddrsAndSignaturesSize();
}

Expand All @@ -137,15 +152,19 @@ contract PolygonDataCommittee is IDataAvailabilityProtocol, IPolygonDataCommitte
// Recover currnet signer from the signature
address currentSigner = ECDSA.recover(
signedHash,
signaturesAndAddrs[currentSignatureStartingByte:currentSignatureStartingByte + _SIGNATURE_SIZE]
signaturesAndAddrs[currentSignatureStartingByte:currentSignatureStartingByte +
_SIGNATURE_SIZE]
);

// Search the recovered signer inside the address array
bool currentSignerIsPartOfCommittee = false;
for (uint256 j = lastAddrIndexUsed; j < addrsLen; j++) {
uint256 currentAddresStartingByte = splitByte + j * _ADDR_SIZE;
address committeeAddr = address(
bytes20(signaturesAndAddrs[currentAddresStartingByte:currentAddresStartingByte + _ADDR_SIZE])
bytes20(
signaturesAndAddrs[currentAddresStartingByte:currentAddresStartingByte +
_ADDR_SIZE]
)
);
if (committeeAddr == currentSigner) {
lastAddrIndexUsed = j + 1;
Expand Down
65 changes: 52 additions & 13 deletions contracts/consensus/validium/PolygonValidiumEtrog.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ contract PolygonValidiumEtrog is PolygonRollupBaseEtrog, IPolygonValidium {
IERC20Upgradeable _pol,
IPolygonZkEVMBridgeV2 _bridgeAddress,
PolygonRollupManager _rollupManager
) PolygonRollupBaseEtrog(_globalExitRootManager, _pol, _bridgeAddress, _rollupManager) {}
)
PolygonRollupBaseEtrog(
_globalExitRootManager,
_pol,
_bridgeAddress,
_rollupManager
)
{}

/////////////////////////////////////
// Sequence/Verify batches functions
Expand Down Expand Up @@ -99,15 +106,19 @@ contract PolygonValidiumEtrog is PolygonRollupBaseEtrog, IPolygonValidium {
}

// Check max sequence timestamp inside of range
if (uint256(maxSequenceTimestamp) > (block.timestamp + TIMESTAMP_RANGE)) {
if (
uint256(maxSequenceTimestamp) > (block.timestamp + TIMESTAMP_RANGE)
) {
revert MaxTimestampSequenceInvalid();
}

// Update global exit root if there are new deposits
bridgeAddress.updateGlobalExitRoot();

// Get global batch variables
bytes32 l1InfoRoot = globalExitRootManager.l1InfoRootMap(l1InfoTreeLeafCount);
bytes32 l1InfoRoot = globalExitRootManager.l1InfoRootMap(
l1InfoTreeLeafCount
);

if (l1InfoRoot == bytes32(0)) {
revert L1InfoTreeLeafCountInvalid();
Expand Down Expand Up @@ -138,7 +149,10 @@ contract PolygonValidiumEtrog is PolygonRollupBaseEtrog, IPolygonValidium {
)
);

if (hashedForcedBatchData != forcedBatches[currentLastForceBatchSequenced]) {
if (
hashedForcedBatchData !=
forcedBatches[currentLastForceBatchSequenced]
) {
revert ForcedDataDoesNotMatch();
}

Expand Down Expand Up @@ -186,12 +200,16 @@ contract PolygonValidiumEtrog is PolygonRollupBaseEtrog, IPolygonValidium {

// Check if there has been forced batches
if (currentLastForceBatchSequenced != initLastForceBatchSequenced) {
uint64 forcedBatchesSequenced = currentLastForceBatchSequenced - initLastForceBatchSequenced;
uint64 forcedBatchesSequenced = currentLastForceBatchSequenced -
initLastForceBatchSequenced;
// substract forced batches
nonForcedBatchesSequenced -= forcedBatchesSequenced;

// Transfer pol for every forced batch submitted
pol.safeTransfer(address(rollupManager), calculatePolPerForceBatch() * (forcedBatchesSequenced));
pol.safeTransfer(
address(rollupManager),
calculatePolPerForceBatch() * (forcedBatchesSequenced)
);

// Store new last force batch sequenced
lastForceBatchSequenced = currentLastForceBatchSequenced;
Expand All @@ -200,15 +218,23 @@ contract PolygonValidiumEtrog is PolygonRollupBaseEtrog, IPolygonValidium {
// Pay collateral for every non-forced batch submitted
if (nonForcedBatchesSequenced != 0) {
pol.safeTransferFrom(
msg.sender, address(rollupManager), rollupManager.getBatchFee() * nonForcedBatchesSequenced
msg.sender,
address(rollupManager),
rollupManager.getBatchFee() * nonForcedBatchesSequenced
);

// Validate that the data availability protocol accepts the dataAvailabilityMessage
// note This is a view function, so there's not much risk even if this contract was vulnerable to reentrant attacks
dataAvailabilityProtocol.verifyMessage(expectedFinalAccInputHash, dataAvailabilityMessage);
dataAvailabilityProtocol.verifyMessage(
expectedFinalAccInputHash,
dataAvailabilityMessage
);
}

uint64 currentBatchSequenced = rollupManager.onSequenceBatches(uint64(batchesNum), currentAccInputHash);
uint64 currentBatchSequenced = rollupManager.onSequenceBatches(
uint64(batchesNum),
currentAccInputHash
);

// Check expectedFinalAccInputHash
if (currentAccInputHash != expectedFinalAccInputHash) {
Expand Down Expand Up @@ -239,7 +265,13 @@ contract PolygonValidiumEtrog is PolygonRollupBaseEtrog, IPolygonValidium {
if (!isSequenceWithDataAvailabilityAllowed) {
revert SequenceWithDataAvailabilityNotAllowed();
}
super.sequenceBatches(batches, l1InfoTreeLeafCount, maxSequenceTimestamp, expectedFinalAccInputHash, l2Coinbase);
super.sequenceBatches(
batches,
l1InfoTreeLeafCount,
maxSequenceTimestamp,
expectedFinalAccInputHash,
l2Coinbase
);
}

//////////////////
Expand All @@ -250,7 +282,9 @@ contract PolygonValidiumEtrog is PolygonRollupBaseEtrog, IPolygonValidium {
* @notice Allow the admin to set a new data availability protocol
* @param newDataAvailabilityProtocol Address of the new data availability protocol
*/
function setDataAvailabilityProtocol(IDataAvailabilityProtocol newDataAvailabilityProtocol) external onlyAdmin {
function setDataAvailabilityProtocol(
IDataAvailabilityProtocol newDataAvailabilityProtocol
) external onlyAdmin {
dataAvailabilityProtocol = newDataAvailabilityProtocol;

emit SetDataAvailabilityProtocol(address(newDataAvailabilityProtocol));
Expand All @@ -260,8 +294,13 @@ contract PolygonValidiumEtrog is PolygonRollupBaseEtrog, IPolygonValidium {
* @notice Allow the admin to switch the sequence with data availability
* @param newIsSequenceWithDataAvailabilityAllowed Boolean to switch
*/
function switchSequenceWithDataAvailability(bool newIsSequenceWithDataAvailabilityAllowed) external onlyAdmin {
if (newIsSequenceWithDataAvailabilityAllowed == isSequenceWithDataAvailabilityAllowed) {
function switchSequenceWithDataAvailability(
bool newIsSequenceWithDataAvailabilityAllowed
) external onlyAdmin {
if (
newIsSequenceWithDataAvailabilityAllowed ==
isSequenceWithDataAvailabilityAllowed
) {
revert SwitchToSameValue();
}
isSequenceWithDataAvailabilityAllowed = newIsSequenceWithDataAvailabilityAllowed;
Expand Down
9 changes: 8 additions & 1 deletion contracts/consensus/zkEVM/PolygonZkEVMEtrog.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@ contract PolygonZkEVMEtrog is PolygonRollupBaseEtrog {
IERC20Upgradeable _pol,
IPolygonZkEVMBridgeV2 _bridgeAddress,
PolygonRollupManager _rollupManager
) PolygonRollupBaseEtrog(_globalExitRootManager, _pol, _bridgeAddress, _rollupManager) {}
)
PolygonRollupBaseEtrog(
_globalExitRootManager,
_pol,
_bridgeAddress,
_rollupManager
)
{}
}
Loading

0 comments on commit 8faa01c

Please sign in to comment.