Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Productionize RMN remote contract #1431

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
58d8150
fix pragma to 0.8.24
RyanRHall Sep 6, 2024
4e49933
switch to OwnerIsCreator
RyanRHall Sep 6, 2024
efcca8b
remove XXX comments and test functions
RyanRHall Sep 6, 2024
43de93d
reorder imports
RyanRHall Sep 6, 2024
512c7b1
reorder contract contents
RyanRHall Sep 6, 2024
8779688
create RMNRemote.t.sol and RMNHome.t.sol
RyanRHall Sep 6, 2024
ec2825a
setup RMNHome test
RyanRHall Sep 6, 2024
89cc83a
add RMNRemote constructor test
RyanRHall Sep 6, 2024
1d32ad2
add setConfig success test for RMNRemote
RyanRHall Sep 9, 2024
1773727
write setconfig tests
RyanRHall Sep 9, 2024
2e376cc
add initial verify() tests
RyanRHall Sep 9, 2024
333ec83
move RMNRemoteSetup contract to it's own file; pre-sort signing addre…
RyanRHall Sep 10, 2024
a67a1d9
add out of order / duplicate sig tests
RyanRHall Sep 10, 2024
9d3dfe9
add test_verify_unknownSigner_reverts
RyanRHall Sep 10, 2024
98ec143
write test_verify_insufficientSignatures_reverts
RyanRHall Sep 10, 2024
ba9f69d
refactor verify() tests
RyanRHall Sep 10, 2024
fb783c6
incorporate Kostis's RMNRemote changes
RyanRHall Sep 10, 2024
99aa66b
refactor
RyanRHall Sep 10, 2024
28cf1ef
rename curse functions
RyanRHall Sep 11, 2024
22bbcd0
write tests for cursing / uncursing
RyanRHall Sep 11, 2024
e235c26
add RMNRemote_global_and_legacy_curses
RyanRHall Sep 11, 2024
7448001
update comments
RyanRHall Sep 11, 2024
6b807e8
move natspec from RMNRemote to IRMNV2
RyanRHall Sep 11, 2024
07b840a
add natspec @dev comments to structs
RyanRHall Sep 12, 2024
e793eff
improve natspec
RyanRHall Sep 12, 2024
bcc03c8
ignore RMNHome from coverage checks
RyanRHall Sep 12, 2024
255109d
Update comment
RyanRHall Sep 13, 2024
3c8008d
rename i_chainSelector => i_localChainSelector
RyanRHall Sep 13, 2024
d0da905
remove storage / constructor headers
RyanRHall Sep 13, 2024
325b7a8
add comment
RyanRHall Sep 13, 2024
711a4b4
update comments
RyanRHall Sep 13, 2024
bbf4e56
add new constructor test
RyanRHall Sep 13, 2024
b4cbb9a
improve gas efficiency in verify() function
RyanRHall Sep 13, 2024
75f9ca3
PR suggested feedback
RyanRHall Sep 16, 2024
0644f96
rename destLandUpdates => merkleRoots
RyanRHall Sep 16, 2024
22595ea
rename s_cursedSubjectsSequence to s_cursedSubjects and add comment
RyanRHall Sep 16, 2024
508abaa
var rename
RyanRHall Sep 16, 2024
b80d2f7
Squashed commit of the following:
RyanRHall Sep 16, 2024
413a582
gas golf verify() function
RyanRHall Sep 16, 2024
c51a319
implement EnumerableSetBytes16 for cursedSubjects
RyanRHall Sep 16, 2024
4c44a8b
gas golf verify()
RyanRHall Sep 16, 2024
6552764
array cleanup
RyanRHall Sep 16, 2024
74a2487
test refactor
RyanRHall Sep 16, 2024
e8b345c
wrappers & snapshot
RyanRHall Sep 16, 2024
4277680
fix solhint issues
RyanRHall Sep 16, 2024
57da48d
update natspec
RyanRHall Sep 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions contracts/.solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@
./src/v0.8/vendor
./node_modules/

# Ignore RMN contracts temporarily
./src/v0.8/ccip/rmn
# Ignore RMNHome contract temporarily
./src/v0.8/ccip/rmn/RMNHome.sol

# Ignore tweaked vendored contracts
./src/v0.8/shared/enumerable/EnumerableSetWithBytes16.sol
423 changes: 222 additions & 201 deletions contracts/gas-snapshots/ccip.gas-snapshot

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion contracts/src/v0.8/ccip/interfaces/IRMNV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,29 @@ interface IRMNV2 {
bytes32 s;
}

