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

Make onRamp mutable in OffRamp #1422

Merged
merged 24 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b6d52f9
chore: make onRamp mutable in OffRamp
RayXpub Sep 10, 2024
2a6fb27
chore: update gas snapshot and geth wrappers
RayXpub Sep 10, 2024
72b52e8
chore: fmt
RayXpub Sep 10, 2024
4456bc5
chore: add onRamp check in commit and add conditions for onRamp update
RayXpub Sep 11, 2024
bc82b76
Merge branch 'ccip-develop' into feat/make-onramp-dynamic-var-in-offramp
RayXpub Sep 11, 2024
5fde62e
chore: update gas snapshot and geth wrappers
RayXpub Sep 11, 2024
9977ca4
chore: fmt
RayXpub Sep 11, 2024
da09dc4
chore: update gas snapshot
RayXpub Sep 11, 2024
e2bcb9c
chore: lower optimizer rounds
RayXpub Sep 11, 2024
1324349
chore: update gas snapshot
RayXpub Sep 11, 2024
b461638
Merge branch 'ccip-develop' into feat/make-onramp-dynamic-var-in-offramp
RayXpub Sep 12, 2024
e1c2bfd
chore: revert cache var
RayXpub Sep 12, 2024
77db35e
chore: move check into else if statement
RayXpub Sep 12, 2024
cfbf85c
chore: rm unused error
RayXpub Sep 12, 2024
54afc4f
chore: move check to else if block and add test
RayXpub Sep 12, 2024
97cdccb
Merge branch 'ccip-develop' into feat/make-onramp-dynamic-var-in-offramp
RayXpub Sep 12, 2024
2b52acd
chore: update gas snapshot and geth wrappers
RayXpub Sep 12, 2024
52d36b1
chore: fmt
RayXpub Sep 12, 2024
48868c7
chore: update geth wrappers
RayXpub Sep 12, 2024
1f19f84
chore: rename event
RayXpub Sep 12, 2024
2abe966
Merge branch 'ccip-develop' into feat/make-onramp-dynamic-var-in-offramp
RayXpub Sep 12, 2024
85ee9c7
chore: update gas snapshot
RayXpub Sep 12, 2024
f4dcd49
Merge 85ee9c7c3d6b90ed5685a015c7fe41dfb56d6cea into 3d54dfb3e03e5e738…
RayXpub Sep 12, 2024
8495bb5
Update gethwrappers
app-token-issuer-infra-releng[bot] Sep 12, 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
2 changes: 1 addition & 1 deletion contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ single_line_statement_blocks = "preserve"
solc_version = '0.8.24'
src = 'src/v0.8/ccip'
test = 'src/v0.8/ccip/test'
optimizer_runs = 1_925
optimizer_runs = 1_650
Copy link
Contributor

Choose a reason for hiding this comment

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

😅

evm_version = 'paris'

[profile.functions]
Expand Down
1,434 changes: 717 additions & 717 deletions contracts/gas-snapshots/ccip.gas-snapshot

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/scripts/native_solc_compile_all_ccip
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SOLC_VERSION="0.8.24"
OPTIMIZE_RUNS=26000
OPTIMIZE_RUNS_OFFRAMP=18000
OPTIMIZE_RUNS_ONRAMP=4100
OPTIMIZE_RUNS_MULTI_OFFRAMP=1925
OPTIMIZE_RUNS_MULTI_OFFRAMP=1650


SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
Expand Down
34 changes: 24 additions & 10 deletions contracts/src/v0.8/ccip/offRamp/OffRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
error InvalidMessageDestChainSelector(uint64 messageDestChainSelector);
error SourceChainSelectorMismatch(uint64 reportSourceChainSelector, uint64 messageSourceChainSelector);
error SignatureVerificationDisabled();
error InvalidOnRamp(bytes reportOnRamp, bytes configOnRamp);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: naming - should we name this InvalidCommitOnRamp?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think here the most likely scenario is that the wrong onRamp would be the configured one, not the one from the commit report.

Copy link
Collaborator

@elatoskinas elatoskinas Sep 12, 2024

Choose a reason for hiding this comment

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

