ToolszkEVMArchitectureHigh levelSmart contractsApi

PolygonRollupManager.sol

## Functions ### ##### Parameters | Name | Type | Description | | :--- | :--- | :------------------------------------------------------------------- | | | contr

Functions

constructor

  function constructor(
    contract IPolygonZkEVMGlobalExitRootV2 _globalExitRootManager,
    contract IERC20Upgradeable _pol,
    contract IPolygonZkEVMBridge _bridgeAddress
  ) public
Parameters
NameTypeDescription
_globalExitRootManagercontract IPolygonZkEVMGlobalExitRootV2Global exit root manager address
_polcontract IERC20UpgradeablePOL token address
_bridgeAddresscontract IPolygonZkEVMBridgeBridge address

initialize

  function initialize(
    address trustedAggregator,
    uint64 _pendingStateTimeout,
    uint64 _trustedAggregatorTimeout,
    address admin,
    address timelock,
    address emergencyCouncil,
    contract PolygonZkEVMExistentEtrog polygonZkEVM,
    contract IVerifierRollup zkEVMVerifier,
    uint64 zkEVMForkID,
    uint64 zkEVMChainID
  ) external
Parameters
NameTypeDescription
trustedAggregatoraddressTrusted aggregator address
_pendingStateTimeoutuint64Pending state timeout
_trustedAggregatorTimeoutuint64Trusted aggregator timeout
adminaddressAdmin of the rollup manager
timelockaddressTimelock address
emergencyCounciladdressEmergency council address
polygonZkEVMcontract PolygonZkEVMExistentEtrogNew deployed Polygon zkEVM which will be initialized wiht previous values
zkEVMVerifiercontract IVerifierRollupVerifier of the new zkEVM deployed
zkEVMForkIDuint64Fork id of the new zkEVM deployed
zkEVMChainIDuint64Chain id of the new zkEVM deployed

addNewRollupType

  function addNewRollupType(
    address consensusImplementation,
    contract IVerifierRollup verifier,
    uint64 forkID,
    uint8 genesis,
    bytes32 description
  ) external
Parameters
NameTypeDescription
consensusImplementationaddressConsensus implementation
verifiercontract IVerifierRollupVerifier address
forkIDuint64ForkID of the verifier
genesisuint8Genesis block of the rollup
descriptionbytes32Description of the rollup type

obsoleteRollupType

  function obsoleteRollupType(
    uint32 rollupTypeID
  ) external
Parameters
NameTypeDescription
rollupTypeIDuint32Rollup type to obsolete

createNewRollup

  function createNewRollup(
    uint32 rollupTypeID,
    uint64 chainID,
    address admin,
    address sequencer,
    address gasTokenAddress,
    string sequencerURL,
    string networkName
  ) external
Parameters
NameTypeDescription
rollupTypeIDuint32Rollup type to deploy
chainIDuint64ChainID of the rollup, must be a new one
adminaddressAdmin of the new created rollup
sequenceraddressSequencer of the new created rollup
gasTokenAddressaddressIndicates the token address that will be used to pay gas fees in the new rollup
Note if a wrapped token of the bridge is used, the original network and address of this wrapped will be used instead
sequencerURLstringSequencer URL of the new created rollup
networkNamestringNetwork name of the new created rollup

addExistingRollup

Add an already deployed rollup.

  function addExistingRollup(
    contract IPolygonRollupBase rollupAddress,
    contract IVerifierRollup verifier,
    uint64 forkID,
    uint64 chainID,
    bytes32 genesis,
    uint8 rollupCompatibilityID
  ) external
  • This rollup does not follow any rollupType.
Parameters
NameTypeDescription
rollupAddresscontract IPolygonRollupBaseRollup address
verifiercontract IVerifierRollupVerifier address, must be added before
forkIDuint64Fork id of the added rollup
chainIDuint64Chain id of the added rollup
genesisbytes32Genesis block for this rollup
rollupCompatibilityIDuint8Compatibility ID for the added rollup

_addExistingRollup

Add an already deployed rollup.

  function _addExistingRollup(
    contract IPolygonRollupBase rollupAddress,
    contract IVerifierRollup verifier,
    uint64 forkID,
    uint64 chainID,
    uint8 rollupCompatibilityID,
    uint64 lastVerifiedBatch
  ) internal returns (struct PolygonRollupManager.RollupData rollup)
  • This rollup does not follow any rollupType.
