diff --git a/.github/workflows/mocks.yml b/.github/workflows/mocks.yml index b2e089e..3749697 100644 --- a/.github/workflows/mocks.yml +++ b/.github/workflows/mocks.yml @@ -16,7 +16,7 @@ jobs: with: go-version: "^1.17" - - run: go install github.com/golang/mock/mockgen@v1.6.0 + - run: go install go.uber.org/mock/mockgen@v0.3.0 - run: make genmocks diff --git a/Makefile b/Makefile index 33240c1..f6648cd 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ test: ./scripts/tests.sh genmocks: - echo '' + mockgen -source=./chains/evm/listener/events/handlers/deposit.go -destination=./mock/handlers.go -package mock PLATFORMS := linux/amd64 darwin/amd64 darwin/arm64 linux/arm diff --git a/chains/evm/abi/router.go b/chains/evm/abi/router.go new file mode 100644 index 0000000..30f15ee --- /dev/null +++ b/chains/evm/abi/router.go @@ -0,0 +1,213 @@ +// The Licensed Work is (c) 2023 Sygma +// SPDX-License-Identifier: LGPL-3.0-only + +package abi + +const RouterABI = `[ + { + "inputs": [ + { + "internalType": "uint8", + "name": "domainID", + "type": "uint8" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "DepositToCurrentDomain", + "type": "error" + }, + { + "inputs": [], + "name": "NonceDecrementsNotAllowed", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "destinationDomainID", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "securityModel", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "resourceID", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint64", + "name": "depositNonce", + "type": "uint64" + }, + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "Deposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "name": "_depositCounts", + "outputs": [ + { + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "_domainID", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "destinationDomainID", + "type": "uint8" + }, + { + "internalType": "uint8", + "name": "securityModel", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "resourceID", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "depositData", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "feeData", + "type": "bytes" + } + ], + "name": "deposit", + "outputs": [ + { + "internalType": "uint64", + "name": "depositNonce", + "type": "uint64" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "transferHashes", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +]` diff --git a/chains/evm/listener/events/events.go b/chains/evm/listener/events/events.go new file mode 100644 index 0000000..1086643 --- /dev/null +++ b/chains/evm/listener/events/events.go @@ -0,0 +1,36 @@ +// The Licensed Work is (c) 2023 Sygma +// SPDX-License-Identifier: LGPL-3.0-only + +package events + +import ( + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" +) + +type EventSig string + +func (es EventSig) GetTopic() common.Hash { + return crypto.Keccak256Hash([]byte(es)) +} + +const ( + DepositSig EventSig = "Deposit(uint8,uint8,bytes32,uint64,address,bytes)" +) + +// Deposit struct holds event data raised by Deposit event on-chain +type Deposit struct { + // ID of chain deposit will be bridged to + DestinationDomainID uint8 + // SecurityModel is used to distringuish between block header oracles + // on the destination network that verify this deposit + SecurityModel uint8 + // ResourceID used to find address of handler to be used for deposit + ResourceID [32]byte + // Nonce of deposit + DepositNonce uint64 + // Address of sender (msg.sender: user) + SenderAddress common.Address + // Additional data to be passed to specified handler + Data []byte +} diff --git a/chains/evm/listener/events/handlers/deposit.go b/chains/evm/listener/events/handlers/deposit.go new file mode 100644 index 0000000..15a5553 --- /dev/null +++ b/chains/evm/listener/events/handlers/deposit.go @@ -0,0 +1,122 @@ +// The Licensed Work is (c) 2023 Sygma +// SPDX-License-Identifier: LGPL-3.0-only + +package handlers + +import ( + "context" + "fmt" + "math/big" + "strings" + + ethereumABI "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/rs/zerolog/log" + "github.com/sygmaprotocol/spectre-node/chains/evm/abi" + "github.com/sygmaprotocol/spectre-node/chains/evm/listener/events" + evmMessage "github.com/sygmaprotocol/spectre-node/chains/evm/message" + "github.com/sygmaprotocol/sygma-core/relayer/message" +) + +type EventFetcher interface { + FetchEventLogs(ctx context.Context, contractAddress common.Address, event string, startBlock *big.Int, endBlock *big.Int) ([]types.Log, error) +} + +type StepProver interface { + StepProof(blocknumber *big.Int) (interface{}, error) +} + +type DepositEventHandler struct { + msgChan chan []*message.Message + + eventFetcher EventFetcher + stepProver StepProver + + domainID uint8 + routerABI ethereumABI.ABI + routerAddress common.Address +} + +func NewDepositEventHandler( + msgChan chan []*message.Message, + eventFetcher EventFetcher, + stepProver StepProver, + routerAddress common.Address, + domainID uint8, +) *DepositEventHandler { + routerABI, _ := ethereumABI.JSON(strings.NewReader(abi.RouterABI)) + return &DepositEventHandler{ + eventFetcher: eventFetcher, + stepProver: stepProver, + routerAddress: routerAddress, + routerABI: routerABI, + msgChan: msgChan, + domainID: domainID, + } +} + +// HandleEvents fetches deposit events and if deposits exists, submits a step message +// to be executed on the destination network +func (h *DepositEventHandler) HandleEvents(startBlock *big.Int, endBlock *big.Int) error { + deposits, err := h.fetchDeposits(startBlock, endBlock) + if err != nil { + return fmt.Errorf("unable to fetch deposit events because of: %+v", err) + } + domainDeposits := make(map[uint8][]*events.Deposit) + for _, d := range deposits { + domainDeposits[d.DestinationDomainID] = append(domainDeposits[d.DestinationDomainID], d) + } + if len(domainDeposits) == 0 { + return nil + } + + proof, err := h.stepProver.StepProof(endBlock) + if err != nil { + return err + } + for _, deposits := range domainDeposits { + h.msgChan <- []*message.Message{ + evmMessage.NewEvmStepMessage( + h.domainID, + deposits[0].DestinationDomainID, + proof, + ), + } + } + return nil +} + +func (h *DepositEventHandler) fetchDeposits(startBlock *big.Int, endBlock *big.Int) ([]*events.Deposit, error) { + logs, err := h.eventFetcher.FetchEventLogs(context.Background(), h.routerAddress, string(events.DepositSig), startBlock, endBlock) + if err != nil { + return nil, err + } + + deposits := make([]*events.Deposit, 0) + for _, dl := range logs { + d, err := h.unpackDeposit(dl.Data) + if err != nil { + log.Error().Msgf("Failed unpacking deposit event log: %v", err) + continue + } + d.SenderAddress = common.BytesToAddress(dl.Topics[1].Bytes()) + + log.Debug().Msgf("Found deposit log in block: %d, TxHash: %s, contractAddress: %s, sender: %s", dl.BlockNumber, dl.TxHash, dl.Address, d.SenderAddress) + deposits = append(deposits, d) + } + + return deposits, nil +} + +func (h *DepositEventHandler) unpackDeposit(data []byte) (*events.Deposit, error) { + fmt.Println(data) + + var d events.Deposit + err := h.routerABI.UnpackIntoInterface(&d, "Deposit", data) + if err != nil { + return &events.Deposit{}, err + } + + return &d, nil +} diff --git a/chains/evm/listener/events/handlers/deposit_test.go b/chains/evm/listener/events/handlers/deposit_test.go new file mode 100644 index 0000000..162cf44 --- /dev/null +++ b/chains/evm/listener/events/handlers/deposit_test.go @@ -0,0 +1,171 @@ +// The Licensed Work is (c) 2023 Sygma +// SPDX-License-Identifier: LGPL-3.0-only + +package handlers_test + +import ( + "context" + "encoding/hex" + "fmt" + "math/big" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/suite" + "github.com/sygmaprotocol/spectre-node/chains/evm/listener/events" + "github.com/sygmaprotocol/spectre-node/chains/evm/listener/events/handlers" + evmMessage "github.com/sygmaprotocol/spectre-node/chains/evm/message" + "github.com/sygmaprotocol/spectre-node/mock" + "github.com/sygmaprotocol/sygma-core/relayer/message" + "go.uber.org/mock/gomock" +) + +func readFromChannel(msgChan chan []*message.Message) ([]*message.Message, error) { + select { + case msgs := <-msgChan: + return msgs, nil + default: + return make([]*message.Message, 0), fmt.Errorf("no message sent") + } +} + +func SliceTo32Bytes(in []byte) [32]byte { + var res [32]byte + copy(res[:], in) + return res +} + +type DepositHandlerTestSuite struct { + suite.Suite + + depositHandler *handlers.DepositEventHandler + + msgChan chan []*message.Message + mockEventFetcher *mock.MockEventFetcher + mockStepProver *mock.MockStepProver +} + +func TestRunConfigTestSuite(t *testing.T) { + suite.Run(t, new(DepositHandlerTestSuite)) +} + +func (s *DepositHandlerTestSuite) SetupTest() { + ctrl := gomock.NewController(s.T()) + s.mockEventFetcher = mock.NewMockEventFetcher(ctrl) + s.mockStepProver = mock.NewMockStepProver(ctrl) + s.msgChan = make(chan []*message.Message, 1) + s.depositHandler = handlers.NewDepositEventHandler( + s.msgChan, + s.mockEventFetcher, + s.mockStepProver, + common.HexToAddress("0xb0b13f0109ef097C3Aa70Fb543EA4942114A845d"), + 1) +} + +func (s *DepositHandlerTestSuite) Test_HandleEvents_FetchingDepositsFails() { + startBlock := big.NewInt(0) + endBlock := big.NewInt(4) + s.mockEventFetcher.EXPECT().FetchEventLogs( + context.Background(), + gomock.Any(), + string(events.DepositSig), + startBlock, + endBlock, + ).Return(nil, fmt.Errorf("Error")) + + err := s.depositHandler.HandleEvents(startBlock, endBlock) + s.NotNil(err) + + _, err = readFromChannel(s.msgChan) + s.NotNil(err) +} + +func (s *DepositHandlerTestSuite) Test_HandleEvents_NoEvents_MessageNotSent() { + startBlock := big.NewInt(0) + endBlock := big.NewInt(4) + s.mockEventFetcher.EXPECT().FetchEventLogs( + context.Background(), + gomock.Any(), + string(events.DepositSig), + startBlock, + endBlock, + ).Return(make([]types.Log, 0), nil) + + err := s.depositHandler.HandleEvents(startBlock, endBlock) + s.Nil(err) + + _, err = readFromChannel(s.msgChan) + s.NotNil(err) +} + +func (s *DepositHandlerTestSuite) Test_HandleEvents_ValidDeposit_ProverFails() { + validDepositData, _ := hex.DecodeString("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000") + invalidDepositData := []byte("invalid") + + startBlock := big.NewInt(0) + endBlock := big.NewInt(4) + s.mockStepProver.EXPECT().StepProof(endBlock).Return(nil, fmt.Errorf("error")) + s.mockEventFetcher.EXPECT().FetchEventLogs( + context.Background(), + gomock.Any(), + string(events.DepositSig), + startBlock, + endBlock, + ).Return([]types.Log{ + { + Data: invalidDepositData, + }, + { + Data: validDepositData, + Topics: []common.Hash{ + {}, + common.HexToHash("0xd68eb9b5E135b96c1Af165e1D8c4e2eB0E1CE4CD"), + }, + }, + }, nil) + + err := s.depositHandler.HandleEvents(startBlock, endBlock) + s.NotNil(err) + + _, err = readFromChannel(s.msgChan) + s.NotNil(err) +} + +func (s *DepositHandlerTestSuite) Test_HandleEvents_ValidDeposit() { + validDepositData, _ := hex.DecodeString("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000") + invalidDepositData := []byte("invalid") + + startBlock := big.NewInt(0) + endBlock := big.NewInt(4) + s.mockStepProver.EXPECT().StepProof(endBlock).Return("step data", nil) + s.mockEventFetcher.EXPECT().FetchEventLogs( + context.Background(), + gomock.Any(), + string(events.DepositSig), + startBlock, + endBlock, + ).Return([]types.Log{ + { + Data: invalidDepositData, + }, + { + Data: validDepositData, + Topics: []common.Hash{ + {}, + common.HexToHash("0xd68eb9b5E135b96c1Af165e1D8c4e2eB0E1CE4CD"), + }, + }, + }, nil) + + err := s.depositHandler.HandleEvents(startBlock, endBlock) + s.Nil(err) + + msgs, err := readFromChannel(s.msgChan) + s.Nil(err) + s.Equal(msgs[0], evmMessage.NewEvmStepMessage( + 1, + 2, + "step data", + )) +} diff --git a/chains/evm/message/step.go b/chains/evm/message/step.go new file mode 100644 index 0000000..0373ba8 --- /dev/null +++ b/chains/evm/message/step.go @@ -0,0 +1,19 @@ +// The Licensed Work is (c) 2023 Sygma +// SPDX-License-Identifier: LGPL-3.0-only + +package message + +import "github.com/sygmaprotocol/sygma-core/relayer/message" + +const ( + EVMStepMessage message.MessageType = "EVMStepMessage" +) + +func NewEvmStepMessage(source uint8, destination uint8, stepProof interface{}) *message.Message { + return &message.Message{ + Source: source, + Destination: destination, + Data: stepProof, + Type: EVMStepMessage, + } +} diff --git a/go.mod b/go.mod index b5c2089..05ddb66 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,34 @@ module github.com/sygmaprotocol/spectre-node go 1.19 require ( + github.com/ethereum/go-ethereum v1.13.4 github.com/kelseyhightower/envconfig v1.4.0 + github.com/rs/zerolog v1.31.0 github.com/stretchr/testify v1.8.4 + github.com/sygmaprotocol/sygma-core v0.0.0-20231019093207-256532b316d8 + go.uber.org/mock v0.3.0 + ) require ( + github.com/bits-and-blooms/bitset v1.7.0 // indirect + github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect + github.com/consensys/bavard v0.1.13 // indirect + github.com/consensys/gnark-crypto v0.12.1 // indirect + github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect + github.com/ethereum/c-kzg-4844 v0.3.1 // indirect + github.com/go-stack/stack v1.8.1 // indirect + github.com/holiman/uint256 v1.2.3 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/supranational/blst v0.3.11 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/sync v0.3.0 // indirect + golang.org/x/sys v0.13.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + rsc.io/tmplfunc v0.0.3 // indirect ) diff --git a/go.sum b/go.sum index 8cddb33..cc8857a 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,123 @@ +github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM= +github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= +github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/bits-and-blooms/bitset v1.7.0 h1:YjAGVd3XmtK9ktAbX8Zg2g2PwLIMjGREZJHlV4j7NEo= +github.com/bits-and-blooms/bitset v1.7.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= +github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k= +github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 h1:KdUfX2zKommPRa+PD0sWZUyXe9w277ABlgELO7H04IM= +github.com/centrifuge/go-substrate-rpc-client/v4 v4.1.0 h1:GEvub7kU5YFAcn5A2uOo4AZSM1/cWZCOvfu7E3gQmK8= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cockroachdb/errors v1.8.1 h1:A5+txlVZfOqFBDa4mGz2bUWSp0aHElvHX2bKkdbQu+Y= +github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f h1:o/kfcElHqOiXqcou5a3rIlMc7oJbMQkeLk0VQJ7zgqY= +github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 h1:aPEJyR4rPBvDmeyi+l/FS/VtA00IWvjeFvjen1m1l1A= +github.com/cockroachdb/redact v1.0.8 h1:8QG/764wK+vmEYoOlfobpe12EQcS81ukx/a4hdVMxNw= +github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 h1:IKgmqgMQlVJIZj19CdocBeSfSaiCbEBZGKODaixqtHM= +github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= +github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= +github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= +github.com/consensys/gnark-crypto v0.12.1 h1:lHH39WuuFgVHONRl3J0LRBtuYdQTumFSDtJF7HpyG8M= +github.com/consensys/gnark-crypto v0.12.1/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= +github.com/crate-crypto/go-kzg-4844 v0.3.0 h1:UBlWE0CgyFqqzTI+IFyCzA7A3Zw4iip6uzRv5NIXG0A= +github.com/crate-crypto/go-kzg-4844 v0.3.0/go.mod h1:SBP7ikXEgDnUPONgm33HtuDZEDtWa3L4QtN1ocJSEQ4= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= +github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI= +github.com/decred/base58 v1.0.4 h1:QJC6B0E0rXOPA8U/kw2rP+qiRJsUaE2Er+pYb3siUeA= +github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= +github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= +github.com/ethereum/c-kzg-4844 v0.3.1 h1:sR65+68+WdnMKxseNWxSJuAv2tsUrihTpVBTfM/U5Zg= +github.com/ethereum/c-kzg-4844 v0.3.1/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= +github.com/ethereum/go-ethereum v1.13.4 h1:25HJnaWVg3q1O7Z62LaaI6S9wVq8QCw3K88g8wEzrcM= +github.com/ethereum/go-ethereum v1.13.4/go.mod h1:I0U5VewuuTzvBtVzKo7b3hJzDhXOUtn9mJW7SsIPB0Q= +github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY= +github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= +github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= +github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gtank/merlin v0.1.1 h1:eQ90iG7K9pOhtereWsmyRJ6RAwcP4tHTDBHXNg+u5is= +github.com/gtank/ristretto255 v0.1.2 h1:JEqUCPA1NvLq5DwYtuzigd7ss8fwbYay9fi4/5uMzcc= +github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o= +github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= +github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= +github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI= +github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b h1:QrHweqAtyJ9EwCaGHBu1fghwxIPiopAHV06JlXrMHjk= +github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= +github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= +github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/pierrec/xxHash v0.1.5 h1:n/jBpwTHiER4xYvK3/CdPVnLDPchj8eTJFFLUb4QHBo= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v1.12.0 h1:C+UIj/QWtmqY13Arb8kwMt5j34/0Z2iKamrJ+ryC0Gg= +github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a h1:CmF68hwI0XsOQ5UwlBopMi2Ow4Pbg32akc4KIVCOm+Y= +github.com/prometheus/common v0.32.1 h1:hWIdL3N2HoUx3B8j3YN9mWor0qhY/NlEKZEaXxuIRh4= +github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= +github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= +github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= +github.com/sygmaprotocol/sygma-core v0.0.0-20231019093207-256532b316d8 h1:GRfMPF9faTUkWe51dCzM/VVLX58q5niGzOliFqsmVaA= +github.com/sygmaprotocol/sygma-core v0.0.0-20231019093207-256532b316d8/go.mod h1:b4RZCyYr20Mp4WAAj4TkC6gU2KZ0ZWcpSGmKc6n8NKc= +github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/vedhavyas/go-subkey v1.0.4 h1:QwjBZx4w7qXC2lmqol2jJfhaNXPI9BsgLZiMiCwqGDU= +go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo= +go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= +rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= diff --git a/mock/handlers.go b/mock/handlers.go new file mode 100644 index 0000000..630f04b --- /dev/null +++ b/mock/handlers.go @@ -0,0 +1,95 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./chains/evm/listener/events/handlers/deposit.go +// +// Generated by this command: +// +// mockgen -source=./chains/evm/listener/events/handlers/deposit.go -destination=./mock/handlers.go -package mock +// +// Package mock is a generated GoMock package. +package mock + +import ( + context "context" + big "math/big" + reflect "reflect" + + common "github.com/ethereum/go-ethereum/common" + types "github.com/ethereum/go-ethereum/core/types" + gomock "go.uber.org/mock/gomock" +) + +// MockEventFetcher is a mock of EventFetcher interface. +type MockEventFetcher struct { + ctrl *gomock.Controller + recorder *MockEventFetcherMockRecorder +} + +// MockEventFetcherMockRecorder is the mock recorder for MockEventFetcher. +type MockEventFetcherMockRecorder struct { + mock *MockEventFetcher +} + +// NewMockEventFetcher creates a new mock instance. +func NewMockEventFetcher(ctrl *gomock.Controller) *MockEventFetcher { + mock := &MockEventFetcher{ctrl: ctrl} + mock.recorder = &MockEventFetcherMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEventFetcher) EXPECT() *MockEventFetcherMockRecorder { + return m.recorder +} + +// FetchEventLogs mocks base method. +func (m *MockEventFetcher) FetchEventLogs(ctx context.Context, contractAddress common.Address, event string, startBlock, endBlock *big.Int) ([]types.Log, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FetchEventLogs", ctx, contractAddress, event, startBlock, endBlock) + ret0, _ := ret[0].([]types.Log) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// FetchEventLogs indicates an expected call of FetchEventLogs. +func (mr *MockEventFetcherMockRecorder) FetchEventLogs(ctx, contractAddress, event, startBlock, endBlock any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FetchEventLogs", reflect.TypeOf((*MockEventFetcher)(nil).FetchEventLogs), ctx, contractAddress, event, startBlock, endBlock) +} + +// MockStepProver is a mock of StepProver interface. +type MockStepProver struct { + ctrl *gomock.Controller + recorder *MockStepProverMockRecorder +} + +// MockStepProverMockRecorder is the mock recorder for MockStepProver. +type MockStepProverMockRecorder struct { + mock *MockStepProver +} + +// NewMockStepProver creates a new mock instance. +func NewMockStepProver(ctrl *gomock.Controller) *MockStepProver { + mock := &MockStepProver{ctrl: ctrl} + mock.recorder = &MockStepProverMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockStepProver) EXPECT() *MockStepProverMockRecorder { + return m.recorder +} + +// StepProof mocks base method. +func (m *MockStepProver) StepProof(blocknumber *big.Int) (any, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StepProof", blocknumber) + ret0, _ := ret[0].(any) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StepProof indicates an expected call of StepProof. +func (mr *MockStepProverMockRecorder) StepProof(blocknumber any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StepProof", reflect.TypeOf((*MockStepProver)(nil).StepProof), blocknumber) +}