Main confusion with the current naming is that this is easily confused with InvalidOnRampUpdate - would help if this error included that it is in the commit context (maybe CommitRampMismatch would be more accurate)

Copy link
Collaborator Author

@RayXpub RayXpub Sep 12, 2024

Choose a reason for hiding this comment

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

Updated to CommitOnRampMismatch

error InvalidOnRampUpdate();

/// @dev Atlas depends on this event, if changing, please notify Atlas.
event StaticConfigSet(StaticConfig staticConfig);
Expand Down Expand Up @@ -132,6 +134,8 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {

// STATIC CONFIG
string public constant override typeAndVersion = "OffRamp 1.6.0-dev";
/// @dev Hash of encoded address(0) used for empty address checks
bytes32 internal constant EMPTY_ENCODED_ADDRESS_HASH = keccak256(abi.encode(address(0)));
/// @dev ChainSelector of this chain
uint64 internal immutable i_chainSelector;
/// @dev The RMN verification contract
Expand Down Expand Up @@ -617,6 +621,11 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
}

SourceChainConfig storage sourceChainConfig = _getEnabledSourceChainConfig(sourceChainSelector);
bytes memory onRamp = sourceChainConfig.onRamp;

if (keccak256(root.onRampAddress) != keccak256(onRamp)) {
revert InvalidOnRamp(root.onRampAddress, onRamp);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: reading onRamp into memory seems like an optimization for the error path, yeah? I think we could save on the happy path if we just read from storage again when doing the revert.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, updated.


if (sourceChainConfig.minSeqNr != root.minSeqNr || root.minSeqNr > root.maxSeqNr) {
revert InvalidInterval(root.sourceChainSelector, root.minSeqNr, root.maxSeqNr);
Expand Down Expand Up @@ -738,24 +747,29 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
}

SourceChainConfig storage currentConfig = s_sourceChainConfigs[sourceChainSelector];
bytes memory currentOnRamp = currentConfig.onRamp;
bytes memory newOnRamp = sourceConfigUpdate.onRamp;

// OnRamp can never be zero - if it is, then the source chain has been added for the first time
if (currentOnRamp.length == 0) {
if (newOnRamp.length == 0) {
revert ZeroAddressNotAllowed();
}

currentConfig.onRamp = newOnRamp;
if (currentConfig.onRamp.length == 0) {
currentConfig.minSeqNr = 1;
emit SourceChainSelectorAdded(sourceChainSelector);
} else if (keccak256(currentOnRamp) != keccak256(newOnRamp)) {
revert InvalidStaticConfig(sourceChainSelector);
elatoskinas marked this conversation as resolved.
Show resolved Hide resolved
}

// OnRamp can never be zero - if it is, then the source chain has been added for the first time
if (newOnRamp.length == 0 || keccak256(newOnRamp) == EMPTY_ENCODED_ADDRESS_HASH) {
revert ZeroAddressNotAllowed();
}

// OnRamp updates should only happens due to a misconfiguration
// If an OnRamp is misconfigured not reports should have been committed and no messages should have been executed
// This is enforced byt the onRamp address check in the commit function
if (currentConfig.minSeqNr != 1) {
elatoskinas marked this conversation as resolved.
Show resolved Hide resolved
revert InvalidOnRampUpdate();
elatoskinas marked this conversation as resolved.
Show resolved Hide resolved
}

currentConfig.onRamp = newOnRamp;
currentConfig.isEnabled = sourceConfigUpdate.isEnabled;
currentConfig.router = sourceConfigUpdate.router;

emit SourceChainConfigSet(sourceChainSelector, currentConfig);
}
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/test/e2e/MultiRampsEnd2End.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ contract MultiRampsE2E is OnRampSetup, OffRampSetup {
});
roots[1] = Internal.MerkleRoot({
sourceChainSelector: SOURCE_CHAIN_SELECTOR + 1,
onRampAddress: abi.encode(address(s_onRamp)),
onRampAddress: abi.encode(address(s_onRamp2)),
minSeqNr: messages2[0].header.sequenceNumber,
maxSeqNr: messages2[0].header.sequenceNumber,
merkleRoot: merkleRoots[1]
Expand Down
85 changes: 42 additions & 43 deletions contracts/src/v0.8/ccip/test/offRamp/OffRamp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -789,24 +789,6 @@ contract OffRamp_executeSingleReport is OffRampSetup {
s_offRamp.executeSingleReport(executionReport, new uint256[](0));
}

function test_MismatchingOnRampRoot_Revert() public {
s_offRamp.setVerifyOverrideResult(SOURCE_CHAIN_SELECTOR_1, 0);

Internal.Any2EVMRampMessage[] memory messages =
_generateSingleBasicMessage(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1);

OffRamp.CommitReport memory commitReport = _constructCommitReport(
// Root against mismatching on ramp
Internal._hash(messages[0], ON_RAMP_ADDRESS_3)
);
_commit(commitReport, s_latestSequenceNumber);

Internal.ExecutionReportSingleChain memory executionReport =
_generateReportFromMessages(SOURCE_CHAIN_SELECTOR_1, messages);
vm.expectRevert(abi.encodeWithSelector(OffRamp.RootNotCommitted.selector, SOURCE_CHAIN_SELECTOR_1));
s_offRamp.executeSingleReport(executionReport, new uint256[](0));
}

function test_UnhealthySingleChainCurse_Revert() public {
_setMockRMNChainCurse(SOURCE_CHAIN_SELECTOR_1, true);
vm.expectEmit();
Expand Down Expand Up @@ -3047,6 +3029,27 @@ contract OffRamp_applySourceChainConfigUpdates is OffRampSetup {
);
}

function test_ReplaceExistingChainOnRamp_Success() public {
OffRamp.SourceChainConfigArgs[] memory sourceChainConfigs = new OffRamp.SourceChainConfigArgs[](1);
sourceChainConfigs[0] = OffRamp.SourceChainConfigArgs({
router: s_destRouter,
sourceChainSelector: SOURCE_CHAIN_SELECTOR_1,
onRamp: ON_RAMP_ADDRESS_1,
isEnabled: true
});

s_offRamp.applySourceChainConfigUpdates(sourceChainConfigs);

sourceChainConfigs[0].onRamp = ON_RAMP_ADDRESS_2;

vm.expectEmit();
emit OffRamp.SourceChainConfigSet(
SOURCE_CHAIN_SELECTOR_1,
OffRamp.SourceChainConfig({router: s_destRouter, isEnabled: true, minSeqNr: 1, onRamp: ON_RAMP_ADDRESS_2})
);
s_offRamp.applySourceChainConfigUpdates(sourceChainConfigs);
}

// Reverts

function test_ZeroOnRampAddress_Revert() public {
Expand All @@ -3060,6 +3063,10 @@ contract OffRamp_applySourceChainConfigUpdates is OffRampSetup {

vm.expectRevert(OffRamp.ZeroAddressNotAllowed.selector);
s_offRamp.applySourceChainConfigUpdates(sourceChainConfigs);

sourceChainConfigs[0].onRamp = abi.encode(address(0));
vm.expectRevert(OffRamp.ZeroAddressNotAllowed.selector);
s_offRamp.applySourceChainConfigUpdates(sourceChainConfigs);
}

function test_RouterAddress_Revert() public {
Expand Down Expand Up @@ -3087,23 +3094,6 @@ contract OffRamp_applySourceChainConfigUpdates is OffRampSetup {
vm.expectRevert(OffRamp.ZeroChainSelectorNotAllowed.selector);
s_offRamp.applySourceChainConfigUpdates(sourceChainConfigs);
}

function test_ReplaceExistingChainOnRamp_Revert() public {
OffRamp.SourceChainConfigArgs[] memory sourceChainConfigs = new OffRamp.SourceChainConfigArgs[](1);
sourceChainConfigs[0] = OffRamp.SourceChainConfigArgs({
router: s_destRouter,
sourceChainSelector: SOURCE_CHAIN_SELECTOR_1,
onRamp: ON_RAMP_ADDRESS_1,
isEnabled: true
});

s_offRamp.applySourceChainConfigUpdates(sourceChainConfigs);

sourceChainConfigs[0].onRamp = ON_RAMP_ADDRESS_2;

vm.expectRevert(abi.encodeWithSelector(OffRamp.InvalidStaticConfig.selector, SOURCE_CHAIN_SELECTOR_1));
s_offRamp.applySourceChainConfigUpdates(sourceChainConfigs);
}
}

contract OffRamp_commit is OffRampSetup {
Expand Down Expand Up @@ -3138,7 +3128,7 @@ contract OffRamp_commit is OffRampSetup {
Internal.MerkleRoot[] memory roots = new Internal.MerkleRoot[](1);
roots[0] = Internal.MerkleRoot({
sourceChainSelector: SOURCE_CHAIN_SELECTOR_1,
onRampAddress: abi.encode(ON_RAMP_ADDRESS_1),
onRampAddress: ON_RAMP_ADDRESS_1,
minSeqNr: 1,
maxSeqNr: max1,
merkleRoot: root
Expand Down Expand Up @@ -3167,7 +3157,7 @@ contract OffRamp_commit is OffRampSetup {
Internal.MerkleRoot[] memory roots = new Internal.MerkleRoot[](1);
roots[0] = Internal.MerkleRoot({
sourceChainSelector: SOURCE_CHAIN_SELECTOR_1,
onRampAddress: abi.encode(ON_RAMP_ADDRESS_1),
onRampAddress: ON_RAMP_ADDRESS_1,
minSeqNr: 1,
maxSeqNr: maxSeq,
merkleRoot: "stale report 1"
Expand Down Expand Up @@ -3318,7 +3308,7 @@ contract OffRamp_commit is OffRampSetup {
roots = new Internal.MerkleRoot[](1);
roots[0] = Internal.MerkleRoot({
sourceChainSelector: SOURCE_CHAIN_SELECTOR_1,
onRampAddress: abi.encode(ON_RAMP_ADDRESS_1),
onRampAddress: ON_RAMP_ADDRESS_1,
minSeqNr: 1,
maxSeqNr: maxSeq,
merkleRoot: "stale report"
Expand Down Expand Up @@ -3424,7 +3414,7 @@ contract OffRamp_commit is OffRampSetup {
Internal.MerkleRoot[] memory roots = new Internal.MerkleRoot[](1);
roots[0] = Internal.MerkleRoot({
sourceChainSelector: SOURCE_CHAIN_SELECTOR_1,
onRampAddress: abi.encode(ON_RAMP_ADDRESS_1),
onRampAddress: ON_RAMP_ADDRESS_1,
minSeqNr: 1,
maxSeqNr: 4,
merkleRoot: bytes32(0)
Expand All @@ -3440,7 +3430,7 @@ contract OffRamp_commit is OffRampSetup {
Internal.MerkleRoot[] memory roots = new Internal.MerkleRoot[](1);
roots[0] = Internal.MerkleRoot({
sourceChainSelector: SOURCE_CHAIN_SELECTOR_1,
onRampAddress: abi.encode(ON_RAMP_ADDRESS_1),
onRampAddress: ON_RAMP_ADDRESS_1,
minSeqNr: 2,
maxSeqNr: 2,
merkleRoot: bytes32(0)
Expand All @@ -3461,7 +3451,7 @@ contract OffRamp_commit is OffRampSetup {
Internal.MerkleRoot[] memory roots = new Internal.MerkleRoot[](1);
roots[0] = Internal.MerkleRoot({
sourceChainSelector: SOURCE_CHAIN_SELECTOR_1,
onRampAddress: abi.encode(ON_RAMP_ADDRESS_1),
onRampAddress: ON_RAMP_ADDRESS_1,
minSeqNr: 1,
maxSeqNr: 0,
merkleRoot: bytes32(0)
Expand Down Expand Up @@ -3526,7 +3516,7 @@ contract OffRamp_commit is OffRampSetup {
Internal.MerkleRoot[] memory roots = new Internal.MerkleRoot[](1);
roots[0] = Internal.MerkleRoot({
sourceChainSelector: SOURCE_CHAIN_SELECTOR_1,
onRampAddress: abi.encode(ON_RAMP_ADDRESS_1),
onRampAddress: ON_RAMP_ADDRESS_1,
minSeqNr: 1,
maxSeqNr: 2,
merkleRoot: "Only a single root"
Expand All @@ -3544,11 +3534,20 @@ contract OffRamp_commit is OffRampSetup {
_commit(commitReport, ++s_latestSequenceNumber);
}

function test_InvalidOnRamp_Revert() public {
OffRamp.CommitReport memory commitReport = _constructCommitReport();

commitReport.merkleRoots[0].onRampAddress = ON_RAMP_ADDRESS_2;

vm.expectRevert(abi.encodeWithSelector(OffRamp.InvalidOnRamp.selector, ON_RAMP_ADDRESS_2, ON_RAMP_ADDRESS_1));
_commit(commitReport, s_latestSequenceNumber);
}

function _constructCommitReport() internal view returns (OffRamp.CommitReport memory) {
Internal.MerkleRoot[] memory roots = new Internal.MerkleRoot[](1);
roots[0] = Internal.MerkleRoot({
sourceChainSelector: SOURCE_CHAIN_SELECTOR_1,
onRampAddress: abi.encode(ON_RAMP_ADDRESS_1),
onRampAddress: ON_RAMP_ADDRESS_1,
minSeqNr: 1,
maxSeqNr: s_maxInterval,
merkleRoot: "test #2"
Expand Down
4 changes: 2 additions & 2 deletions core/gethwrappers/ccip/generated/offramp/offramp.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ multi_aggregate_rate_limiter: ../../../contracts/solc/v0.8.24/MultiAggregateRate
multi_ocr3_helper: ../../../contracts/solc/v0.8.24/MultiOCR3Helper/MultiOCR3Helper.abi ../../../contracts/solc/v0.8.24/MultiOCR3Helper/MultiOCR3Helper.bin 6b56e0114a4d50797d30a34aecc2641ef340451d0c3fcb9d729bba4df2435122
nonce_manager: ../../../contracts/solc/v0.8.24/NonceManager/NonceManager.abi ../../../contracts/solc/v0.8.24/NonceManager/NonceManager.bin 6f64e1083b356c06ee66b9138e398b9c97a4cd3e8c9ec38cf3010cebc79af536
ocr3_config_encoder: ../../../contracts/solc/v0.8.24/IOCR3ConfigEncoder/IOCR3ConfigEncoder.abi ../../../contracts/solc/v0.8.24/IOCR3ConfigEncoder/IOCR3ConfigEncoder.bin 9254b35a86f00fde7b7193a033ca58f6521a66e87b9cf9da6ce5660082e79f5d
offramp: ../../../contracts/solc/v0.8.24/OffRamp/OffRamp.abi ../../../contracts/solc/v0.8.24/OffRamp/OffRamp.bin 741b4b66670c06c1b09408ec6706656c46e4c98b227111d99f80940cc5faad42
offramp: ../../../contracts/solc/v0.8.24/OffRamp/OffRamp.abi ../../../contracts/solc/v0.8.24/OffRamp/OffRamp.bin 3b81bd7b38eb5051b8aef1462f838ff734eb9189073d9534cab443589201a1cc
onramp: ../../../contracts/solc/v0.8.24/OnRamp/OnRamp.abi ../../../contracts/solc/v0.8.24/OnRamp/OnRamp.bin 594439983f963f4158f9c5009dee7cba4ee56be61900bb1d5b9108eaeac3d6a6
ping_pong_demo: ../../../contracts/solc/v0.8.24/PingPongDemo/PingPongDemo.abi ../../../contracts/solc/v0.8.24/PingPongDemo/PingPongDemo.bin c1c2f8a65c7ffd971899cae7fe62f2da57d09e936151e2b92163c4bebe699d6b
price_registry: ../../../contracts/solc/v0.8.24/PriceRegistry/PriceRegistry.abi ../../../contracts/solc/v0.8.24/PriceRegistry/PriceRegistry.bin e7781d600c1bb7aa4620106af7f6e146a109b97f4cb6a7d06c9e15773340ecb2
Expand Down
Loading