From 2b1dfdbe1b7fe56bc8b9208c9cd82e5cb72f086a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Sat, 17 Feb 2024 00:36:38 +0900 Subject: [PATCH] Mark utils as internal for inlining? --- contracts/gas-snapshots/keystone.gas-snapshot | 2 +- .../src/v0.8/keystone/KeystoneForwarder.sol | 4 ++-- .../src/v0.8/keystone/libraries/Utils.sol | 9 ++++++-- .../keystone/test/KeystoneForwarder.t.sol | 2 +- core/capabilities/targets/write_target.go | 23 ++++++++----------- .../capabilities/targets/write_target_test.go | 2 ++ integration-tests/go.mod | 1 + integration-tests/go.sum | 2 ++ 8 files changed, 26 insertions(+), 19 deletions(-) diff --git a/contracts/gas-snapshots/keystone.gas-snapshot b/contracts/gas-snapshots/keystone.gas-snapshot index 11897d62913..be23de1fc62 100644 --- a/contracts/gas-snapshots/keystone.gas-snapshot +++ b/contracts/gas-snapshots/keystone.gas-snapshot @@ -1,2 +1,2 @@ KeystoneForwarderTest:test_abi_partial_decoding_works() (gas: 2068) -KeystoneForwarderTest:test_it_works() (gas: 1026676) \ No newline at end of file +KeystoneForwarderTest:test_it_works() (gas: 993848) \ No newline at end of file diff --git a/contracts/src/v0.8/keystone/KeystoneForwarder.sol b/contracts/src/v0.8/keystone/KeystoneForwarder.sol index 056f5630687..2fa3304addc 100644 --- a/contracts/src/v0.8/keystone/KeystoneForwarder.sol +++ b/contracts/src/v0.8/keystone/KeystoneForwarder.sol @@ -39,12 +39,12 @@ contract KeystoneForwarder is IForwarder, ConfirmedOwner, TypeAndVersionInterfac // validate signatures for (uint256 i = 0; i < signatures.length; i++) { // TODO: is libocr-style multiple bytes32 arrays more optimal? - (bytes32 r, bytes32 s, uint8 v) = Utils.splitSignature(signatures[i]); + (bytes32 r, bytes32 s, uint8 v) = Utils._splitSignature(signatures[i]); address signer = ecrecover(hash, v, r, s); // TODO: we need to store oracle cluster similar to aggregator then, to validate valid signer list } - (bytes32 workflowId, bytes32 workflowExecutionId) = Utils.splitReport(rawReport); + (bytes32 workflowId, bytes32 workflowExecutionId) = Utils._splitReport(rawReport); // report was already processed if (s_reports[workflowExecutionId] != address(0)) { diff --git a/contracts/src/v0.8/keystone/libraries/Utils.sol b/contracts/src/v0.8/keystone/libraries/Utils.sol index 6ec6dcb89a0..3a11c0792a1 100644 --- a/contracts/src/v0.8/keystone/libraries/Utils.sol +++ b/contracts/src/v0.8/keystone/libraries/Utils.sol @@ -1,7 +1,10 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + // solhint-disable custom-errors library Utils { // solhint-disable avoid-low-level-calls, chainlink-solidity/explicit-returns - function splitSignature(bytes memory sig) public pure returns (bytes32 r, bytes32 s, uint8 v) { + function _splitSignature(bytes memory sig) internal pure returns (bytes32 r, bytes32 s, uint8 v) { require(sig.length == 65, "invalid signature length"); assembly { @@ -26,7 +29,9 @@ library Utils { } // solhint-disable avoid-low-level-calls, chainlink-solidity/explicit-returns - function splitReport(bytes memory rawReport) public pure returns (bytes32 workflowId, bytes32 workflowExecutionId) { + function _splitReport( + bytes memory rawReport + ) internal pure returns (bytes32 workflowId, bytes32 workflowExecutionId) { require(rawReport.length > 64, "invalid report length"); assembly { // skip first 32 bytes, contains length of the report diff --git a/contracts/src/v0.8/keystone/test/KeystoneForwarder.t.sol b/contracts/src/v0.8/keystone/test/KeystoneForwarder.t.sol index 1c47d697c33..10d4cb3f9c2 100644 --- a/contracts/src/v0.8/keystone/test/KeystoneForwarder.t.sol +++ b/contracts/src/v0.8/keystone/test/KeystoneForwarder.t.sol @@ -13,7 +13,7 @@ contract Receiver { function foo(bytes calldata rawReport) external { // decode metadata - (bytes32 workflowId, bytes32 workflowExecutionId) = Utils.splitReport(rawReport); + (bytes32 workflowId, bytes32 workflowExecutionId) = Utils._splitReport(rawReport); // parse actual report bytes[] memory mercuryReports = abi.decode(rawReport[64:], (bytes[])); emit MessageReceived(workflowId, workflowExecutionId, mercuryReports); diff --git a/core/capabilities/targets/write_target.go b/core/capabilities/targets/write_target.go index 3d5727f9282..c6d34271662 100644 --- a/core/capabilities/targets/write_target.go +++ b/core/capabilities/targets/write_target.go @@ -27,13 +27,6 @@ import ( var forwardABI = evmtypes.MustGetABI(forwarder.KeystoneForwarderMetaData.ABI) -var info = capabilities.MustNewCapabilityInfo( - "", - capabilities.CapabilityTypeTarget, - "Write target.", - "v1.0.0", -) - func InitializeWrite(registry commontypes.CapabilitiesRegistry, legacyEVMChains legacyevm.LegacyChainContainer) error { for _, chain := range legacyEVMChains.Slice() { capability := NewEvmWrite(chain) @@ -54,16 +47,20 @@ type EvmWrite struct { } func NewEvmWrite(chain legacyevm.Chain) *EvmWrite { - // generate ID based on name - info := info + // generate ID based on chain selector + name := fmt.Sprintf("write_%v", chain.ID()) chainName, err := chainselectors.NameFromChainId(chain.ID().Uint64()) if err == nil { - info.ID = fmt.Sprintf("write_%v", chainName) - - } else { - info.ID = fmt.Sprintf("write_%v", chain.ID()) + name = fmt.Sprintf("write_%v", chainName) } + info := capabilities.MustNewCapabilityInfo( + name, + capabilities.CapabilityTypeTarget, + "Write target.", + "v1.0.0", + ) + return &EvmWrite{ chain, info, diff --git a/core/capabilities/targets/write_target_test.go b/core/capabilities/targets/write_target_test.go index e4bd2e4e54f..68ca890cc0c 100644 --- a/core/capabilities/targets/write_target_test.go +++ b/core/capabilities/targets/write_target_test.go @@ -1,6 +1,7 @@ package targets_test import ( + "math/big" "testing" "github.com/smartcontractkit/chainlink-common/pkg/capabilities" @@ -27,6 +28,7 @@ func TestEvmWrite(t *testing.T) { chain := evmmocks.NewChain(t) txManager := txmmocks.NewMockEvmTxManager(t) + chain.On("ID").Return(big.NewInt(11155111)) chain.On("TxManager").Return(txManager) cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) { diff --git a/integration-tests/go.mod b/integration-tests/go.mod index e8d46fd8ab8..29483763f50 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -369,6 +369,7 @@ require ( github.com/shopspring/decimal v1.3.1 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 // indirect + github.com/smartcontractkit/chain-selectors v1.0.10 // indirect github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240213120401-01a23955f9f8 // indirect github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240214203158-47dae5de1336 // indirect github.com/smartcontractkit/chainlink-feeds v0.0.0-20240119021347-3c541a78cdb8 // indirect diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 9b5c4ad604d..849d8974815 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1501,6 +1501,8 @@ github.com/slack-go/slack v0.12.2 h1:x3OppyMyGIbbiyFhsBmpf9pwkUzMhthJMRNmNlA4LaQ github.com/slack-go/slack v0.12.2/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw= github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumvbfM1u/etVq42Afwq/jtNSBSOA8n5jntnNPo= github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M= +github.com/smartcontractkit/chain-selectors v1.0.10 h1:t9kJeE6B6G+hKD0GYR4kGJSCqR1LNS7aI3jT0V+xGrg= +github.com/smartcontractkit/chain-selectors v1.0.10/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE= github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240118014648-1ab6a88c9429 h1:xkejUBZhcBpBrTSfxc91Iwzadrb6SXw8ks69bHIQ9Ww= github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240118014648-1ab6a88c9429/go.mod h1:wJmVvDf4XSjsahWtfUq3wvIAYEAuhr7oxmxYnEL/LGQ= github.com/smartcontractkit/chainlink-common v0.1.7-0.20240215221559-8a726e745417 h1:1IeZowwqz3Uql9UqH8KP3C0J48wd/W0bVPMF5D+wDdA=