Skip to content

Commit

Permalink
Merge branch 'develop' into CCIP-4223_fix-gas-estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xsuryansh committed Jan 10, 2025
2 parents fe07034 + 8811103 commit 9b35ee7
Show file tree
Hide file tree
Showing 38 changed files with 440 additions and 78 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-lizards-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Changed RMNRemote and RMNHome parameter f to fObserve and fSign #updated
5 changes: 5 additions & 0 deletions contracts/.changeset/stale-dots-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/contracts': patch
---

replace f with fObserve in RMNHome and RMNRemote and update all tests CCIP-4058
4 changes: 2 additions & 2 deletions contracts/src/v0.8/ccip/rmn/RMNHome.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ contract RMNHome is Ownable2StepMsgSender, ITypeAndVersion {

struct SourceChain {
uint64 chainSelector; // ─╮ The Source chain selector.
uint64 f; // ─────────────╯ Maximum number of faulty observers; f+1 observers required to agree on an observation for this source chain.
uint64 fObserve; // ──────╯ Maximum number of faulty observers; f+1 observers required to agree on an observation for this source chain.
uint256 observerNodesBitmap; // ObserverNodesBitmap & (1<<i) == (1<<i) iff StaticConfig.nodes[i] is an observer for this source chain.
}

Expand Down Expand Up @@ -387,7 +387,7 @@ contract RMNHome is Ownable2StepMsgSender, ITypeAndVersion {
}

// min observers are tenable.
if (observersCount < 2 * currentSourceChain.f + 1) {
if (observersCount < 2 * currentSourceChain.fObserve + 1) {
revert NotEnoughObservers();
}
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/src/v0.8/ccip/rmn/RMNRemote.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract RMNRemote is Ownable2StepMsgSender, ITypeAndVersion, IRMNRemote, IRMN {
struct Config {
bytes32 rmnHomeContractConfigDigest; // Digest of the RMNHome contract config.
Signer[] signers; // List of signers.
uint64 f; // Max number of faulty RMN nodes; f+1 signers are required to verify a report, must configure 2f+1 signers in total.
uint64 fSign; // Max number of faulty RMN nodes; f+1 signers are required to verify a report, must configure 2f+1 signers in total.
}

/// @dev part of the payload that RMN nodes sign: keccak256(abi.encode(RMN_V1_6_ANY2EVM_REPORT, report)).
Expand Down Expand Up @@ -101,7 +101,7 @@ contract RMNRemote is Ownable2StepMsgSender, ITypeAndVersion, IRMNRemote, IRMN {
if (s_configCount == 0) {
revert ConfigNotSet();
}
if (signatures.length < s_config.f + 1) revert ThresholdNotMet();
if (signatures.length < s_config.fSign + 1) revert ThresholdNotMet();

bytes32 digest = keccak256(
abi.encode(
Expand Down Expand Up @@ -150,7 +150,7 @@ contract RMNRemote is Ownable2StepMsgSender, ITypeAndVersion, IRMNRemote, IRMN {
}

// min signers requirement is tenable.
if (newConfig.signers.length < 2 * newConfig.f + 1) {
if (newConfig.signers.length < 2 * newConfig.fSign + 1) {
revert NotEnoughSigners();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract RMNHome_revokeCandidate is RMNHomeTestSetup {
bytes32 digest = s_rmnHome.setCandidate(config.staticConfig, config.dynamicConfig, ZERO_DIGEST);
s_rmnHome.promoteCandidateAndRevokeActive(digest, ZERO_DIGEST);

config.dynamicConfig.sourceChains[1].f--;
config.dynamicConfig.sourceChains[1].fObserve--;
s_rmnHome.setCandidate(config.staticConfig, config.dynamicConfig, ZERO_DIGEST);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract RMNHome_setCandidate is RMNHomeTestSetup {
for (uint256 i = 0; i < storedDynamicConfig.sourceChains.length; i++) {
RMNHome.SourceChain memory storedSourceChain = storedDynamicConfig.sourceChains[i];
assertEq(storedSourceChain.chainSelector, versionedConfig.dynamicConfig.sourceChains[i].chainSelector);
assertEq(storedSourceChain.f, versionedConfig.dynamicConfig.sourceChains[i].f);
assertEq(storedSourceChain.fObserve, versionedConfig.dynamicConfig.sourceChains[i].fObserve);
assertEq(storedSourceChain.observerNodesBitmap, versionedConfig.dynamicConfig.sourceChains[i].observerNodesBitmap);
}
assertEq(storedDynamicConfig.offchainConfig, versionedConfig.dynamicConfig.offchainConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract RMNHome_setDynamicConfig is RMNHomeTestSetup {
(bytes32 priorActiveDigest,) = s_rmnHome.getConfigDigests();

Config memory config = _getBaseConfig();
config.dynamicConfig.sourceChains[1].f--;
config.dynamicConfig.sourceChains[1].fObserve--;

(, bytes32 candidateConfigDigest) = s_rmnHome.getConfigDigests();

Expand All @@ -27,7 +27,9 @@ contract RMNHome_setDynamicConfig is RMNHomeTestSetup {

(RMNHome.VersionedConfig memory storedVersionedConfig, bool ok) = s_rmnHome.getConfig(candidateConfigDigest);
assertTrue(ok);
assertEq(storedVersionedConfig.dynamicConfig.sourceChains[0].f, config.dynamicConfig.sourceChains[0].f);
assertEq(
storedVersionedConfig.dynamicConfig.sourceChains[0].fObserve, config.dynamicConfig.sourceChains[0].fObserve
);

// Asser the digests don't change when updating the dynamic config
(bytes32 activeDigest, bytes32 candidateDigest) = s_rmnHome.getConfigDigests();
Expand All @@ -38,7 +40,7 @@ contract RMNHome_setDynamicConfig is RMNHomeTestSetup {
// Asserts the validation function is being called
function test_RevertWhen_setDynamicConfig_MinObserversTooHigh() public {
Config memory config = _getBaseConfig();
config.dynamicConfig.sourceChains[0].f++;
config.dynamicConfig.sourceChains[0].fObserve++;

vm.expectRevert(abi.encodeWithSelector(RMNHome.DigestNotFound.selector, ZERO_DIGEST));
s_rmnHome.setDynamicConfig(config.dynamicConfig, ZERO_DIGEST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract RMNHome_validateStaticAndDynamicConfig is RMNHomeTestSetup {

function test_RevertWhen_validateStaticAndDynamicConfig_NotEnoughObservers() public {
Config memory config = _getBaseConfig();
config.dynamicConfig.sourceChains[0].f++;
config.dynamicConfig.sourceChains[0].fObserve++;

vm.expectRevert(RMNHome.NotEnoughObservers.selector);
s_rmnHome.setCandidate(config.staticConfig, config.dynamicConfig, ZERO_DIGEST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ contract RMNHomeTestSetup is Test {

RMNHome.SourceChain[] memory sourceChains = new RMNHome.SourceChain[](2);
// Observer 0 for source chain 9000
sourceChains[0] = RMNHome.SourceChain({chainSelector: 9000, f: 1, observerNodesBitmap: 1 << 0 | 1 << 1 | 1 << 2});
sourceChains[0] =
RMNHome.SourceChain({chainSelector: 9000, fObserve: 1, observerNodesBitmap: 1 << 0 | 1 << 1 | 1 << 2});
// Observers 0, 1 and 2 for source chain 9001
sourceChains[1] = RMNHome.SourceChain({chainSelector: 9001, f: 1, observerNodesBitmap: 1 << 0 | 1 << 1 | 1 << 2});
sourceChains[1] =
RMNHome.SourceChain({chainSelector: 9001, fObserve: 1, observerNodesBitmap: 1 << 0 | 1 << 1 | 1 << 2});

return Config({
staticConfig: RMNHome.StaticConfig({nodes: nodes, offchainConfig: abi.encode("static_config")}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {RMNRemoteSetup} from "./RMNRemoteSetup.t.sol";
contract RMNRemote_setConfig is RMNRemoteSetup {
function test_RevertWhen_setConfig_ZeroValueNotAllowed() public {
RMNRemote.Config memory config =
RMNRemote.Config({rmnHomeContractConfigDigest: bytes32(0), signers: s_signers, f: 1});
RMNRemote.Config({rmnHomeContractConfigDigest: bytes32(0), signers: s_signers, fSign: 1});

vm.expectRevert(RMNRemote.ZeroValueNotAllowed.selector);

Expand All @@ -18,7 +18,7 @@ contract RMNRemote_setConfig is RMNRemoteSetup {
uint32 currentConfigVersion = 0;
uint256 numSigners = s_signers.length;
RMNRemote.Config memory config =
RMNRemote.Config({rmnHomeContractConfigDigest: _randomBytes32(), signers: s_signers, f: 1});
RMNRemote.Config({rmnHomeContractConfigDigest: _randomBytes32(), signers: s_signers, fSign: 1});

vm.expectEmit();
emit RMNRemote.ConfigSet(++currentConfigVersion, config);
Expand All @@ -28,7 +28,7 @@ contract RMNRemote_setConfig is RMNRemoteSetup {
// add a signer
address newSigner = makeAddr("new signer");
s_signers.push(RMNRemote.Signer({onchainPublicKey: newSigner, nodeIndex: uint64(numSigners)}));
config = RMNRemote.Config({rmnHomeContractConfigDigest: _randomBytes32(), signers: s_signers, f: 1});
config = RMNRemote.Config({rmnHomeContractConfigDigest: _randomBytes32(), signers: s_signers, fSign: 1});

vm.expectEmit();
emit RMNRemote.ConfigSet(++currentConfigVersion, config);
Expand All @@ -44,7 +44,7 @@ contract RMNRemote_setConfig is RMNRemoteSetup {
// remove two signers
s_signers.pop();
s_signers.pop();
config = RMNRemote.Config({rmnHomeContractConfigDigest: _randomBytes32(), signers: s_signers, f: 1});
config = RMNRemote.Config({rmnHomeContractConfigDigest: _randomBytes32(), signers: s_signers, fSign: 1});

vm.expectEmit();
emit RMNRemote.ConfigSet(++currentConfigVersion, config);
Expand All @@ -59,7 +59,7 @@ contract RMNRemote_setConfig is RMNRemoteSetup {
function test_RevertWhen_setConfig_invalidSignerOrder() public {
s_signers.push(RMNRemote.Signer({onchainPublicKey: address(4), nodeIndex: 0}));
RMNRemote.Config memory config =
RMNRemote.Config({rmnHomeContractConfigDigest: _randomBytes32(), signers: s_signers, f: 1});
RMNRemote.Config({rmnHomeContractConfigDigest: _randomBytes32(), signers: s_signers, fSign: 1});

vm.expectRevert(RMNRemote.InvalidSignerOrder.selector);
s_rmnRemote.setConfig(config);
Expand All @@ -69,7 +69,7 @@ contract RMNRemote_setConfig is RMNRemoteSetup {
RMNRemote.Config memory config = RMNRemote.Config({
rmnHomeContractConfigDigest: _randomBytes32(),
signers: s_signers,
f: uint64(s_signers.length / 2) // at least 2f+1 is required
fSign: uint64(s_signers.length / 2) // at least 2f+1 is required
});

vm.expectRevert(RMNRemote.NotEnoughSigners.selector);
Expand All @@ -79,7 +79,7 @@ contract RMNRemote_setConfig is RMNRemoteSetup {
function test_RevertWhen_setConfig_duplicateOnChainPublicKey() public {
s_signers.push(RMNRemote.Signer({onchainPublicKey: s_signerWallets[0].addr, nodeIndex: uint64(s_signers.length)}));
RMNRemote.Config memory config =
RMNRemote.Config({rmnHomeContractConfigDigest: _randomBytes32(), signers: s_signers, f: 1});
RMNRemote.Config({rmnHomeContractConfigDigest: _randomBytes32(), signers: s_signers, fSign: 1});

vm.expectRevert(RMNRemote.DuplicateOnchainPublicKey.selector);
s_rmnRemote.setConfig(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract RMNRemote_verify_withConfigSet is RMNRemoteSetup {
super.setUp();

RMNRemote.Config memory config =
RMNRemote.Config({rmnHomeContractConfigDigest: _randomBytes32(), signers: s_signers, f: 3});
RMNRemote.Config({rmnHomeContractConfigDigest: _randomBytes32(), signers: s_signers, fSign: 3});
s_rmnRemote.setConfig(config);
_generatePayloadAndSigs(2, 4);
}
Expand Down Expand Up @@ -55,7 +55,7 @@ contract RMNRemote_verify_withConfigSet is RMNRemoteSetup {

function test_verify_RevertWhen_ThresholdNotMet() public {
RMNRemote.Config memory config =
RMNRemote.Config({rmnHomeContractConfigDigest: _randomBytes32(), signers: s_signers, f: 2}); // 3 = f+1 sigs required
RMNRemote.Config({rmnHomeContractConfigDigest: _randomBytes32(), signers: s_signers, fSign: 2}); // 3 = f+1 sigs required
s_rmnRemote.setConfig(config);

_generatePayloadAndSigs(2, 2); // 2 sigs generated, but 3 required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func GenerateRMNHomeConfigs(
SourceChains: []rmn_home.RMNHomeSourceChain{
{
ChainSelector: chainSelector,
F: f,
FObserve: f,
ObserverNodesBitmap: observerBitmap,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import (
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
"github.com/smartcontractkit/chainlink/v2/core/utils/testutils/heavyweight"

"github.com/smartcontractkit/chainlink-common/pkg/types"

"github.com/smartcontractkit/chainlink-ccip/pkg/contractreader"
"github.com/smartcontractkit/chainlink-ccip/pkg/reader"
cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
"github.com/smartcontractkit/chainlink-ccip/pluginconfig"
"github.com/smartcontractkit/chainlink-common/pkg/types"

evmconfig "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/configs/evm"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
Expand Down Expand Up @@ -195,7 +196,7 @@ func Test_USDCReader_MessageHashes(t *testing.T) {

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
hashes, err1 := usdcReader.MessageHashes(ctx, tc.sourceChain, tc.destChain, tc.tokens)
hashes, err1 := usdcReader.MessagesByTokenID(ctx, tc.sourceChain, tc.destChain, tc.tokens)
require.NoError(t, err1)

require.Equal(t, len(tc.expectedMsgIDs), len(hashes))
Expand Down Expand Up @@ -270,7 +271,7 @@ func Benchmark_MessageHashes(b *testing.B) {
b.ResetTimer()

for i := 0; i < b.N; i++ {
hashes, err := usdcReader.MessageHashes(ctx, sourceChain, destChain, tokens)
hashes, err := usdcReader.MessagesByTokenID(ctx, sourceChain, destChain, tokens)
require.NoError(b, err)
require.Len(b, hashes, tc.tokenCount) // Ensure the number of matches is as expected
}
Expand Down
Loading

0 comments on commit 9b35ee7

Please sign in to comment.