From 64ac981c8a3d8be5e69fded8dc7da19d13fa4b31 Mon Sep 17 00:00:00 2001 From: lolchocotaco <2431304+lolchocotaco@users.noreply.github.com> Date: Thu, 25 Jan 2024 10:46:35 -0800 Subject: [PATCH 1/4] feat: adding feature flag --- contracts/CDKValidium.sol | 52 ++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/contracts/CDKValidium.sol b/contracts/CDKValidium.sol index 8af82fd77..cfb15c362 100644 --- a/contracts/CDKValidium.sol +++ b/contracts/CDKValidium.sol @@ -246,6 +246,9 @@ contract CDKValidium is // Indicates if forced batches are disallowed bool public isForcedBatchDisallowed; + // Indicates if the MATIC transfer is disabled on sequencing/verifying (default: false) + bool public isMaticTransferDisabled; + /** * @dev Emitted when the trusted sequencer sends a new batch of transactions */ @@ -594,8 +597,6 @@ contract CDKValidium is revert ForceBatchesOverflow(); } - uint256 nonForcedBatchesSequenced = batchesNum - - (currentLastForceBatchSequenced - initLastForceBatchSequenced); // Update sequencedBatches mapping sequencedBatches[currentBatchSequenced] = SequencedBatchData({ @@ -611,12 +612,18 @@ contract CDKValidium is if (currentLastForceBatchSequenced != initLastForceBatchSequenced) lastForceBatchSequenced = currentLastForceBatchSequenced; + if (!isMaticTransferDisabled) { + + uint256 nonForcedBatchesSequenced = batchesNum - + (currentLastForceBatchSequenced - initLastForceBatchSequenced); + + matic.safeTransferFrom( + msg.sender, + address(this), + batchFee * nonForcedBatchesSequenced + ); + } // Pay collateral for every non-forced batch submitted - matic.safeTransferFrom( - msg.sender, - address(this), - batchFee * nonForcedBatchesSequenced - ); // Consolidate pending state if possible _tryConsolidatePendingState(); @@ -822,11 +829,13 @@ contract CDKValidium is } // Get MATIC reward - matic.safeTransfer( - msg.sender, - calculateRewardPerBatch() * - (finalNewBatch - currentLastVerifiedBatch) - ); + if (!isMaticTransferDisabled) { + matic.safeTransfer( + msg.sender, + calculateRewardPerBatch() * + (finalNewBatch - currentLastVerifiedBatch) + ); + } } /** @@ -1022,18 +1031,21 @@ contract CDKValidium is bytes calldata transactions, uint256 maticAmount ) public isForceBatchAllowed ifNotEmergencyState { - // Calculate matic collateral - uint256 maticFee = getForcedBatchFee(); - - if (maticFee > maticAmount) { - revert NotEnoughMaticAmount(); - } if (transactions.length > _MAX_FORCE_BATCH_BYTE_LENGTH) { revert TransactionsLengthAboveMax(); } - matic.safeTransferFrom(msg.sender, address(this), maticFee); + if (!isMaticTransferDisabled) { + // Calculate matic collateral + uint256 maticFee = getForcedBatchFee(); + + if (maticFee > maticAmount) { + revert NotEnoughMaticAmount(); + } + + matic.safeTransferFrom(msg.sender, address(this), maticFee); + } // Get globalExitRoot global exit root bytes32 lastGlobalExitRoot = globalExitRootManager @@ -1666,7 +1678,7 @@ contract CDKValidium is abi.encodePacked( msg.sender, oldStateRoot, - oldAccInputHash, + oldAccInputHash, initNumBatch, chainID, forkID, From c60201a42fde485db3f0198e80b5b2574d6c733a Mon Sep 17 00:00:00 2001 From: lolchocotaco <2431304+lolchocotaco@users.noreply.github.com> Date: Thu, 25 Jan 2024 10:57:44 -0800 Subject: [PATCH 2/4] feat: adding admin toggles, rename to feeTransfer --- contracts/CDKValidium.sol | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/contracts/CDKValidium.sol b/contracts/CDKValidium.sol index cfb15c362..e4079d851 100644 --- a/contracts/CDKValidium.sol +++ b/contracts/CDKValidium.sol @@ -247,7 +247,7 @@ contract CDKValidium is bool public isForcedBatchDisallowed; // Indicates if the MATIC transfer is disabled on sequencing/verifying (default: false) - bool public isMaticTransferDisabled; + bool public isFeeTransferDisabled; /** * @dev Emitted when the trusted sequencer sends a new batch of transactions @@ -341,6 +341,11 @@ contract CDKValidium is */ event ActivateForceBatches(); + /** + * @dev Emitted when admin updates state of matic transfers + */ + event SetMaticTransferDisabled(bool isFeeTransferDisabled); + /** * @dev Emitted when the admin starts the two-step transfer role setting a new pending admin */ @@ -612,7 +617,7 @@ contract CDKValidium is if (currentLastForceBatchSequenced != initLastForceBatchSequenced) lastForceBatchSequenced = currentLastForceBatchSequenced; - if (!isMaticTransferDisabled) { + if (!isFeeTransferDisabled) { uint256 nonForcedBatchesSequenced = batchesNum - (currentLastForceBatchSequenced - initLastForceBatchSequenced); @@ -829,7 +834,7 @@ contract CDKValidium is } // Get MATIC reward - if (!isMaticTransferDisabled) { + if (!isFeeTransferDisabled) { matic.safeTransfer( msg.sender, calculateRewardPerBatch() * @@ -1036,7 +1041,7 @@ contract CDKValidium is revert TransactionsLengthAboveMax(); } - if (!isMaticTransferDisabled) { + if (!isFeeTransferDisabled) { // Calculate matic collateral uint256 maticFee = getForcedBatchFee(); @@ -1201,7 +1206,7 @@ contract CDKValidium is emit SetTrustedSequencerURL(newTrustedSequencerURL); } - + /** * @notice Allow the admin to set a new trusted aggregator address * @param newTrustedAggregator Address of the new trusted aggregator @@ -1323,6 +1328,27 @@ contract CDKValidium is emit ActivateForceBatches(); } + + /** + * @notice Allow the admin to disable matic fee transfers for sequence and verify batches + */ + function disableBatchFee() external onlyAdmin { + isFeeTransferDisabled = true; + + emit SetMaticTransferDisabled(true); + } + + + /** + * @notice Allow the admin to enable matic fee transfers for sequence and verify batches + */ + function enableBatchFee() external onlyAdmin { + isFeeTransferDisabled = true; + + emit SetMaticTransferDisabled(true); + } + + /** * @notice Starts the admin role transfer * This is a two step process, the pending admin must accepted to finalize the process From 09d310c23c7562d93bc37420cfb819f6e6c63e9a Mon Sep 17 00:00:00 2001 From: lolchocotaco <2431304+lolchocotaco@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:01:34 -0800 Subject: [PATCH 3/4] chore: rename event var --- contracts/CDKValidium.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/CDKValidium.sol b/contracts/CDKValidium.sol index e4079d851..23135cd5d 100644 --- a/contracts/CDKValidium.sol +++ b/contracts/CDKValidium.sol @@ -344,7 +344,7 @@ contract CDKValidium is /** * @dev Emitted when admin updates state of matic transfers */ - event SetMaticTransferDisabled(bool isFeeTransferDisabled); + event SetMaticTransferDisabled(bool feeTransferDisabled); /** * @dev Emitted when the admin starts the two-step transfer role setting a new pending admin From a3ea8a02cf25875977a9b9d8e0d9ab3cc9280633 Mon Sep 17 00:00:00 2001 From: lolchocotaco <2431304+lolchocotaco@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:02:09 -0800 Subject: [PATCH 4/4] bug: fixing enable --- contracts/CDKValidium.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/CDKValidium.sol b/contracts/CDKValidium.sol index 23135cd5d..2cbf6a5ed 100644 --- a/contracts/CDKValidium.sol +++ b/contracts/CDKValidium.sol @@ -1343,7 +1343,7 @@ contract CDKValidium is * @notice Allow the admin to enable matic fee transfers for sequence and verify batches */ function enableBatchFee() external onlyAdmin { - isFeeTransferDisabled = true; + isFeeTransferDisabled = false; emit SetMaticTransferDisabled(true); }