Skip to content

Commit 7448d95

Browse files
committed
update comments
comment comment better error comment
1 parent 4528794 commit 7448d95

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

src/protocol/CheckpointTracker.sol

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ import {IPublicationFeed} from "./IPublicationFeed.sol";
77
import {IVerifier} from "./IVerifier.sol";
88

99
contract CheckpointTracker is ICheckpointTracker {
10-
/// @notice The publication id of the current proven checkpoint representing the latest verified state of the rollup
11-
/// @dev A checkpoint commitment is any value (typically a state root) that uniquely identifies
12-
/// the state of the rollup at a specific point in time
10+
/// @dev The publication id of the current proven checkpoint representing
11+
/// the latest verified state of the rollup
1312
uint256 private _provenPublicationId;
1413

1514
IPublicationFeed public immutable publicationFeed;
1615
IVerifier public immutable verifier;
1716
ICommitmentStore public immutable commitmentStore;
18-
address public proverManager;
17+
address public immutable proverManager;
1918

2019
/// @param _genesis the checkpoint commitment describing the initial state of the rollup
2120
/// @param _publicationFeed the input data source that updates the state of this rollup
@@ -73,11 +72,16 @@ contract CheckpointTracker is ICheckpointTracker {
7372
_updateCheckpoint(end.publicationId, end.commitment);
7473
}
7574

75+
/// @inheritdoc ICheckpointTracker
7676
function getProvenCheckpoint() public view returns (Checkpoint memory provenCheckpoint) {
7777
provenCheckpoint.publicationId = _provenPublicationId;
7878
provenCheckpoint.commitment = commitmentStore.commitmentAt(address(this), provenCheckpoint.publicationId);
7979
}
8080

81+
/// @dev Updates the proven checkpoint to a new publication ID and commitment
82+
/// @dev Stores the commitment in the commitment store and emits an event
83+
/// @param publicationId The ID of the publication to set as the latest proven checkpoint
84+
/// @param commitment The checkpoint commitment representing the state at the given publication ID
8185
function _updateCheckpoint(uint256 publicationId, bytes32 commitment) internal {
8286
_provenPublicationId = publicationId;
8387
commitmentStore.storeCommitment(publicationId, commitment);

src/protocol/ICommitmentStore.sol

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ interface ICommitmentStore {
1515
/// @dev A new `commitment` has been stored by `source` at a specified `height`.
1616
event CommitmentStored(address indexed source, uint256 indexed height, bytes32 commitment);
1717

18-
/// @dev Returns the commitment at the given `height`.
18+
/// @notice Returns the commitment at the given `height`.
19+
/// @dev If the commitment does not exist at the given `height`, it returns zero.
1920
/// @param source The source address for the saved commitment
2021
/// @param height The height of the commitment
2122
function commitmentAt(address source, uint256 height) external view returns (bytes32 commitment);
2223

23-
/// @dev Stores a commitment.
24+
/// @notice Stores a commitment attributed to `msg.sender`
2425
/// @param height The height of the commitment
2526
/// @param commitment The commitment to store
2627
function storeCommitment(uint256 height, bytes32 commitment) external;

src/protocol/ISignalService.sol

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ interface ISignalService {
2828
/// @dev We require the commitment to contain a state root (with an embedded storage root)
2929
error StorageRootCommitmentNotSupported();
3030

31+
/// @dev If the commitment returns 0 we assume it does not exist
32+
error CommitmentNotFound();
33+
3134
/// @notice Stores a signal and returns its storage location.
3235
/// @param value Data to be stored (signalled)
3336
function sendSignal(bytes32 value) external returns (bytes32 slot);
@@ -44,8 +47,9 @@ interface ISignalService {
4447
/// sent by `sender` on the source chain, which state is represented by `commitmentPublisher` at `height`.
4548
/// @dev Signals are not deleted when verified, and can be
4649
/// verified multiple times by calling this function
47-
/// @param height This refers to the block number / commitmentId where the trusted root is mapped to
48-
/// @param commitmentPublisher The address that published the commitment containing the signal.
50+
/// @param height A reference value indicating which trusted root to use for verification
51+
/// see ICommitmentStore for more information
52+
/// @param commitmentPublisher The address that published the commitment
4953
/// @param sender The address that originally sent the signal on the source chain
5054
/// @param value The signal value to verify
5155
/// @param proof The encoded value of the SignalProof struct

src/protocol/SignalService.sol

+19-9
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ import {ETHBridge} from "./ETHBridge.sol";
88
import {ICommitmentStore} from "./ICommitmentStore.sol";
99
import {ISignalService} from "./ISignalService.sol";
1010

11-
/// @dev SignalService combines secure cross-chain messaging with native token bridging.
11+
/// @dev SignalService is used for secure cross-chain messaging
1212
///
13-
/// This contract allows sending arbitrary data as signals via `sendSignal`, verifying signals from other chains using
14-
/// `verifySignal`, and bridging native ETH with built-in signal generation and verification. It integrates:
15-
/// - `CommitmentStore` to access state roots,
16-
/// - `LibSignal` for signal hashing, storage, and verification logic.
13+
/// This contract allows sending arbitrary data as signals via `sendSignal` and verifying signals from other chains
14+
/// using`verifySignal`
15+
/// It integrates:
16+
/// - `CommitmentStore` to access state roots,
17+
/// - `LibSignal` for signal hashing, storage, and verification logic.
1718
///
18-
/// Signals stored cannot be deleted and can be verified multiple times.
19+
/// Signals stored cannot be deleted
20+
/// WARN: this contract does not provide replay protection(signals can be verified multiple times).
1921
contract SignalService is ISignalService, CommitmentStore {
2022
using LibSignal for bytes32;
2123

@@ -58,12 +60,20 @@ contract SignalService is ISignalService, CommitmentStore {
5860
// For now it could be the block hash or other hashed value
5961
// further work is needed to ensure we get the 'state root' of the chain
6062
bytes32 root = commitmentAt(commitmentPublisher, height);
63+
64+
// A 0 root would probably fail further down the line but its better to explicitly check
65+
require(root != 0, CommitmentNotFound());
66+
6167
SignalProof memory signalProof = abi.decode(proof, (SignalProof));
6268
bytes[] memory accountProof = signalProof.accountProof;
6369
bytes[] memory storageProof = signalProof.storageProof;
64-
// if there is no account proof, verify signal will treat root as a storage root
65-
// for now, we only support full state roots
70+
71+
// We only support state roots for verification
72+
// this is to avoid state roots being used as storage roots (for safety)
6673
require(accountProof.length != 0, StorageRootCommitmentNotSupported());
67-
value.verifySignal(namespace, sender, root, accountProof, storageProof);
74+
75+
value.verifySignal(sender, root, accountProof, storageProof);
76+
77+
emit SignalVerified(sender, value);
6878
}
6979
}

0 commit comments

Comments
 (0)