Parameters
NameTypeDescription
rollupAddresscontract IPolygonRollupBaseRollup address
verifiercontract IVerifierRollupVerifier address, must be added before
forkIDuint64Fork id of the added rollup
chainIDuint64Chain id of the added rollup
rollupCompatibilityIDuint8Compatibility ID for the added rollup
lastVerifiedBatchuint64Last verified batch before adding the rollup

updateRollup

Upgrade an existing rollup.

  function updateRollup(
    contract ITransparentUpgradeableProxy rollupContract,
    uint32 newRollupTypeID,
    bytes upgradeData
  ) external
Parameters
NameTypeDescription
rollupContractcontract ITransparentUpgradeableProxyRollup consensus proxy address
newRollupTypeIDuint32New rolluptypeID to upgrade to
upgradeDatabytesUpgrade data

onSequenceBatches

Sequence batches, callback called by one of the consensus rollups managed by this contract.

  function onSequenceBatches(
    uint64 newSequencedBatches,
    bytes32 newAccInputHash
  ) external returns (uint64)
Parameters
NameTypeDescription
newSequencedBatchesuint64Number of batches sequenced
newAccInputHashbytes32New accumulate input hash

verifyBatches

Allows an aggregator to verify multiple batches.

  function verifyBatches(
    uint32 rollupID,
    uint64 pendingStateNum,
    uint64 initNumBatch,
    uint64 finalNewBatch,
    bytes32 newLocalExitRoot,
    bytes32 newStateRoot,
    address beneficiary,
    bytes32[24] proof
  ) external
Parameters
NameTypeDescription
rollupIDuint32Rollup identifier
pendingStateNumuint64Init pending state, 0 if consolidated state is used
initNumBatchuint64Batch which the aggregator starts the verification
finalNewBatchuint64Last batch aggregator intends to verify
newLocalExitRootbytes32New local exit root once the batch is processed
newStateRootbytes32New State root once the batch is processed
beneficiaryaddressAddress that will receive the verification reward
proofbytes32[24]Fflonk proof

verifyBatchesTrustedAggregator

Allows a trusted aggregator to verify multiple batches.

  function verifyBatchesTrustedAggregator(
    uint32 rollupID,
    uint64 pendingStateNum,
    uint64 initNumBatch,
    uint64 finalNewBatch,
    bytes32 newLocalExitRoot,
    bytes32 newStateRoot,
    address beneficiary,
    bytes32[24] proof
  ) external
Parameters
NameTypeDescription
rollupIDuint32Rollup identifier
pendingStateNumuint64Init pending state, 0 if consolidated state is used
initNumBatchuint64Batch which the aggregator starts the verification
finalNewBatchuint64Last batch aggregator intends to verify
newLocalExitRootbytes32New local exit root once the batch is processed
newStateRootbytes32New State root once the batch is processed
beneficiaryaddressAddress that will receive the verification reward
proofbytes32[24]Fflonk proof

_verifyAndRewardBatches

Verify and reward batches internal function.

  function _verifyAndRewardBatches(
    struct PolygonRollupManager.RollupData rollup,
    uint64 pendingStateNum,
    uint64 initNumBatch,
    uint64 finalNewBatch,
    bytes32 newLocalExitRoot,
    bytes32 newStateRoot,
    address beneficiary,
    bytes32[24] proof
  ) internal
Parameters
NameTypeDescription
rollupstruct PolygonRollupManager.RollupDataRollup Data storage pointer that will be used to the verification
pendingStateNumuint64Init pending state, 0 if consolidated state is used
initNumBatchuint64Batch which the aggregator starts the verification
finalNewBatchuint64Last batch aggregator intends to verify
newLocalExitRootbytes32New local exit root once the batch is processed
newStateRootbytes32New State root once the batch is processed
beneficiaryaddressAddress that will receive the verification reward
proofbytes32[24]Fflonk proof

_tryConsolidatePendingState

Internal function to consolidate the state automatically once sequence or verify batches are called. It tries to consolidate the first and the middle pending state in the queue.

  function _tryConsolidatePendingState(
  ) internal

consolidatePendingState

Consolidates any pending state that has already exceed the pendingStateTimeout. Can be called by the trusted aggregator, which can consolidate any state without the timeout restrictions.

  function consolidatePendingState(
    uint32 rollupID,
    uint64 pendingStateNum
  ) external
Parameters
NameTypeDescription
rollupIDuint32Rollup identifier
pendingStateNumuint64Pending state to consolidate

_consolidatePendingState

Internal function to consolidate any pending state that has already exceed the pendingStateTimeout.

  function _consolidatePendingState(
    struct PolygonRollupManager.RollupData rollup,
    uint64 pendingStateNum
  ) internal
