Skip to content

Commit e016955

Browse files
authored
Minor Cleanup (#151)
1 parent b4ce696 commit e016955

24 files changed

Lines changed: 261 additions & 175 deletions

offchain/sample_deposit_proof.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ pub struct DepositSpecification {
6464

6565
fn deposit_specification() -> Vec<DepositSpecification> {
6666
// This is an address on the destination chain, so it seems natural to use one generated there
67-
// In this case, the CrossChainDepositExists.sol test case defines _randomAddress("recipient");
68-
let recipient = "0x99A270Be1AA5E97633177041859aEEB9a0670fAa";
67+
// In this case, the CrossChainDepositExists.sol test case defines makeAddr("recipient");
68+
let recipient = "0x006217c47ffA5Eb3F3c92247ffFE22AD998242c5";
6969
// Use both zero and non-zero amounts (in this case 4 ether)
7070
let amounts = vec![0_u128, 4000000000000000000_u128];
7171
// Use different calldata to try different functions and inputs

src/libs/LibProvingPeriod.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@ library LibProvingPeriod {
3939
bool pastDeadline;
4040
}
4141

42+
/// @dev Prover Address cannot be zero
43+
error ZeroProverAddress();
44+
4245
/// @dev Initializes the period with the given parameters.
4346
/// @dev The _end_ and _deadline_ default to zero. The _pastDeadline_ flag defaults to false.
4447
/// @dev This can be called multiple times to set the latest bid while the auction is ongoing.
4548
function init(Period storage period, address prover, uint96 fee, uint16 delayedFeePercentage, uint96 stake)
4649
internal
4750
{
48-
require(prover != address(0), "Prover cannot be zero address");
51+
require(prover != address(0), ZeroProverAddress());
4952
period.prover = prover;
5053
period.fee = fee;
5154
period.delayedFeePercentage = delayedFeePercentage;

src/protocol/BaseProverManager.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ abstract contract BaseProverManager is IProposerFees, IProverManager, BalanceAcc
8080
/// @dev Current period is not vacant
8181
error NoProvingVacancy();
8282

83+
/// @dev The provided address is zero
84+
error ZeroAddress();
85+
8386
/// @dev Initializes the contract state and deposits the initial prover's liveness bond.
8487
/// The constructor also calls `_claimProvingVacancy`. Publications will actually start in period 1.
8588
/// @param _inbox The address of the inbox contract
@@ -94,9 +97,9 @@ abstract contract BaseProverManager is IProposerFees, IProverManager, BalanceAcc
9497
uint96 _initialFee,
9598
uint256 _initialDeposit
9699
) {
97-
require(_inbox != address(0), "Inbox address cannot be 0");
98-
require(_checkpointTracker != address(0), "Checkpoint tracker address cannot be 0");
99-
require(_initialProver != address(0), "Initial prover address cannot be 0");
100+
require(_inbox != address(0), ZeroAddress());
101+
require(_checkpointTracker != address(0), ZeroAddress());
102+
require(_initialProver != address(0), ZeroAddress());
100103

101104
inbox = IInbox(_inbox);
102105
checkpointTracker = ICheckpointTracker(_checkpointTracker);

src/protocol/CheckpointTracker.sol

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ contract CheckpointTracker is ICheckpointTracker {
2525
/// @param _commitmentStore contract responsible storing historical commitments
2626
constructor(bytes32 _genesis, address _inbox, address _verifier, address _proverManager, address _commitmentStore) {
2727
// set the genesis checkpoint commitment of the rollup - genesis is trusted to be correct
28-
require(_genesis != 0, "genesis checkpoint commitment cannot be 0");
28+
require(_genesis != 0, ZeroGenesisCommitment());
2929
inbox = IInbox(_inbox);
3030
uint256 latestPublicationId = inbox.getNextPublicationId() - 1;
3131

@@ -44,25 +44,26 @@ contract CheckpointTracker is ICheckpointTracker {
4444
external
4545
returns (uint256 numPublications, uint256 numDelayedPublications)
4646
{
47+
require(proverManager == address(0) || msg.sender == proverManager, OnlyProverManager());
48+
49+
require(start.commitment != 0, ZeroStartCommitment());
50+
require(end.commitment != 0, ZeroEndCommitment());
4751
require(
48-
proverManager == address(0) || msg.sender == proverManager, "Only the prover manager can call this function"
52+
start.publicationId <= provenPublicationId,
53+
InvalidStartPublication(start.publicationId, provenPublicationId)
4954
);
5055

51-
require(start.commitment != 0, "Start checkpoint commitment cannot be 0");
52-
require(end.commitment != 0, "End checkpoint commitment cannot be 0");
53-
require(start.publicationId <= provenPublicationId, "Start publication must precede latest proven checkpoint");
54-
5556
// Only count publications that have not been proven yet
5657
numPublications = end.publicationId - provenPublicationId;
5758
numDelayedPublications = end.totalDelayedPublications - _totalDelayedPublications;
5859
require(
5960
numDelayedPublications <= numPublications,
60-
"Number of delayed publications cannot be greater than the total number of publications"
61+
ExcessiveDelayedPublications(numDelayedPublications, numPublications)
6162
);
6263

6364
bytes32 startPublicationHash = inbox.getPublicationHash(start.publicationId);
6465
bytes32 endPublicationHash = inbox.getPublicationHash(end.publicationId);
65-
require(endPublicationHash != 0, "End publication does not exist");
66+
require(endPublicationHash != 0, EndPublicationNotFound());
6667

6768
verifier.verifyProof(
6869
startPublicationHash,

src/protocol/ERC20ProverManager.sol

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
///SPDX-License-Identifier: MIT
12
pragma solidity ^0.8.28;
23

34
import {BaseProverManager} from "./BaseProverManager.sol";
@@ -15,6 +16,12 @@ contract ERC20ProverManager is BaseProverManager, IERC20Depositor {
1516

1617
IERC20 public immutable token;
1718

19+
/// @param _inbox Address of the inbox contract
20+
/// @param _checkpointTracker Address of the checkpoint tracker contract
21+
/// @param _initialProver Address of the initial prover who will provide the bond
22+
/// @param _initialFee Initial fee amount
23+
/// @param _token Address of the ERC20 token used for bonds and fees
24+
/// @param _initialDeposit Initial deposit amount that must cover the liveness bond
1825
constructor(
1926
address _inbox,
2027
address _checkpointTracker,
@@ -23,13 +30,9 @@ contract ERC20ProverManager is BaseProverManager, IERC20Depositor {
2330
address _token,
2431
uint256 _initialDeposit
2532
) BaseProverManager(_inbox, _checkpointTracker, _initialProver, _initialFee, _initialDeposit) {
26-
require(_token != address(0), "Token address cannot be 0");
27-
require(
28-
_initialDeposit >= _livenessBond(), "Initial deposit must be greater than or equal to the liveness bond"
29-
);
30-
33+
require(_token != address(0), ZeroTokenAddress());
34+
require(_initialDeposit >= _livenessBond(), InsufficientInitialDeposit(_initialDeposit, _livenessBond()));
3135
token = IERC20(_token);
32-
3336
// Deposit the amount of funds needed for the liveness bond from the `_initialProver`
3437
token.safeTransferFrom(_initialProver, address(this), _initialDeposit);
3538
}

src/protocol/ETHBridge.sol

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ contract ETHBridge is IETHBridge, ReentrancyGuardTransient {
2525
/// WARN: This address has no significance (and may be untrustworthy) on this chain.
2626
address public immutable counterpart;
2727

28+
/// @param _signalService Address of the signal service contract
29+
/// @param _trustedCommitmentPublisher Address of the trusted commitment publisher
30+
/// @param _counterpart Address of the counterpart signal contract
2831
constructor(address _signalService, address _trustedCommitmentPublisher, address _counterpart) {
29-
require(_signalService != address(0), "Empty signal service");
30-
require(_trustedCommitmentPublisher != address(0), "Empty trusted publisher");
31-
require(_counterpart != address(0), "Empty counterpart");
32-
32+
require(_signalService != address(0), EmptySignalService());
33+
require(_trustedCommitmentPublisher != address(0), EmptyTrustedPublisher());
34+
require(_counterpart != address(0), EmptyCounterpart());
3335
signalService = ISignalService(_signalService);
3436
trustedCommitmentPublisher = _trustedCommitmentPublisher;
3537
counterpart = _counterpart;

src/protocol/ETHProverManager.sol

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import {IETHDepositor} from "./IProverManager.sol";
88
/// @notice Implementation of the `BaseProverManager` contract that uses ETH for bids, stake and paying for publication
99
/// fees.
1010
contract ETHProverManager is BaseProverManager, IETHDepositor {
11+
/// @param _inbox Address of the inbox contract
12+
/// @param _checkpointTracker Address of the checkpoint tracker contract
13+
/// @param _initialProver Address of the initial prover who will provide the bond
14+
/// @param _initialFee Initial fee amount
1115
constructor(address _inbox, address _checkpointTracker, address _initialProver, uint96 _initialFee)
1216
payable
1317
BaseProverManager(_inbox, _checkpointTracker, _initialProver, _initialFee, msg.value)
1418
{
15-
require(
16-
msg.value >= _livenessBond(),
17-
"The amount of ETH deposited must be greater than or equal to the livenessBond"
18-
);
19+
require(msg.value >= _livenessBond(), InsufficientETHDeposit(msg.value, _livenessBond()));
1920
}
2021

2122
/// @notice Receive ETH transfers and deposit them to the sender's balance
@@ -36,6 +37,6 @@ contract ETHProverManager is BaseProverManager, IETHDepositor {
3637
assembly ("memory-safe") {
3738
ok := call(gas(), to, amount, 0, 0, 0, 0)
3839
}
39-
require(ok, "Withdraw failed");
40+
require(ok, WithdrawFailed());
4041
}
4142
}

src/protocol/ICheckpointTracker.sol

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ interface ICheckpointTracker {
1313
uint256 totalDelayedPublications;
1414
}
1515

16+
/// @dev Genesis checkpoint commitment cannot be zero
17+
error ZeroGenesisCommitment();
18+
19+
/// @dev Only the prover manager can call this function
20+
error OnlyProverManager();
21+
22+
/// @dev Start checkpoint commitment cannot be zero
23+
error ZeroStartCommitment();
24+
25+
/// @dev End checkpoint commitment cannot be zero
26+
error ZeroEndCommitment();
27+
28+
/// @dev Start publication must precede latest proven checkpoint
29+
/// @param startPublicationId The provided start publication ID
30+
/// @param latestProvenId The latest proven publication ID
31+
error InvalidStartPublication(uint256 startPublicationId, uint256 latestProvenId);
32+
33+
/// @dev Number of delayed publications exceeds total publications
34+
/// @param delayedCount The number of delayed publications
35+
/// @param totalCount The total number of publications
36+
error ExcessiveDelayedPublications(uint256 delayedCount, uint256 totalCount);
37+
38+
/// @dev End publication does not exist
39+
error EndPublicationNotFound();
40+
1641
/// @notice Emitted when the latest commitment is saved
1742
/// @param publicationId the publication ID of the latest proven checkpoint
1843
/// @param commitment the commitment of the latest proven checkpoint

src/protocol/IDelayedInclusionStore.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ interface IDelayedInclusionStore {
1010
/// @param inclusionsList list of inclusions
1111
event DelayedInclusionProcessed(Inclusion[] inclusionsList);
1212

13+
/// @dev Blob ref registry address cannot be zero
14+
error ZeroBlobRefRegistry();
15+
1316
/// @notice Register a delayed publication for later inclusion
1417
/// @param blobIndices An array of blob indices to be registered where the delayed publications are included
1518
function publishDelayed(uint256[] memory blobIndices) external;

src/protocol/IETHBridge.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ interface IETHBridge {
4040
/// @param data The calldata sent to the claimee
4141
event DepositCancelled(bytes32 indexed id, address claimee, bytes data);
4242

43+
/// @dev Signal service address cannot be zero
44+
error EmptySignalService();
45+
46+
/// @dev Trusted publisher address cannot be zero
47+
error EmptyTrustedPublisher();
48+
49+
/// @dev Counterpart address cannot be zero
50+
error EmptyCounterpart();
51+
4352
/// @dev Failed to call the receiver with value.
4453
error FailedClaim();
4554

0 commit comments

Comments
 (0)