Skip to content

Commit

Permalink
Merge pull request #266 from 0xPolygonHermez/feature/fix-tests
Browse files Browse the repository at this point in the history
Feature/fix tests
  • Loading branch information
invocamanman committed Jun 19, 2024
2 parents ac968ab + 5184e5b commit 027f5fd
Show file tree
Hide file tree
Showing 13 changed files with 3,571 additions and 1,532 deletions.
44 changes: 28 additions & 16 deletions contracts/v2/PolygonRollupManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ contract PolygonRollupManager is
*/
event RollbackBatches(
uint32 indexed rollupID,
uint64 indexed batchToRollback,
uint64 indexed targetBatch,
bytes32 accInputHashToRollback
);

Expand Down Expand Up @@ -637,7 +637,7 @@ contract PolygonRollupManager is
rollupAddressToID[address(rollupContract)]
];

// If rollupID does not exist (rollupID = 0), will revert afterwards
// Check all sequenced batches are verified
if (rollup.lastBatchSequenced != rollup.lastVerifiedBatch) {
revert AllSequencedMustBeVerified();
}
Expand Down Expand Up @@ -732,11 +732,11 @@ contract PolygonRollupManager is
/**
* @notice Rollback batches of the target rollup
* @param rollupContract Rollup consensus proxy address
* @param batchToRollback Batch to rollback
* @param targetBatch Batch to rollback up to but not including this batch
*/
function rollbackBatches(
IPolygonRollupBase rollupContract,
uint64 batchToRollback
uint64 targetBatch
) external {
// Check msg.sender has _UPDATE_ROLLUP_ROLE rol or is the admin of the network
if (
Expand All @@ -758,23 +758,23 @@ contract PolygonRollupManager is

// Batch to rollback should be already sequenced
if (
batchToRollback >= lastBatchSequenced ||
batchToRollback < rollup.lastVerifiedBatch
targetBatch >= lastBatchSequenced ||
targetBatch < rollup.lastVerifiedBatch
) {
revert RollbackBatchIsNotValid();
}

uint64 currentBatch = lastBatchSequenced;

// delete sequence batches structs until the batchToRollback
while (currentBatch != batchToRollback) {
// delete sequence batches structs until the targetBatch
while (currentBatch != targetBatch) {
// Load previous end of sequence batch
uint64 previousBatch = rollup
.sequencedBatches[currentBatch]
.previousLastBatchSequenced;

// Batch to rollback must be end of a sequence
if (previousBatch < batchToRollback) {
if (previousBatch < targetBatch) {
revert RollbackBatchIsNotEndOfSequence();
}

Expand All @@ -786,21 +786,33 @@ contract PolygonRollupManager is
}

// Update last batch sequenced on rollup data
rollup.lastBatchSequenced = batchToRollback;
rollup.lastBatchSequenced = targetBatch;

// Update totalSequencedBatches
totalSequencedBatches -= lastBatchSequenced - batchToRollback;
totalSequencedBatches -= lastBatchSequenced - targetBatch;

// Callback the consensus contract
// Check pending state
if (rollup.lastPendingState > 0) {
// update total verified batches
uint64 currentLastVerifiedBatch = _getLastVerifiedBatch(rollup);
totalVerifiedBatches -=
currentLastVerifiedBatch -
rollup.lastVerifiedBatch;

rollup.lastPendingState = 0;
rollup.lastPendingStateConsolidated = 0;
}

// Clean pending state if any
rollupContract.rollbackBatches(
batchToRollback,
rollup.sequencedBatches[batchToRollback].accInputHash
targetBatch,
rollup.sequencedBatches[targetBatch].accInputHash
);

emit RollbackBatches(
rollupID,
batchToRollback,
rollup.sequencedBatches[batchToRollback].accInputHash
targetBatch,
rollup.sequencedBatches[targetBatch].accInputHash
);
}

Expand Down
3 changes: 1 addition & 2 deletions contracts/v2/interfaces/IPolygonRollupBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ interface IPolygonRollupBase {
function admin() external returns (address);

function rollbackBatches(
uint64 batchToRollback,
uint64 targetBatch,
bytes32 accInputHashToRollback
) external;

}
8 changes: 4 additions & 4 deletions contracts/v2/lib/PolygonRollupBaseEtrog.sol
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ abstract contract PolygonRollupBaseEtrog is
* @dev Emitted when a aggregator verifies batches
*/
event RollbackBatches(
uint64 indexed batchToRollback,
uint64 indexed targetBatch,
bytes32 accInputHashToRollback
);

Expand Down Expand Up @@ -583,17 +583,17 @@ abstract contract PolygonRollupBaseEtrog is

/**
* @notice Callback on rollback batches, can only be called by the rollup manager
* @param batchToRollback Batch to rollback
* @param targetBatch Batch to rollback up to but not including this batch
* @param accInputHashToRollback Acc input hash to rollback
*/
function rollbackBatches(
uint64 batchToRollback,
uint64 targetBatch,
bytes32 accInputHashToRollback
) public virtual override onlyRollupManager {
// Rollback the accumulated input hash
lastAccInputHash = accInputHashToRollback;

emit RollbackBatches(batchToRollback, accInputHashToRollback);
emit RollbackBatches(targetBatch, accInputHashToRollback);
}

////////////////////////////
Expand Down
22 changes: 22 additions & 0 deletions contracts/v2/previousVersions/IPolygonRollupBasePrevious.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: AGPL-3.0

pragma solidity ^0.8.20;

interface IPolygonRollupBasePrevious {
function initialize(
address _admin,
address sequencer,
uint32 networkID,
address gasTokenAddress,
string memory sequencerURL,
string memory _networkName
) external;

function onVerifyBatches(
uint64 lastVerifiedBatch,
bytes32 newStateRoot,
address aggregator
) external;

function admin() external returns (address);
}
Loading

0 comments on commit 027f5fd

Please sign in to comment.