Parameters
NameTypeDescription
rollupstruct PolygonRollupManager.RollupDataRollup data storage pointer
pendingStateNumuint64Pending state to consolidate

overridePendingState

Allows the trusted aggregator to override the pending state if it is possible to prove a different state root given the same batches.

  function overridePendingState(
    uint32 rollupID,
    uint64 initPendingStateNum,
    uint64 finalPendingStateNum,
    uint64 initNumBatch,
    uint64 finalNewBatch,
    bytes32 newLocalExitRoot,
    bytes32 newStateRoot,
    bytes32[24] proof
  ) external
Parameters
NameTypeDescription
rollupIDuint32Rollup identifier
initPendingStateNumuint64Init pending state, 0 if consolidated state is used
finalPendingStateNumuint64Final pending state, that will be used to compare with the newStateRoot
initNumBatchuint64Batch which the aggregator starts the verification
finalNewBatchuint64Last batch aggregator intends to verify
newLocalExitRootbytes32New local exit root once the batch is processed
newStateRootbytes32New State root once the batch is processed
proofbytes32[24]Fflonk proof

proveNonDeterministicPendingState

Activates the emergency state if its possible to prove a different state root given the same batches.

  function proveNonDeterministicPendingState(
    uint32 rollupID,
    uint64 initPendingStateNum,
    uint64 finalPendingStateNum,
    uint64 initNumBatch,
    uint64 finalNewBatch,
    bytes32 newLocalExitRoot,
    bytes32 newStateRoot,
    bytes32[24] proof
  ) external
Parameters
NameTypeDescription
rollupIDuint32Rollup identifier
initPendingStateNumuint64Init pending state, 0 if consolidated state is used
finalPendingStateNumuint64Final pending state, that will be used to compare with the newStateRoot
initNumBatchuint64Batch which the aggregator starts the verification
finalNewBatchuint64Last batch aggregator intends to verify
newLocalExitRootbytes32New local exit root once the batch is processed
newStateRootbytes32New State root once the batch is processed
proofbytes32[24]Fflonk proof

_proveDistinctPendingState

Internal function that proves a different state root given the same batches to verify.

  function _proveDistinctPendingState(
    struct PolygonRollupManager.RollupData rollup,
    uint64 initPendingStateNum,
    uint64 finalPendingStateNum,
    uint64 initNumBatch,
    uint64 finalNewBatch,
    bytes32 newLocalExitRoot,
    bytes32 newStateRoot,
    bytes32[24] proof
  ) internal
Parameters
NameTypeDescription
rollupstruct PolygonRollupManager.RollupDataRollup Data struct that will be checked
initPendingStateNumuint64Init pending state, 0 if consolidated state is used
finalPendingStateNumuint64Final pending state, that will be used to compare with the newStateRoot
initNumBatchuint64Batch which the aggregator starts the verification
finalNewBatchuint64Last batch aggregator intends to verify
newLocalExitRootbytes32New local exit root once the batch is processed
newStateRootbytes32New State root once the batch is processed
proofbytes32[24]Fflonk proof

_updateBatchFee

Function to update the batch fee based on the new verified batches. The batch fee is not updated when the trusted aggregator verifies batches.

  function _updateBatchFee(
    struct PolygonRollupManager.RollupData newLastVerifiedBatch
  ) internal
Parameters
NameTypeDescription
newLastVerifiedBatchstruct PolygonRollupManager.RollupDataNew last verified batch

activateEmergencyState

Function to activate emergency state, which also enables the emergency mode on both PolygonRollupManager and PolygonZkEVMBridge contracts. If not called by the owner, it must not have been aggregated within a _HALT_AGGREGATION_TIMEOUT period and an emergency state should not have happened in the same period.

  function activateEmergencyState(
  ) external

deactivateEmergencyState

Function to deactivate emergency state on both PolygonRollupManager and PolygonZkEVMBridge contracts.

  function deactivateEmergencyState(
  ) external

_activateEmergencyState

Internal function to activate emergency state on both PolygonRollupManager and PolygonZkEVMBridge contracts.

  function _activateEmergencyState(
  ) internal

setTrustedAggregatorTimeout

Set a new pending state timeout. The timeout can only be lowered, except if emergency state is active.

  function setTrustedAggregatorTimeout(
    uint64 newTrustedAggregatorTimeout
  ) external
Parameters
NameTypeDescription
newTrustedAggregatorTimeoutuint64Trusted aggregator timeout

setPendingStateTimeout

Set a new trusted aggregator timeout. The timeout can only be lowered, except if emergency state is active.

  function setPendingStateTimeout(
    uint64 newPendingStateTimeout
  ) external