function verify(Internal.MerkleRoot[] memory merkleRoots, Signature[] memory signatures) external view;
/// @notice Verifies signatures of RMN nodes, on dest lane updates as provided in the CommitReport
/// @param offRampAddress is not inferred by msg.sender, in case the call is made through ARMProxy
makramkd marked this conversation as resolved.
Show resolved Hide resolved
/// @param merkleRoots must be well formed, and is a representation of the CommitReport received from the oracles
/// @param signatures rmnNodes ECDSA sigs, only r & s, must be sorted in ascending order by signer address
/// @param rawVs rmnNodes ECDSA sigs, part v bitmap
/// @dev Will revert if verification fails
function verify(
address offRampAddress,
Internal.MerkleRoot[] memory merkleRoots,
Signature[] memory signatures,
uint256 rawVs
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this is new since last review

RyanRHall marked this conversation as resolved.
Show resolved Hide resolved
) external view;

/// @notice gets the current set of cursed subjects
/// @return subjects the list of cursed subjects
function getCursedSubjects() external view returns (bytes16[] memory subjects);

/// @notice If there is an active global or legacy curse, this function returns true.
/// @return bool true if there is an active global curse
function isCursed() external view returns (bool);

/// @notice If there is an active global curse, or an active curse for `subject`, this function returns true.
/// @param subject To check whether a particular chain is cursed, set to bytes16(uint128(chainSelector)).
/// @return bool true if the provided subject is cured *or* if there is an active global curse
function isCursed(bytes16 subject) external view returns (bool);
}
5 changes: 3 additions & 2 deletions contracts/src/v0.8/ccip/offRamp/OffRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
Internal.PriceUpdates priceUpdates; // Collection of gas and price updates to commit
Internal.MerkleRoot[] merkleRoots; // Collection of merkle roots per source chain to commit
IRMNV2.Signature[] rmnSignatures; // RMN signatures on the merkle roots
uint256 rmnRawVs; // Raw v values of the RMN signatures
}

struct GasLimitOverride {
Expand Down Expand Up @@ -778,13 +779,13 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
bytes calldata report,
bytes32[] calldata rs,
bytes32[] calldata ss,
bytes32 rawVs // signatures
bytes32 rawVs
) external {
CommitReport memory commitReport = abi.decode(report, (CommitReport));

// Verify RMN signatures
if (commitReport.merkleRoots.length > 0) {
i_rmn.verify(commitReport.merkleRoots, commitReport.rmnSignatures);
i_rmn.verify(address(this), commitReport.merkleRoots, commitReport.rmnSignatures, commitReport.rmnRawVs);
}

// Check if the report contains price updates
Expand Down
41 changes: 15 additions & 26 deletions contracts/src/v0.8/ccip/rmn/RMNHome.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.24;

import "@openzeppelin/contracts/access/Ownable2Step.sol";
pragma solidity 0.8.24;

import {ITypeAndVersion} from "../../shared/interfaces/ITypeAndVersion.sol";

import {OwnerIsCreator} from "../../shared/access/OwnerIsCreator.sol";

/// @notice Stores the home configuration for RMN, that is referenced by CCIP oracles, RMN nodes, and the RMNRemote
/// contracts.
contract RMNHome is Ownable2Step, ITypeAndVersion {
/// @dev temp placeholder to exclude this contract from coverage
function test() public {}
contract RMNHome is OwnerIsCreator, ITypeAndVersion {
error DuplicatePeerId();
error DuplicateOffchainPublicKey();
error OutOfOrderSourceChains();
error OutOfOrderObserverNodeIndices();
error OutOfBoundsObserverNodeIndex();
error MinObserversTooHigh();

string public constant override typeAndVersion = "RMNHome 1.6.0-dev";
uint256 public constant CONFIG_RING_BUFFER_SIZE = 2;
event ConfigSet(bytes32 configDigest, VersionedConfig versionedConfig);
event ConfigRevoked(bytes32 configDigest);

struct Node {
string peerId; // used for p2p communication, base58 encoded
RensR marked this conversation as resolved.
Show resolved Hide resolved
RensR marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -38,6 +42,9 @@ contract RMNHome is Ownable2Step, ITypeAndVersion {
Config config;
}

string public constant override typeAndVersion = "RMNHome 1.6.0-dev";
uint256 public constant CONFIG_RING_BUFFER_SIZE = 2;

function _configDigest(VersionedConfig memory versionedConfig) internal pure returns (bytes32) {
uint256 h = uint256(keccak256(abi.encode(versionedConfig)));
uint256 prefixMask = type(uint256).max << (256 - 16); // 0xFFFF00..00
Expand Down Expand Up @@ -143,22 +150,4 @@ contract RMNHome is Ownable2Step, ITypeAndVersion {
}
}
}

///
/// Events
///

event ConfigSet(bytes32 configDigest, VersionedConfig versionedConfig);
event ConfigRevoked(bytes32 configDigest);

///
/// Errors
///

error DuplicatePeerId();
error DuplicateOffchainPublicKey();
error OutOfOrderSourceChains();
error OutOfOrderObserverNodeIndices();
error OutOfBoundsObserverNodeIndex();
error MinObserversTooHigh();
}
Loading
Loading