Skip to content

Commit

Permalink
Mark utils as internal for inlining?
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Feb 16, 2024
1 parent b446d96 commit 2b1dfdb
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion contracts/gas-snapshots/keystone.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
KeystoneForwarderTest:test_abi_partial_decoding_works() (gas: 2068)
KeystoneForwarderTest:test_it_works() (gas: 1026676)
KeystoneForwarderTest:test_it_works() (gas: 993848)
4 changes: 2 additions & 2 deletions contracts/src/v0.8/keystone/KeystoneForwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
9 changes: 7 additions & 2 deletions contracts/src/v0.8/keystone/libraries/Utils.sol
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/keystone/test/KeystoneForwarder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 10 additions & 13 deletions core/capabilities/targets/write_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions core/capabilities/targets/write_target_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package targets_test

import (
"math/big"
"testing"

"github.com/smartcontractkit/chainlink-common/pkg/capabilities"
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 2b1dfdb

Please sign in to comment.