Parameters
NameTypeDescription
newPendingStateTimeoutuint64Trusted aggregator timeout

setMultiplierBatchFee

Set a new multiplier batch fee.

  function setMultiplierBatchFee(
    uint16 newMultiplierBatchFee
  ) external
Parameters
NameTypeDescription
newMultiplierBatchFeeuint16multiplier batch fee

setVerifyBatchTimeTarget

Set a new verify batch time target. This value will only be relevant once the aggregation is decentralized, so the trustedAggregatorTimeout should be zero or very close to zero.

  function setVerifyBatchTimeTarget(
    uint64 newVerifyBatchTimeTarget
  ) external
Parameters
NameTypeDescription
newVerifyBatchTimeTargetuint64Verify batch time target

setBatchFee

  function setBatchFee(
    uint256 newBatchFee
  ) external
Parameters
NameTypeDescription
newBatchFeeuint256new batch fee

getRollupExitRoot

Get the current rollup exit root: Compute the rollup exit root by using all the local exit roots of all rollups.

  function getRollupExitRoot(
  ) public returns (bytes32)

getLastVerifiedBatch

  function getLastVerifiedBatch(
  ) public returns (uint64)

_getLastVerifiedBatch

  function _getLastVerifiedBatch(
  ) internal returns (uint64)

isPendingStateConsolidable

Returns a boolean that indicates if the pendingStateNum is consolidate-able.

  function isPendingStateConsolidable(
    uint32 rollupID,
    uint64 pendingStateNum
  ) public returns (bool)
Parameters
NameTypeDescription
rollupIDuint32Rollup id
pendingStateNumuint64Pending state number to check
  • This function does not check if the pending state currently exists, or if it's consolidated already.

_isPendingStateConsolidable

Returns a boolean that indicates if the pendingStateNum is consolidate-able.

  function _isPendingStateConsolidable(
    struct PolygonRollupManager.RollupData rollup,
    uint64 pendingStateNum
  ) internal returns (bool)
Parameters
NameTypeDescription
rollupstruct PolygonRollupManager.RollupDataRollup data storage pointer
pendingStateNumuint64Pending state number to check
  • This function does not check if the pending state currently exists, or if it's consolidated already.

calculateRewardPerBatch

Function to calculate the reward to verify a single batch.

  function calculateRewardPerBatch(
  ) public returns (uint256)

getBatchFee

This function is used instead of the automatic public view one.

  function getBatchFee(
  ) public returns (uint256)

getForcedBatchFee

  function getForcedBatchFee(
  ) public returns (uint256)

getInputSnarkBytes

Function to calculate the input snark bytes.

  function getInputSnarkBytes(
    uint32 rollupID,
    uint64 initNumBatch,
    uint64 finalNewBatch,
    bytes32 newLocalExitRoot,
    bytes32 oldStateRoot,
    bytes32 newStateRoot
  ) public returns (bytes)
Parameters
NameTypeDescription
rollupIDuint32Rollup id used to calculate the input snark bytes
initNumBatchuint64Batch which the aggregator starts the verification
finalNewBatchuint64Last batch aggregator intends to verify
newLocalExitRootbytes32New local exit root once the batch is processed
oldStateRootbytes32State root before batch is processed
newStateRootbytes32New State root once the batch is processed

_getInputSnarkBytes

Function to calculate the input snark bytes.

  function _getInputSnarkBytes(
    struct PolygonRollupManager.RollupData rollup,
    uint64 initNumBatch,
    uint64 finalNewBatch,
    bytes32 newLocalExitRoot,
    bytes32 oldStateRoot,
    bytes32 newStateRoot
  ) internal returns (bytes)
Parameters
NameTypeDescription
rollupstruct PolygonRollupManager.RollupDataRollup data storage pointer
initNumBatchuint64Batch which the aggregator starts the verification
finalNewBatchuint64Last batch aggregator intends to verify
newLocalExitRootbytes32New local exit root once the batch is processed
oldStateRootbytes32State root before batch is processed
newStateRootbytes32New State root once the batch is processed

_checkStateRootInsidePrime

Function to check if the state root is inside of the prime field.

  function _checkStateRootInsidePrime(
    uint256 newStateRoot
  ) internal returns (bool)
Parameters
NameTypeDescription
newStateRootuint256New State root once the batch is processed

getRollupBatchNumToStateRoot

Get rollup state root given a batch number.

  function getRollupBatchNumToStateRoot(
    uint32 rollupID,
    uint64 batchNum
  ) public returns (bytes32)
Parameters
NameTypeDescription
rollupIDuint32Rollup identifier
batchNumuint64Batch number

