Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 30 additions & 77 deletions contracts/AgglayerManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import "./lib/PolygonTransparentProxy.sol";
import "./lib/PolygonAccessControlUpgradeable.sol";
import "./lib/LegacyZKEVMStateVariables.sol";
import "./lib/PolygonConstantsBase.sol";
import "./interfaces/IPolygonPessimisticConsensus.sol";
import "./interfaces/ISP1Verifier.sol";
import "./interfaces/IAgglayerManager.sol";
import "./interfaces/IAggchainBase.sol";
Expand Down Expand Up @@ -528,10 +527,7 @@ contract AgglayerManager is

uint32 rollupTypeID = ++rollupTypeCount;

if (rollupVerifierType == VerifierType.Pessimistic) {
// No genesis on pessimistic rollups
if (genesis != bytes32(0)) revert InvalidRollupType();
} else if (rollupVerifierType == VerifierType.ALGateway) {
Comment on lines -531 to -534
Copy link
Collaborator

@invocamanman invocamanman Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after those lines fix comment:
// unreachable code since solidity enforces the enum input rollupVerifierType to be one of the enum values

if (rollupVerifierType == VerifierType.ALGateway) {
// Those params should be zero for ALGateway rollup types
if (
verifier != address(0) ||
Expand Down Expand Up @@ -778,14 +774,7 @@ contract AgglayerManager is
rollup.rollupVerifierType = rollupVerifierType;

// Check verifier type
if (rollupVerifierType == VerifierType.Pessimistic) {
rollup.programVKey = programVKey;
rollup.lastPessimisticRoot = initPessimisticRoot;
rollup.lastLocalExitRoot = initRoot;
if (verifier.code.length == 0) {
revert InvalidVerifierAddress();
}
} else if (rollupVerifierType == VerifierType.ALGateway) {
Comment on lines -781 to -788
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the condition if (rollupVerifierType == VerifierType.Pessimistic) {
should revert with a custom error.
Now we can create a "weird" state transition rollup

if (rollupVerifierType == VerifierType.ALGateway) {
if (
verifier != address(0) ||
forkID != 0 ||
Expand Down Expand Up @@ -990,11 +979,11 @@ contract AgglayerManager is
revert AllSequencedMustBeVerified();
}

// NewRollupType must be pessimistic or ALGateway
// NewRollupType must be ALGateway
require(
rollupTypeMap[newRollupTypeID].rollupVerifierType !=
VerifierType.StateTransition,
NewRollupTypeMustBePessimisticOrALGateway()
rollupTypeMap[newRollupTypeID].rollupVerifierType ==
VerifierType.ALGateway,
InvalidRollupType()
);

// Add rollupID to migration mapping
Expand Down Expand Up @@ -1312,14 +1301,6 @@ contract AgglayerManager is
revert StateTransitionChainsNotAllowed();
}

// Not aggchainData for VerifierType.Pessimistic
if (
rollup.rollupVerifierType == VerifierType.Pessimistic &&
aggchainData.length != 0
) {
revert AggchainDataMustBeZeroForPessimisticVerifierType();
}

// Check l1InfoTreeLeafCount has a valid l1InfoTreeRoot
bytes32 l1InfoRoot = globalExitRootManager.l1InfoRootMap(
l1InfoTreeLeafCount
Expand Down Expand Up @@ -1361,23 +1342,14 @@ contract AgglayerManager is
aggchainData
);

if (rollup.rollupVerifierType == VerifierType.ALGateway) {
// Verify proof. The pessimistic proof selector is attached at the first 4 bytes of the proof
// proof[0:4]: 4 bytes selector pp
// proof[4:8]: 4 bytes selector SP1 verifier
// proof[8:]: proof
aggLayerGateway.verifyPessimisticProof(
inputPessimisticBytes,
proof
);
} else {
// Verify proof
ISP1Verifier(rollup.verifier).verifyProof(
rollup.programVKey,
inputPessimisticBytes,
proof
);
}
// Verify proof. The pessimistic proof selector is attached at the first 4 bytes of the proof
// proof[0:4]: 4 bytes selector pp
// proof[4:8]: 4 bytes selector SP1 verifier
// proof[8:]: proof
aggLayerGateway.verifyPessimisticProof(
inputPessimisticBytes,
proof
);

// Update aggregation parameters
lastAggregationTimestamp = uint64(block.timestamp);
Expand Down Expand Up @@ -1413,13 +1385,11 @@ contract AgglayerManager is
msg.sender
);

if (rollup.rollupVerifierType == VerifierType.ALGateway) {
// Allow chains to manage customData
// Callback to the rollup address
IAggchainBase(rollup.rollupContract).onVerifyPessimistic(
aggchainData
);
}
// Allow chains to manage customData
// Callback to the rollup address
IAggchainBase(rollup.rollupContract).onVerifyPessimistic(
aggchainData
);
}

////////////////////////
Expand Down Expand Up @@ -1660,35 +1630,18 @@ contract AgglayerManager is
bytes32 newPessimisticRoot,
bytes calldata aggchainData
) internal view returns (bytes memory inputPessimisticBytes) {
// Different consensusHash and encoding if the rollup is ALGateway or pessimistic
if (rollup.rollupVerifierType == VerifierType.ALGateway) {
bytes32 aggchainHash = IAggchainBase(rollup.rollupContract)
.getAggchainHash(aggchainData);
bytes32 aggchainHash = IAggchainBase(rollup.rollupContract)
.getAggchainHash(aggchainData);

inputPessimisticBytes = abi.encodePacked(
rollup.lastLocalExitRoot,
rollup.lastPessimisticRoot,
l1InfoTreeRoot,
rollupID,
aggchainHash,
newLocalExitRoot,
newPessimisticRoot
);
} else {
bytes32 consensusHash = IPolygonPessimisticConsensus(
address(rollup.rollupContract)
).getConsensusHash();

inputPessimisticBytes = abi.encodePacked(
rollup.lastLocalExitRoot,
rollup.lastPessimisticRoot,
l1InfoTreeRoot,
rollupID,
consensusHash,
newLocalExitRoot,
newPessimisticRoot
);
}
inputPessimisticBytes = abi.encodePacked(
rollup.lastLocalExitRoot,
rollup.lastPessimisticRoot,
l1InfoTreeRoot,
rollupID,
aggchainHash,
newLocalExitRoot,
newPessimisticRoot
);
}

/**
Expand Down
11 changes: 1 addition & 10 deletions contracts/interfaces/IAgglayerManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,6 @@ interface IAgglayerManager {
*/
error StateTransitionChainsNotAllowed();

/**
* @dev Custom chain data must be zero for pessimistic verifier type
*/
error AggchainDataMustBeZeroForPessimisticVerifierType();

/**
* @dev Invalid Pessimistic proof
*/
Expand Down Expand Up @@ -339,18 +334,14 @@ interface IAgglayerManager {
*/
error InvalidVerifierAddress();

/**
* @dev Thrown when trying to migrate a rollup to a non pessimistic rollup type with `initMigration` function.
*/
error NewRollupTypeMustBePessimisticOrALGateway();

/**
* @dev Thrown when trying to finish a migration of a rollup to a pessimistic rollup type with `verifyPessimisticTrustedAggregator` function and the proposed new local exit root does not match the expected new local exit root
*/
error InvalidNewLocalExitRoot();

enum VerifierType {
StateTransition,
// Deprecated: Pessimistic rollup type is deprecated. Now new rollups can be created with such types nor migrated to/from it.
Pessimistic,
ALGateway
}
Expand Down
Loading
Loading