From dd1c3be8fafd26d46308af1b984adad760e7f700 Mon Sep 17 00:00:00 2001 From: dimkouv Date: Fri, 8 Sep 2023 12:55:12 +0300 Subject: [PATCH] rename hasher to hashlib and place under internal --- core/services/ocr2/plugins/ccip/commit_plugin.go | 4 ++-- .../ocr2/plugins/ccip/commit_reporting_plugin.go | 6 +++--- .../plugins/ccip/commit_reporting_plugin_test.go | 8 ++++---- .../plugins/ccip/execution_batch_building.go | 6 +++--- .../ocr2/plugins/ccip/execution_plugin.go | 4 ++-- .../plugins/ccip/execution_reporting_plugin.go | 4 ++-- .../ccip/execution_reporting_plugin_test.go | 4 ++-- .../ccip/{hasher => internal/hashlib}/hasher.go | 2 +- .../{hasher => internal/hashlib}/hasher_test.go | 2 +- .../{hasher => internal/hashlib}/leaf_hasher.go | 2 +- .../hashlib}/leaf_hasher_test.go | 12 ++++++------ .../ccip/internal/merklemulti/merkle_multi.go | 16 ++++++++-------- .../internal/merklemulti/merkle_multi_test.go | 6 +++--- .../services/ocr2/plugins/ccip/plugins_common.go | 4 ++-- .../plugins/ccip/testhelpers/ccip_contracts.go | 6 +++--- .../ccip/testhelpers/plugins/plugin_harness.go | 6 +++--- 16 files changed, 46 insertions(+), 46 deletions(-) rename core/services/ocr2/plugins/ccip/{hasher => internal/hashlib}/hasher.go (98%) rename core/services/ocr2/plugins/ccip/{hasher => internal/hashlib}/hasher_test.go (95%) rename core/services/ocr2/plugins/ccip/{hasher => internal/hashlib}/leaf_hasher.go (99%) rename core/services/ocr2/plugins/ccip/{hasher => internal/hashlib}/leaf_hasher_test.go (89%) diff --git a/core/services/ocr2/plugins/ccip/commit_plugin.go b/core/services/ocr2/plugins/ccip/commit_plugin.go index 2410695883..f91169a58d 100644 --- a/core/services/ocr2/plugins/ccip/commit_plugin.go +++ b/core/services/ocr2/plugins/ccip/commit_plugin.go @@ -15,6 +15,7 @@ import ( relaylogger "github.com/smartcontractkit/chainlink-relay/pkg/logger" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipevents" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/oraclelib" "github.com/smartcontractkit/chainlink/v2/core/chains/evm" @@ -26,7 +27,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/job" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers" ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/hasher" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/promwrapper" "github.com/smartcontractkit/chainlink/v2/core/services/pg" "github.com/smartcontractkit/chainlink/v2/core/services/pipeline" @@ -95,7 +95,7 @@ func NewCommitServices(lggr logger.Logger, jb job.Job, chainSet evm.LegacyChainC return nil, err } - leafHasher := hasher.NewLeafHasher(staticConfig.SourceChainSelector, staticConfig.ChainSelector, onRamp.Address(), hasher.NewKeccakCtx()) + leafHasher := hashlib.NewLeafHasher(staticConfig.SourceChainSelector, staticConfig.ChainSelector, onRamp.Address(), hashlib.NewKeccakCtx()) // Note that lggr already has the jobName and contractID (commit store) commitLggr := lggr.Named("CCIPCommit").With( "sourceChain", ChainName(int64(chainId)), diff --git a/core/services/ocr2/plugins/ccip/commit_reporting_plugin.go b/core/services/ocr2/plugins/ccip/commit_reporting_plugin.go index cd01141155..2bfb050e3e 100644 --- a/core/services/ocr2/plugins/ccip/commit_reporting_plugin.go +++ b/core/services/ocr2/plugins/ccip/commit_reporting_plugin.go @@ -25,9 +25,9 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers" ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/hasher" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/cache" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipevents" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/merklemulti" ) @@ -63,7 +63,7 @@ type CommitPluginConfig struct { sourceNative common.Address sourceFeeEstimator gas.EvmFeeEstimator sourceClient, destClient evmclient.Client - leafHasher hasher.LeafHasherInterface[[32]byte] + leafHasher hashlib.LeafHasherInterface[[32]byte] checkFinalityTags bool } @@ -677,7 +677,7 @@ func (r *CommitReportingPlugin) buildReport(ctx context.Context, lggr logger.Log return commit_store.CommitStoreCommitReport{}, fmt.Errorf("tried building a tree without leaves") } - tree, err := merklemulti.NewTree(hasher.NewKeccakCtx(), leaves) + tree, err := merklemulti.NewTree(hashlib.NewKeccakCtx(), leaves) if err != nil { return commit_store.CommitStoreCommitReport{}, err } diff --git a/core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go b/core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go index 60bf396e47..416cad1258 100644 --- a/core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go +++ b/core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go @@ -34,9 +34,9 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers" ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/hasher" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/cache" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipevents" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/merklemulti" plugintesthelpers "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/testhelpers/plugins" "github.com/smartcontractkit/chainlink/v2/core/store/models" @@ -84,7 +84,7 @@ func setupCommitTestHarness(t *testing.T) commitTestHarness { sourceChainSelector: th.Source.ChainSelector, destClient: backendClient, sourceClient: backendClient, - leafHasher: hasher.NewLeafHasher(th.Source.ChainSelector, th.Dest.ChainSelector, th.Source.OnRamp.Address(), hasher.NewKeccakCtx()), + leafHasher: hashlib.NewLeafHasher(th.Source.ChainSelector, th.Dest.ChainSelector, th.Source.OnRamp.Address(), hashlib.NewKeccakCtx()), }, inflightReports: newInflightCommitReportsContainer(time.Hour), onchainConfig: th.CommitOnchainConfig, @@ -141,7 +141,7 @@ func TestCommitReportEncoding(t *testing.T) { newGasPrice := big.NewInt(2000e9) // $2000 per eth * 1gwei // Send a report. - mctx := hasher.NewKeccakCtx() + mctx := hashlib.NewKeccakCtx() tree, err := merklemulti.NewTree(mctx, [][32]byte{mctx.Hash([]byte{0xaa})}) require.NoError(t, err) report := commit_store.CommitStoreCommitReport{ @@ -1095,7 +1095,7 @@ func TestShouldAcceptFinalizedReport(t *testing.T) { } func TestCommitReportToEthTxMeta(t *testing.T) { - mctx := hasher.NewKeccakCtx() + mctx := hashlib.NewKeccakCtx() tree, err := merklemulti.NewTree(mctx, [][32]byte{mctx.Hash([]byte{0xaa})}) require.NoError(t, err) diff --git a/core/services/ocr2/plugins/ccip/execution_batch_building.go b/core/services/ocr2/plugins/ccip/execution_batch_building.go index f1ec25a9f6..5f2019c24f 100644 --- a/core/services/ocr2/plugins/ccip/execution_batch_building.go +++ b/core/services/ocr2/plugins/ccip/execution_batch_building.go @@ -13,8 +13,8 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_onramp" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/hasher" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipevents" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/merklemulti" "github.com/smartcontractkit/chainlink/v2/core/services/pg" ) @@ -22,7 +22,7 @@ import ( func getProofData( ctx context.Context, lggr logger.Logger, - hashLeaf hasher.LeafHasherInterface[[32]byte], + hashLeaf hashlib.LeafHasherInterface[[32]byte], onRampAddress common.Address, sourceEventsClient ccipevents.Client, interval commit_store.CommitStoreInterval, @@ -41,7 +41,7 @@ func getProofData( if err != nil { return nil, nil, nil, err } - tree, err = merklemulti.NewTree(hasher.NewKeccakCtx(), leaves) + tree, err = merklemulti.NewTree(hashlib.NewKeccakCtx(), leaves) if err != nil { return nil, nil, nil, err } diff --git a/core/services/ocr2/plugins/ccip/execution_plugin.go b/core/services/ocr2/plugins/ccip/execution_plugin.go index 4b5b08e4e1..093dad2fe0 100644 --- a/core/services/ocr2/plugins/ccip/execution_plugin.go +++ b/core/services/ocr2/plugins/ccip/execution_plugin.go @@ -16,6 +16,7 @@ import ( relaylogger "github.com/smartcontractkit/chainlink-relay/pkg/logger" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipevents" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/oraclelib" "github.com/smartcontractkit/chainlink/v2/core/chains/evm" @@ -29,7 +30,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/job" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers" ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/hasher" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/observability" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/promwrapper" "github.com/smartcontractkit/chainlink/v2/core/services/pg" @@ -122,7 +122,7 @@ func NewExecutionServices(lggr logger.Logger, jb job.Job, chainSet evm.LegacyCha destClient: destChain.Client(), sourceClient: sourceChain.Client(), destGasEstimator: destChain.GasEstimator(), - leafHasher: hasher.NewLeafHasher(offRampConfig.SourceChainSelector, offRampConfig.ChainSelector, onRamp.Address(), hasher.NewKeccakCtx()), + leafHasher: hashlib.NewLeafHasher(offRampConfig.SourceChainSelector, offRampConfig.ChainSelector, onRamp.Address(), hashlib.NewKeccakCtx()), }) err = wrappedPluginFactory.UpdateLogPollerFilters(zeroAddress) diff --git a/core/services/ocr2/plugins/ccip/execution_reporting_plugin.go b/core/services/ocr2/plugins/ccip/execution_reporting_plugin.go index 68eaab22a0..f7735bfd68 100644 --- a/core/services/ocr2/plugins/ccip/execution_reporting_plugin.go +++ b/core/services/ocr2/plugins/ccip/execution_reporting_plugin.go @@ -32,9 +32,9 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers" ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/hasher" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/cache" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipevents" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/observability" "github.com/smartcontractkit/chainlink/v2/core/services/pg" ) @@ -65,7 +65,7 @@ type ExecutionPluginConfig struct { destClient evmclient.Client sourceClient evmclient.Client destGasEstimator gas.EvmFeeEstimator - leafHasher hasher.LeafHasherInterface[[32]byte] + leafHasher hashlib.LeafHasherInterface[[32]byte] } type ExecutionReportingPlugin struct { diff --git a/core/services/ocr2/plugins/ccip/execution_reporting_plugin_test.go b/core/services/ocr2/plugins/ccip/execution_reporting_plugin_test.go index 56d8316161..ad58b96aae 100644 --- a/core/services/ocr2/plugins/ccip/execution_reporting_plugin_test.go +++ b/core/services/ocr2/plugins/ccip/execution_reporting_plugin_test.go @@ -30,6 +30,7 @@ import ( ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/cache" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipevents" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/testhelpers" plugintesthelpers "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/testhelpers/plugins" "github.com/smartcontractkit/chainlink/v2/core/utils" @@ -39,7 +40,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/commit_store" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_offramp" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/hasher" "github.com/smartcontractkit/chainlink/v2/core/store/models" ) @@ -90,7 +90,7 @@ func setupExecTestHarness(t *testing.T) execTestHarness { destClient: th.DestClient, sourceClient: th.SourceClient, sourceWrappedNativeToken: th.Source.WrappedNative.Address(), - leafHasher: hasher.NewLeafHasher(th.Source.ChainSelector, th.Dest.ChainSelector, th.Source.OnRamp.Address(), hasher.NewKeccakCtx()), + leafHasher: hashlib.NewLeafHasher(th.Source.ChainSelector, th.Dest.ChainSelector, th.Source.OnRamp.Address(), hashlib.NewKeccakCtx()), destGasEstimator: destFeeEstimator, }, onchainConfig: th.ExecOnchainConfig, diff --git a/core/services/ocr2/plugins/ccip/hasher/hasher.go b/core/services/ocr2/plugins/ccip/internal/hashlib/hasher.go similarity index 98% rename from core/services/ocr2/plugins/ccip/hasher/hasher.go rename to core/services/ocr2/plugins/ccip/internal/hashlib/hasher.go index 2f2a4f555a..6eeb4e2f1d 100644 --- a/core/services/ocr2/plugins/ccip/hasher/hasher.go +++ b/core/services/ocr2/plugins/ccip/internal/hashlib/hasher.go @@ -1,4 +1,4 @@ -package hasher +package hashlib import ( "bytes" diff --git a/core/services/ocr2/plugins/ccip/hasher/hasher_test.go b/core/services/ocr2/plugins/ccip/internal/hashlib/hasher_test.go similarity index 95% rename from core/services/ocr2/plugins/ccip/hasher/hasher_test.go rename to core/services/ocr2/plugins/ccip/internal/hashlib/hasher_test.go index 9fa558efba..856be2358b 100644 --- a/core/services/ocr2/plugins/ccip/hasher/hasher_test.go +++ b/core/services/ocr2/plugins/ccip/internal/hashlib/hasher_test.go @@ -1,4 +1,4 @@ -package hasher +package hashlib import ( "testing" diff --git a/core/services/ocr2/plugins/ccip/hasher/leaf_hasher.go b/core/services/ocr2/plugins/ccip/internal/hashlib/leaf_hasher.go similarity index 99% rename from core/services/ocr2/plugins/ccip/hasher/leaf_hasher.go rename to core/services/ocr2/plugins/ccip/internal/hashlib/leaf_hasher.go index 8a93e8a520..3bcd9e9c85 100644 --- a/core/services/ocr2/plugins/ccip/hasher/leaf_hasher.go +++ b/core/services/ocr2/plugins/ccip/internal/hashlib/leaf_hasher.go @@ -1,4 +1,4 @@ -package hasher +package hashlib import ( "math/big" diff --git a/core/services/ocr2/plugins/ccip/hasher/leaf_hasher_test.go b/core/services/ocr2/plugins/ccip/internal/hashlib/leaf_hasher_test.go similarity index 89% rename from core/services/ocr2/plugins/ccip/hasher/leaf_hasher_test.go rename to core/services/ocr2/plugins/ccip/internal/hashlib/leaf_hasher_test.go index 4acf16dbd4..faddb1b673 100644 --- a/core/services/ocr2/plugins/ccip/hasher/leaf_hasher_test.go +++ b/core/services/ocr2/plugins/ccip/internal/hashlib/leaf_hasher_test.go @@ -1,4 +1,4 @@ -package hasher_test +package hashlib_test import ( "encoding/hex" @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_onramp" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/hasher" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/testhelpers" ) @@ -17,9 +17,9 @@ func TestHasher(t *testing.T) { sourceChainSelector, destChainSelector := uint64(1), uint64(4) onRampAddress := common.HexToAddress("0x5550000000000000000000000000000000000001") - hashingCtx := hasher.NewKeccakCtx() + hashingCtx := hashlib.NewKeccakCtx() - hasher := hasher.NewLeafHasher(sourceChainSelector, destChainSelector, onRampAddress, hashingCtx) + hasher := hashlib.NewLeafHasher(sourceChainSelector, destChainSelector, onRampAddress, hashingCtx) message := evm_2_evm_onramp.InternalEVM2EVMMessage{ SourceChainSelector: sourceChainSelector, @@ -72,7 +72,7 @@ func TestHasher(t *testing.T) { func TestMetaDataHash(t *testing.T) { sourceChainSelector, destChainSelector := uint64(1), uint64(4) onRampAddress := common.HexToAddress("0x5550000000000000000000000000000000000001") - ctx := hasher.NewKeccakCtx() - hash := hasher.GetMetaDataHash(ctx, ctx.Hash([]byte("EVM2EVMSubscriptionMessagePlus")), sourceChainSelector, onRampAddress, destChainSelector) + ctx := hashlib.NewKeccakCtx() + hash := hashlib.GetMetaDataHash(ctx, ctx.Hash([]byte("EVM2EVMSubscriptionMessagePlus")), sourceChainSelector, onRampAddress, destChainSelector) require.Equal(t, "e8b93c9d01a7a72ec6c7235e238701cf1511b267a31fdb78dd342649ee58c08d", hex.EncodeToString(hash[:])) } diff --git a/core/services/ocr2/plugins/ccip/internal/merklemulti/merkle_multi.go b/core/services/ocr2/plugins/ccip/internal/merklemulti/merkle_multi.go index 55096b1485..c9031b470e 100644 --- a/core/services/ocr2/plugins/ccip/internal/merklemulti/merkle_multi.go +++ b/core/services/ocr2/plugins/ccip/internal/merklemulti/merkle_multi.go @@ -6,16 +6,16 @@ import ( "github.com/pkg/errors" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/hasher" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib" ) -type singleLayerProof[H hasher.Hash] struct { +type singleLayerProof[H hashlib.Hash] struct { nextIndices []int subProof []H sourceFlags []bool } -type Proof[H hasher.Hash] struct { +type Proof[H hashlib.Hash] struct { Hashes []H `json:"hashes"` SourceFlags []bool `json:"source_flags"` } @@ -44,7 +44,7 @@ func siblingIndex(idx int) int { return idx ^ 1 } -func proveSingleLayer[H hasher.Hash](layer []H, indices []int) (singleLayerProof[H], error) { +func proveSingleLayer[H hashlib.Hash](layer []H, indices []int) (singleLayerProof[H], error) { var ( authIndices []int nextIndices []int @@ -77,11 +77,11 @@ func proveSingleLayer[H hasher.Hash](layer []H, indices []int) (singleLayerProof }, nil } -type Tree[H hasher.Hash] struct { +type Tree[H hashlib.Hash] struct { layers [][]H } -func NewTree[H hasher.Hash](ctx hasher.Ctx[H], leafHashes []H) (*Tree[H], error) { +func NewTree[H hashlib.Hash](ctx hashlib.Ctx[H], leafHashes []H) (*Tree[H], error) { if len(leafHashes) == 0 { return nil, errors.New("Cannot construct a tree without leaves") } @@ -131,7 +131,7 @@ func (t *Tree[H]) Prove(indices []int) (Proof[H], error) { return proof, nil } -func computeNextLayer[H hasher.Hash](ctx hasher.Ctx[H], layer []H) ([]H, []H) { +func computeNextLayer[H hashlib.Hash](ctx hashlib.Ctx[H], layer []H) ([]H, []H) { if len(layer) == 1 { return layer, layer } @@ -145,7 +145,7 @@ func computeNextLayer[H hasher.Hash](ctx hasher.Ctx[H], layer []H) ([]H, []H) { return layer, nextLayer } -func VerifyComputeRoot[H hasher.Hash](ctx hasher.Ctx[H], leafHashes []H, proof Proof[H]) (H, error) { +func VerifyComputeRoot[H hashlib.Hash](ctx hashlib.Ctx[H], leafHashes []H, proof Proof[H]) (H, error) { leavesLength := len(leafHashes) proofsLength := len(proof.Hashes) if leavesLength == 0 && proofsLength == 0 { diff --git a/core/services/ocr2/plugins/ccip/internal/merklemulti/merkle_multi_test.go b/core/services/ocr2/plugins/ccip/internal/merklemulti/merkle_multi_test.go index 145fe51a46..fc85172158 100644 --- a/core/services/ocr2/plugins/ccip/internal/merklemulti/merkle_multi_test.go +++ b/core/services/ocr2/plugins/ccip/internal/merklemulti/merkle_multi_test.go @@ -10,12 +10,12 @@ import ( "github.com/stretchr/testify/require" "gonum.org/v1/gonum/stat/combin" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/hasher" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/merklemulti/fixtures" ) var ( - ctx = hasher.NewKeccakCtx() + ctx = hashlib.NewKeccakCtx() a, b, c, d, e, f = ctx.Hash([]byte{0xa}), ctx.Hash([]byte{0xb}), ctx.Hash([]byte{0xc}), ctx.Hash([]byte{0xd}), ctx.Hash([]byte{0xe}), ctx.Hash([]byte{0xf}) ) @@ -87,7 +87,7 @@ func TestSpecFixtureVerifyProof(t *testing.T) { func TestSpecFixtureNewTree(t *testing.T) { for _, testVector := range fixtures.TestVectors { var leafHashes = hashesFromHexStrings(testVector.AllLeafs) - mctx := hasher.NewKeccakCtx() + mctx := hashlib.NewKeccakCtx() tree, err := NewTree(mctx, leafHashes) assert.NoError(t, err) actualRoot := tree.Root() diff --git a/core/services/ocr2/plugins/ccip/plugins_common.go b/core/services/ocr2/plugins/ccip/plugins_common.go index e472404801..8c023d2f72 100644 --- a/core/services/ocr2/plugins/ccip/plugins_common.go +++ b/core/services/ocr2/plugins/ccip/plugins_common.go @@ -19,8 +19,8 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_onramp_1_0_0" "github.com/smartcontractkit/chainlink/v2/core/logger" ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/hasher" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipevents" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/observability" "github.com/smartcontractkit/chainlink/v2/core/services/pg" "github.com/smartcontractkit/chainlink/v2/core/utils" @@ -123,7 +123,7 @@ func calculateUsdPerUnitGas(sourceGasPrice *big.Int, usdPerFeeCoin *big.Int) *bi func leavesFromIntervals( lggr logger.Logger, interval commit_store.CommitStoreInterval, - hasher hasher.LeafHasherInterface[[32]byte], + hasher hashlib.LeafHasherInterface[[32]byte], sendReqs []ccipevents.Event[evm_2_evm_onramp.EVM2EVMOnRampCCIPSendRequested], ) ([][32]byte, error) { var seqNrs []uint64 diff --git a/core/services/ocr2/plugins/ccip/testhelpers/ccip_contracts.go b/core/services/ocr2/plugins/ccip/testhelpers/ccip_contracts.go index f9517e2760..6d5fd6adb1 100644 --- a/core/services/ocr2/plugins/ccip/testhelpers/ccip_contracts.go +++ b/core/services/ocr2/plugins/ccip/testhelpers/ccip_contracts.go @@ -38,7 +38,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/burn_mint_erc677" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/hasher" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/merklemulti" "github.com/smartcontractkit/chainlink/v2/core/utils" ) @@ -1337,8 +1337,8 @@ func (args *ManualExecArgs) execute(report *commit_store.CommitStoreCommitReport log.Info().Msg("Executing request manually") seqNr := args.seqNr // Build a merkle tree for the report - mctx := hasher.NewKeccakCtx() - leafHasher := hasher.NewLeafHasher(args.SourceChainID, args.DestChainID, common.HexToAddress(args.OnRamp), mctx) + mctx := hashlib.NewKeccakCtx() + leafHasher := hashlib.NewLeafHasher(args.SourceChainID, args.DestChainID, common.HexToAddress(args.OnRamp), mctx) onRampContract, err := evm_2_evm_onramp.NewEVM2EVMOnRamp(common.HexToAddress(args.OnRamp), args.SourceChain) if err != nil { return nil, err diff --git a/core/services/ocr2/plugins/ccip/testhelpers/plugins/plugin_harness.go b/core/services/ocr2/plugins/ccip/testhelpers/plugins/plugin_harness.go index 2cc4e37644..61de46d80f 100644 --- a/core/services/ocr2/plugins/ccip/testhelpers/plugins/plugin_harness.go +++ b/core/services/ocr2/plugins/ccip/testhelpers/plugins/plugin_harness.go @@ -21,7 +21,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers" ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config" - "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/hasher" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/merklemulti" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/testhelpers" "github.com/smartcontractkit/chainlink/v2/core/utils" @@ -195,8 +195,8 @@ func (mb MessageBatch) ToExecutionReport() evm_2_evm_offramp.InternalExecutionRe } func (th *CCIPPluginTestHarness) GenerateAndSendMessageBatch(t *testing.T, nMessages int, payloadSize int, nTokensPerMessage int) MessageBatch { - mctx := hasher.NewKeccakCtx() - leafHasher := hasher.NewLeafHasher(th.Source.ChainSelector, th.Dest.ChainSelector, th.Source.OnRamp.Address(), mctx) + mctx := hashlib.NewKeccakCtx() + leafHasher := hashlib.NewLeafHasher(th.Source.ChainSelector, th.Dest.ChainSelector, th.Source.OnRamp.Address(), mctx) maxPayload := make([]byte, payloadSize) for i := 0; i < payloadSize; i++ {