getRollupSequencedBatches

Get rollup sequence batches struct given a batch number.

  function getRollupSequencedBatches(
    uint32 rollupID,
    uint64 batchNum
  ) public returns (struct LegacyZKEVMStateVariables.SequencedBatchData)
Parameters
NameTypeDescription
rollupIDuint32Rollup identifier
batchNumuint64Batch number

getRollupPendingStateTransitions

Get rollup sequence pending state struct given a batch number.

  function getRollupPendingStateTransitions(
    uint32 rollupID,
    uint64 batchNum
  ) public returns (struct LegacyZKEVMStateVariables.PendingState)
Parameters
NameTypeDescription
rollupIDuint32Rollup identifier
batchNumuint64Batch number

Events

AddNewRollupType

Emitted when a new rollup type is added.

  event AddNewRollupType(
  )

ObsoleteRollupType

Emitted when a a rollup type is obsoleted.

  event ObsoleteRollupType(
  )

CreateNewRollup

Emitted when a new rollup is created based on a rollupType.

  event CreateNewRollup(
  )

AddExistingRollup

Emitted when an existing rollup is added.

  event AddExistingRollup(
  )

UpdateRollup

Emitted when a rollup is updated.

  event UpdateRollup(
  )

OnSequenceBatches

Emitted when a new verifier is added.

  event OnSequenceBatches(
  )

VerifyBatches

Emitted when an aggregator verifies batches.

  event VerifyBatches(
  )

VerifyBatchesTrustedAggregator

Emitted when the trusted aggregator verifies batches.

  event VerifyBatchesTrustedAggregator(
  )

ConsolidatePendingState

Emitted when pending state is consolidated.

  event ConsolidatePendingState(
  )

ProveNonDeterministicPendingState

Emitted when is proved a different state given the same batches.

  event ProveNonDeterministicPendingState(
  )

OverridePendingState

Emitted when the trusted aggregator overrides pending state.

  event OverridePendingState(
  )

SetTrustedAggregatorTimeout

Emitted when is updated the trusted aggregator timeout.

  event SetTrustedAggregatorTimeout(
  )

SetPendingStateTimeout

Emitted when is updated the pending state timeout.

  event SetPendingStateTimeout(
  )

SetMultiplierBatchFee

Emitted when is updated the multiplier batch fee.

  event SetMultiplierBatchFee(
  )

SetVerifyBatchTimeTarget

Emitted when is updated the verify batch timeout

  event SetVerifyBatchTimeTarget(
  )

SetTrustedAggregator

Emitted when is updated the trusted aggregator address.

  event SetTrustedAggregator(
  )

SetBatchFee

Emitted when is updated the batch fee.

  event SetBatchFee(
  )
Edit on GitHub

Last updated on

On this page

FunctionsconstructorParametersinitializeParametersaddNewRollupTypeParametersobsoleteRollupTypeParameterscreateNewRollupParametersaddExistingRollupParameters_addExistingRollupParametersupdateRollupParametersonSequenceBatchesParametersverifyBatchesParametersverifyBatchesTrustedAggregatorParameters_verifyAndRewardBatchesParameters_tryConsolidatePendingStateconsolidatePendingStateParameters_consolidatePendingStateParametersoverridePendingStateParametersproveNonDeterministicPendingStateParameters_proveDistinctPendingStateParameters_updateBatchFeeParametersactivateEmergencyStatedeactivateEmergencyState_activateEmergencyStatesetTrustedAggregatorTimeoutParameterssetPendingStateTimeoutParameterssetMultiplierBatchFeeParameterssetVerifyBatchTimeTargetParameterssetBatchFeeParametersgetRollupExitRootgetLastVerifiedBatch_getLastVerifiedBatchisPendingStateConsolidableParameters_isPendingStateConsolidableParameterscalculateRewardPerBatchgetBatchFeegetForcedBatchFeegetInputSnarkBytesParameters_getInputSnarkBytesParameters_checkStateRootInsidePrimeParametersgetRollupBatchNumToStateRootParametersgetRollupSequencedBatchesParametersgetRollupPendingStateTransitionsParametersEventsAddNewRollupTypeObsoleteRollupTypeCreateNewRollupAddExistingRollupUpdateRollupOnSequenceBatchesVerifyBatchesVerifyBatchesTrustedAggregatorConsolidatePendingStateProveNonDeterministicPendingStateOverridePendingStateSetTrustedAggregatorTimeoutSetPendingStateTimeoutSetMultiplierBatchFeeSetVerifyBatchTimeTargetSetTrustedAggregatorSetBatchFee