Skip to content

Commit db2d479

Browse files
authored
Merge pull request #1134 from lidofinance/feat/veb-refactoring
Exit limits utils lib : require -> revert
2 parents d23c10b + 0794a35 commit db2d479

13 files changed

+83
-39
lines changed

contracts/0.8.25/ValidatorExitDelayVerifier.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ contract ValidatorExitDelayVerifier {
361361
ExitRequestData calldata exitRequests
362362
) internal view returns (uint256 deliveryTimestamp) {
363363
bytes32 exitRequestsHash = keccak256(abi.encode(exitRequests.data, exitRequests.dataFormat));
364-
deliveryTimestamp = veb.getDeliveryTime(exitRequestsHash);
364+
deliveryTimestamp = veb.getDeliveryTimestamp(exitRequestsHash);
365365

366366
if (deliveryTimestamp == 0) {
367367
revert EmptyDeliveryHistory();

contracts/0.8.25/interfaces/IValidatorsExitBus.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
pragma solidity 0.8.25;
66

77
interface IValidatorsExitBus {
8-
function getDeliveryTime(bytes32 exitRequestsHash) external view returns (uint256 timestamp);
8+
function getDeliveryTimestamp(bytes32 exitRequestsHash) external view returns (uint256 timestamp);
99

1010
function unpackExitRequest(
1111
bytes calldata exitRequests,

contracts/0.8.9/lib/ExitLimitUtils.sol

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,21 @@ library ExitLimitUtilsStorage {
3131
}
3232

3333
library ExitLimitUtils {
34-
// What should happen with limits if pause is enabled
34+
/// @notice Error when new value for remaining limit exceeds maximum limit.
35+
error LimitExceeded();
36+
37+
/// @notice Error when max exit request limit exceeds uint32 max.
38+
error TooLargeMaxExitRequestsLimit();
39+
40+
/// @notice Error when frame duration exceeds uint32 max.
41+
error TooLargeFrameDuration();
42+
43+
/// @notice Error when exits per frame exceed the maximum exit request limit.
44+
error TooLargeExitsPerFrame();
45+
46+
/// @notice Error when frame duration is zero.
47+
error ZeroFrameDuration();
48+
3549
function calculateCurrentExitLimit(
3650
ExitRequestLimitData memory _data,
3751
uint256 timestamp
@@ -58,7 +72,7 @@ library ExitLimitUtils {
5872
uint256 newExitRequestLimit,
5973
uint256 timestamp
6074
) internal pure returns (ExitRequestLimitData memory) {
61-
require(_data.maxExitRequestsLimit >= newExitRequestLimit, "LIMIT_EXCEEDED");
75+
if (_data.maxExitRequestsLimit < newExitRequestLimit) revert LimitExceeded();
6276

6377
uint256 secondsPassed = timestamp - _data.prevTimestamp;
6478
uint256 framesPassed = secondsPassed / _data.frameDurationInSec;
@@ -77,10 +91,10 @@ library ExitLimitUtils {
7791
uint256 frameDurationInSec,
7892
uint256 timestamp
7993
) internal pure returns (ExitRequestLimitData memory) {
80-
require(maxExitRequestsLimit <= type(uint32).max, "TOO_LARGE_MAX_EXIT_REQUESTS_LIMIT");
81-
require(frameDurationInSec <= type(uint32).max, "TOO_LARGE_FRAME_DURATION");
82-
require(exitsPerFrame <= maxExitRequestsLimit, "TOO_LARGE_EXITS_PER_FRAME");
83-
require(frameDurationInSec != 0, "ZERO_FRAME_DURATION");
94+
if (maxExitRequestsLimit > type(uint32).max) revert TooLargeMaxExitRequestsLimit();
95+
if (frameDurationInSec > type(uint32).max) revert TooLargeFrameDuration();
96+
if (exitsPerFrame > maxExitRequestsLimit) revert TooLargeExitsPerFrame();
97+
if (frameDurationInSec == 0) revert ZeroFrameDuration();
8498

8599
_data.exitsPerFrame = uint32(exitsPerFrame);
86100
_data.frameDurationInSec = uint32(frameDurationInSec);

contracts/0.8.9/oracle/ValidatorsExitBus.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ abstract contract ValidatorsExitBus is AccessControlEnumerable, PausableUntil, V
409409
* - exitRequestsHash was not submited
410410
* - Request was not delivered
411411
*/
412-
function getDeliveryTime(bytes32 exitRequestsHash) external view returns (uint256 deliveryDateTimestamp) {
412+
function getDeliveryTimestamp(bytes32 exitRequestsHash) external view returns (uint256 deliveryDateTimestamp) {
413413
mapping(bytes32 => RequestStatus) storage requestStatusMap = _storageRequestStatus();
414414
RequestStatus storage storedRequest = requestStatusMap[exitRequestsHash];
415415

@@ -513,10 +513,10 @@ abstract contract ValidatorsExitBus is AccessControlEnumerable, PausableUntil, V
513513
return uint32(block.timestamp); // solhint-disable-line not-rely-on-time
514514
}
515515

516-
function _setMaxValidatorsPerReport(uint256 value) internal {
517-
require(value > 0, "ZERO_MAX_VALIDATORS_PER_REPORT");
516+
function _setMaxValidatorsPerReport(uint256 maxValidatorsPerReport) internal {
517+
if (maxValidatorsPerReport == 0) revert ZeroArgument("maxValidatorsPerReport");
518518

519-
MAX_VALIDATORS_PER_REPORT_POSITION.setStorageUint256(value);
519+
MAX_VALIDATORS_PER_REPORT_POSITION.setStorageUint256(maxValidatorsPerReport);
520520
}
521521

522522
function _getMaxValidatorsPerReport() internal view returns (uint256) {

test/0.8.25/contracts/ValidatorsExitBusOracle_Mock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ contract ValidatorsExitBusOracle_Mock is IValidatorsExitBus {
3030
}
3131
}
3232

33-
function getDeliveryTime(bytes32 exitRequestsHash) external view returns (uint256 timestamp) {
33+
function getDeliveryTimestamp(bytes32 exitRequestsHash) external view returns (uint256 timestamp) {
3434
require(exitRequestsHash == _hash, "Mock error, Invalid exitRequestsHash");
3535
return _deliveryTimestamp;
3636
}

test/0.8.25/validatorExitDelayVerifier.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ describe("ValidatorExitDelayVerifier.sol", () => {
518518

519519
// Report not unpacked, deliveryTimestamp == 0
520520
await vebo.setExitRequests(encodedExitRequestsHash, 0, exitRequests);
521-
expect(await vebo.getDeliveryTime(encodedExitRequestsHash)).to.equal(0);
521+
expect(await vebo.getDeliveryTimestamp(encodedExitRequestsHash)).to.equal(0);
522522

523523
await expect(
524524
validatorExitDelayVerifier.verifyValidatorExitDelay(

test/0.8.9/lib/exitLimitUtils.test.ts

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,10 @@ describe("ExitLimitUtils.sol", () => {
249249
prevTimestamp,
250250
);
251251

252-
await expect(exitLimit.updatePrevExitLimit(11, prevTimestamp + 10)).to.be.revertedWith("LIMIT_EXCEEDED");
252+
await expect(exitLimit.updatePrevExitLimit(11, prevTimestamp + 10)).to.be.revertedWithCustomError(
253+
exitLimit,
254+
"LimitExceeded",
255+
);
253256
});
254257

255258
it("should increase prevTimestamp on frame duration if one frame passed", async () => {
@@ -345,7 +348,12 @@ describe("ExitLimitUtils.sol", () => {
345348
const exitsPerFrame = 2;
346349
const frameDurationInSec = 10;
347350

348-
const result = await exitLimit.setExitLimits(maxExitRequestsLimit, exitsPerFrame, frameDurationInSec, timestamp);
351+
const result = await exitLimit.setExitLimits(
352+
maxExitRequestsLimit,
353+
exitsPerFrame,
354+
frameDurationInSec,
355+
timestamp,
356+
);
349357

350358
expect(result.maxExitRequestsLimit).to.equal(maxExitRequestsLimit);
351359
expect(result.exitsPerFrame).to.equal(exitsPerFrame);
@@ -370,7 +378,12 @@ describe("ExitLimitUtils.sol", () => {
370378
);
371379

372380
const newMaxExitRequestsLimit = 50;
373-
const result = await exitLimit.setExitLimits(newMaxExitRequestsLimit, exitsPerFrame, frameDurationInSec, timestamp);
381+
const result = await exitLimit.setExitLimits(
382+
newMaxExitRequestsLimit,
383+
exitsPerFrame,
384+
frameDurationInSec,
385+
timestamp,
386+
);
374387

375388
expect(result.maxExitRequestsLimit).to.equal(newMaxExitRequestsLimit);
376389
expect(result.prevExitRequestsLimit).to.equal(newMaxExitRequestsLimit);
@@ -394,7 +407,12 @@ describe("ExitLimitUtils.sol", () => {
394407

395408
const newMaxExitRequestsLimit = 150;
396409

397-
const result = await exitLimit.setExitLimits(newMaxExitRequestsLimit, exitsPerFrame, frameDurationInSec, timestamp);
410+
const result = await exitLimit.setExitLimits(
411+
newMaxExitRequestsLimit,
412+
exitsPerFrame,
413+
frameDurationInSec,
414+
timestamp,
415+
);
398416

399417
expect(result.maxExitRequestsLimit).to.equal(newMaxExitRequestsLimit);
400418
expect(result.prevExitRequestsLimit).to.equal(prevExitRequestsLimit);
@@ -417,7 +435,12 @@ describe("ExitLimitUtils.sol", () => {
417435
);
418436

419437
const newMaxExitRequestsLimit = 77;
420-
const result = await exitLimit.setExitLimits(newMaxExitRequestsLimit, exitsPerFrame, frameDurationInSec, timestamp);
438+
const result = await exitLimit.setExitLimits(
439+
newMaxExitRequestsLimit,
440+
exitsPerFrame,
441+
frameDurationInSec,
442+
timestamp,
443+
);
421444

422445
expect(result.maxExitRequestsLimit).to.equal(newMaxExitRequestsLimit);
423446
expect(result.prevExitRequestsLimit).to.equal(newMaxExitRequestsLimit);
@@ -426,18 +449,25 @@ describe("ExitLimitUtils.sol", () => {
426449

427450
it("should revert if maxExitRequestsLimit is too large", async () => {
428451
const MAX_UINT32 = 2 ** 32;
429-
await expect(exitLimit.setExitLimits(MAX_UINT32, 1, 10, 1000)).to.be.revertedWith(
430-
"TOO_LARGE_MAX_EXIT_REQUESTS_LIMIT",
452+
await expect(exitLimit.setExitLimits(MAX_UINT32, 1, 10, 1000)).to.be.revertedWithCustomError(
453+
exitLimit,
454+
"TooLargeMaxExitRequestsLimit",
431455
);
432456
});
433457

434458
it("should revert if exitsPerFrame bigger than maxExitRequestsLimit", async () => {
435-
await expect(exitLimit.setExitLimits(100, 101, 10, 1000)).to.be.revertedWith("TOO_LARGE_EXITS_PER_FRAME");
459+
await expect(exitLimit.setExitLimits(100, 101, 10, 1000)).to.be.revertedWithCustomError(
460+
exitLimit,
461+
"TooLargeExitsPerFrame",
462+
);
436463
});
437464

438465
it("should revert if frameDurationInSec is too large", async () => {
439466
const MAX_UINT32 = 2 ** 32;
440-
await expect(exitLimit.setExitLimits(100, 2, MAX_UINT32, 1000)).to.be.revertedWith("TOO_LARGE_FRAME_DURATION");
467+
await expect(exitLimit.setExitLimits(100, 2, MAX_UINT32, 1000)).to.be.revertedWithCustomError(
468+
exitLimit,
469+
"TooLargeFrameDuration",
470+
);
441471
});
442472
});
443473

test/0.8.9/oracle/validator-exit-bus-oracle.submitExitRequestsData.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ describe("ValidatorsExitBusOracle.sol:submitExitRequestsData", () => {
330330
});
331331

332332
it("Should not allow to set exits per frame bigger than max limit", async () => {
333-
await expect(oracle.connect(authorizedEntity).setExitRequestLimit(10, 12, FRAME_DURATION)).to.be.revertedWith(
334-
"TOO_LARGE_EXITS_PER_FRAME",
335-
);
333+
await expect(
334+
oracle.connect(authorizedEntity).setExitRequestLimit(10, 12, FRAME_DURATION),
335+
).to.be.revertedWithCustomError(oracle, "TooLargeExitsPerFrame");
336336
});
337337

338338
it("Should deliver request as it is below limit", async () => {
@@ -432,9 +432,9 @@ describe("ValidatorsExitBusOracle.sol:submitExitRequestsData", () => {
432432
const role = await oracle.EXIT_REQUEST_LIMIT_MANAGER_ROLE();
433433
await oracle.grantRole(role, authorizedEntity);
434434

435-
await expect(oracle.connect(authorizedEntity).setMaxValidatorsPerReport(0)).to.be.revertedWith(
436-
"ZERO_MAX_VALIDATORS_PER_REPORT",
437-
);
435+
await expect(oracle.connect(authorizedEntity).setMaxValidatorsPerReport(0))
436+
.to.be.revertedWithCustomError(oracle, "ZeroArgument")
437+
.withArgs("maxValidatorsPerReport");
438438
});
439439

440440
it("Should not allow to process request larger than MAX_VALIDATORS_PER_REPORT", async () => {

test/0.8.9/oracle/validator-exit-bus.helpers.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe("ValidatorsExitBusOracle.sol:helpers", () => {
128128
});
129129
});
130130

131-
context("getDeliveryTime", () => {
131+
context("getDeliveryTimestamp", () => {
132132
let originalState: string;
133133

134134
before(async () => {
@@ -140,7 +140,7 @@ describe("ValidatorsExitBusOracle.sol:helpers", () => {
140140
it("reverts if exitRequestsHash was never submitted (contractVersion = 0)", async () => {
141141
const fakeHash = keccak256("0x1111");
142142

143-
await expect(oracle.getDeliveryTime(fakeHash)).to.be.revertedWithCustomError(oracle, "ExitHashNotSubmitted");
143+
await expect(oracle.getDeliveryTimestamp(fakeHash)).to.be.revertedWithCustomError(oracle, "ExitHashNotSubmitted");
144144
});
145145

146146
it("reverts if request was not delivered", async () => {
@@ -151,7 +151,7 @@ describe("ValidatorsExitBusOracle.sol:helpers", () => {
151151
// Call the helper to store the hash
152152
await oracle.storeNewHashRequestStatus(exitRequestsHash, contractVersion, timestamp);
153153

154-
await expect(oracle.getDeliveryTime(exitRequestsHash)).to.be.revertedWithCustomError(
154+
await expect(oracle.getDeliveryTimestamp(exitRequestsHash)).to.be.revertedWithCustomError(
155155
oracle,
156156
"RequestsNotDelivered",
157157
);
@@ -165,7 +165,7 @@ describe("ValidatorsExitBusOracle.sol:helpers", () => {
165165
// Call the helper to store the hash
166166
await oracle.storeNewHashRequestStatus(exitRequestsHash, contractVersion, timestamp);
167167

168-
const deliveredExitDataTimestamp = await oracle.getDeliveryTime(exitRequestsHash);
168+
const deliveredExitDataTimestamp = await oracle.getDeliveryTimestamp(exitRequestsHash);
169169

170170
expect(deliveredExitDataTimestamp).to.equal(timestamp);
171171
});

test/0.8.9/triggerableWithdrawalGateway.triggerFullWithdrawals.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ describe("TriggerableWithdrawalsGateway.sol:triggerFullWithdrawals", () => {
354354
it("Should not allow to set exitsPerFrame bigger than maxExitRequestsLimit", async () => {
355355
await expect(
356356
triggerableWithdrawalsGateway.connect(authorizedEntity).setExitRequestLimit(0, 1, 48),
357-
).to.be.revertedWith("TOO_LARGE_EXITS_PER_FRAME");
357+
).to.be.revertedWithCustomError(triggerableWithdrawalsGateway, "TooLargeExitsPerFrame");
358358
});
359359

360360
it("should emit StakingModuleExitNotificationFailed if onValidatorExitTriggered reverts", async () => {

test/integration/report-validator-exit-delay.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe("Report Validator Exit Delay", () => {
8585
await validatorsExitBusOracle.connect(vebReportSubmitter).submitExitRequestsHash(encodedExitRequestsHash);
8686
await validatorsExitBusOracle.submitExitRequestsData(encodedExitRequests);
8787

88-
const deliveryTimestamp = await validatorsExitBusOracle.getDeliveryTime(encodedExitRequestsHash);
88+
const deliveryTimestamp = await validatorsExitBusOracle.getDeliveryTimestamp(encodedExitRequestsHash);
8989
const eligibleToExitInSec = proofSlotTimestamp - deliveryTimestamp;
9090

9191
const blockRootTimestamp = await updateBeaconBlockRoot(ACTIVE_VALIDATOR_PROOF.beaconBlockHeaderRoot);
@@ -152,7 +152,7 @@ describe("Report Validator Exit Delay", () => {
152152
await validatorsExitBusOracle.connect(vebReportSubmitter).submitExitRequestsHash(encodedExitRequestsHash);
153153
await validatorsExitBusOracle.submitExitRequestsData(encodedExitRequests);
154154

155-
const deliveryTimestamp = await validatorsExitBusOracle.getDeliveryTime(encodedExitRequestsHash);
155+
const deliveryTimestamp = await validatorsExitBusOracle.getDeliveryTimestamp(encodedExitRequestsHash);
156156
const eligibleToExitInSec = proofSlotTimestamp - deliveryTimestamp;
157157

158158
const blockRootTimestamp = await updateBeaconBlockRoot(ACTIVE_VALIDATOR_PROOF.futureBeaconBlockHeaderRoot);
@@ -375,7 +375,7 @@ describe("Report Validator Exit Delay", () => {
375375
await validatorsExitBusOracle.connect(vebReportSubmitter).submitExitRequestsHash(encodedExitRequestsHash);
376376
await validatorsExitBusOracle.submitExitRequestsData(encodedExitRequests);
377377

378-
const deliveryTimestamp = await validatorsExitBusOracle.getDeliveryTime(encodedExitRequestsHash);
378+
const deliveryTimestamp = await validatorsExitBusOracle.getDeliveryTimestamp(encodedExitRequestsHash);
379379
const eligibleToExitInSec = proofSlotTimestamp - deliveryTimestamp;
380380

381381
const blockRootTimestamp = await updateBeaconBlockRoot(ACTIVE_VALIDATOR_PROOF.beaconBlockHeaderRoot);

test/integration/validators-exit-bus-single-delivery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe("ValidatorsExitBus integration", () => {
8989
.to.emit(veb, "ValidatorExitRequest")
9090
.withArgs(moduleId, nodeOpId, valIndex, pubkey, blockTimestamp);
9191

92-
const timestamp = await veb.getDeliveryTime(exitRequestsHash);
92+
const timestamp = await veb.getDeliveryTimestamp(exitRequestsHash);
9393
expect(timestamp).to.equal(blockTimestamp);
9494
});
9595
});

test/integration/validators-exit-bus-trigger-exits.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe("ValidatorsExitBus integration", () => {
9393
.to.emit(veb, "ValidatorExitRequest")
9494
.withArgs(moduleId, nodeOpId, valIndex, pubkey, blockTimestamp);
9595

96-
const timestamp = await veb.getDeliveryTime(exitRequestsHash);
96+
const timestamp = await veb.getDeliveryTimestamp(exitRequestsHash);
9797
expect(timestamp).to.equal(blockTimestamp);
9898

9999
const ethBefore = await ethers.provider.getBalance(refundRecipient.getAddress());

0 commit comments

Comments
 (0)