Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: integrate basic step flow #12

Merged
merged 35 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3d8724a
Initial commit
mpetrun5 Oct 18, 2023
a38e9fc
Add license check
mpetrun5 Oct 18, 2023
537bace
Remove extra makefile command
mpetrun5 Oct 18, 2023
0a5c842
Add temporary mocks command
mpetrun5 Oct 18, 2023
9312701
Add basic evm configuration
mpetrun5 Oct 19, 2023
1594a8a
Add basic node config
mpetrun5 Oct 19, 2023
b8d3243
Update license
mpetrun5 Oct 19, 2023
c4c4d5e
Merge branch 'main' into mpetrun5/initial-config-setup
mpetrun5 Oct 19, 2023
54ee6e0
Use custom named structs instead of embedding them
mpetrun5 Oct 19, 2023
d8c9e38
Fix license action
mpetrun5 Oct 19, 2023
73ef8a5
Use check license on CI
mpetrun5 Oct 19, 2023
7279b6f
Implement basic deposit handler
mpetrun5 Oct 20, 2023
599fd7c
Add deposit handler tests
mpetrun5 Oct 23, 2023
75c2d00
Update license
mpetrun5 Oct 23, 2023
fc42070
Add generic prover to deposit handler
mpetrun5 Oct 24, 2023
e014481
Update license
mpetrun5 Oct 24, 2023
4659fef
Update mocks check
mpetrun5 Oct 24, 2023
e11aab1
Fix version of mockgen to 0.3.0
mpetrun5 Oct 24, 2023
85b7d96
Merge branch 'main' into mpetrun5/deposit-event-handler
mpetrun5 Oct 24, 2023
1b3c5e1
Implement fetching epoch from timestamp
mpetrun5 Nov 2, 2023
672c624
Fetch and store epoch and proof
mpetrun5 Nov 2, 2023
de2b871
Add spectre contract
mpetrun5 Nov 2, 2023
34a10fd
Move step data to message package
mpetrun5 Nov 2, 2023
cba3406
Update deposit tests
mpetrun5 Nov 2, 2023
51b2170
Add step executor tests
mpetrun5 Nov 2, 2023
d441043
Update go.mod
mpetrun5 Nov 2, 2023
3ca19eb
Regenerate go.mod
mpetrun5 Nov 3, 2023
df9a2a6
Integrate custom listener that goes by finalized checkpoints
mpetrun5 Nov 6, 2023
702dec5
Merge branch 'main' into mpetrun5/listen-to-finalized-checkpoints
mpetrun5 Nov 6, 2023
57727ff
Add listener tests
mpetrun5 Nov 6, 2023
4116947
Regenerate go.mod
mpetrun5 Nov 6, 2023
ad0fad1
Remove extra prover module
mpetrun5 Nov 6, 2023
0e18e81
Update license
mpetrun5 Nov 6, 2023
547b154
Lint
mpetrun5 Nov 6, 2023
fbf3c4e
Remove prints
mpetrun5 Nov 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ test:

genmocks:
mockgen -source=./chains/evm/listener/events/handlers/deposit.go -destination=./mock/handlers.go -package mock
mockgen -source=./chains/evm/listener/listener.go -destination=./mock/listener.go -package mock
mockgen -source=./chains/evm/executor/step.go -destination=./mock/executor.go -package mock


PLATFORMS := linux/amd64 darwin/amd64 darwin/arm64 linux/arm
Expand Down
246 changes: 246 additions & 0 deletions chains/evm/abi/spectre.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
// The Licensed Work is (c) 2023 Sygma
// SPDX-License-Identifier: LGPL-3.0-only

package abi

const SpectreABI = `[
{
"inputs": [
{
"internalType": "address",
"name": "_stepVerifierAddress",
"type": "address"
},
{
"internalType": "address",
"name": "_committeeUpdateVerifierAddress",
"type": "address"
},
{
"internalType": "uint256",
"name": "_initialSyncPeriod",
"type": "uint256"
},
{
"internalType": "bytes32",
"name": "_initialSyncCommitteePoseidon",
"type": "bytes32"
},
{
"internalType": "uint256",
"name": "_slotsPerPeriod",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "blockHeaderRoots",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "committeeUpdateVerifier",
"outputs": [
{
"internalType": "contract CommitteeUpdateVerifier",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "executionStateRoots",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "head",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"components": [
{
"internalType": "bytes32",
"name": "syncCommitteeSSZ",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "syncCommitteePoseidon",
"type": "bytes32"
}
],
"internalType": "struct RotateLib.RotateInput",
"name": "rotateInput",
"type": "tuple"
},
{
"internalType": "bytes",
"name": "rotateProof",
"type": "bytes"
},
{
"components": [
{
"internalType": "uint64",
"name": "attestedSlot",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "finalizedSlot",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "participation",
"type": "uint64"
},
{
"internalType": "bytes32",
"name": "finalizedHeaderRoot",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "executionPayloadRoot",
"type": "bytes32"
}
],
"internalType": "struct SyncStepLib.SyncStepInput",
"name": "stepInput",
"type": "tuple"
},
{
"internalType": "bytes",
"name": "stepProof",
"type": "bytes"
}
],
"name": "rotate",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"components": [
{
"internalType": "uint64",
"name": "attestedSlot",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "finalizedSlot",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "participation",
"type": "uint64"
},
{
"internalType": "bytes32",
"name": "finalizedHeaderRoot",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "executionPayloadRoot",
"type": "bytes32"
}
],
"internalType": "struct SyncStepLib.SyncStepInput",
"name": "input",
"type": "tuple"
},
{
"internalType": "bytes",
"name": "proof",
"type": "bytes"
}
],
"name": "step",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "stepVerifier",
"outputs": [
{
"internalType": "contract SyncStepVerifier",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "syncCommitteePoseidons",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
}
]`
38 changes: 38 additions & 0 deletions chains/evm/contracts/spectre.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// The Licensed Work is (c) 2023 Sygma
// SPDX-License-Identifier: LGPL-3.0-only

package contracts

import (
"strings"

ethereumABI "github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"

"github.com/sygmaprotocol/spectre-node/chains/evm/abi"
"github.com/sygmaprotocol/spectre-node/chains/evm/message"
coreContracts "github.com/sygmaprotocol/sygma-core/chains/evm/contracts"
"github.com/sygmaprotocol/sygma-core/chains/evm/transactor"
)

type Spectre struct {
coreContracts.Contract
}

func NewSpectreContract(
address common.Address,
transactor transactor.Transactor,
) *Spectre {
a, _ := ethereumABI.JSON(strings.NewReader(abi.SpectreABI))
return &Spectre{
Contract: coreContracts.NewContract(address, a, nil, nil, transactor),
}
}

func (c *Spectre) Step(args message.SyncStepInput, poseidonCommitment [32]byte, opts transactor.TransactOptions) (*common.Hash, error) {
return c.ExecuteTransaction(
"step",
opts,
args, poseidonCommitment,
)
}
40 changes: 40 additions & 0 deletions chains/evm/executor/step.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// The Licensed Work is (c) 2023 Sygma
// SPDX-License-Identifier: LGPL-3.0-only

package executor

import (
"github.com/ethereum/go-ethereum/common"
"github.com/rs/zerolog/log"
"github.com/sygmaprotocol/spectre-node/chains/evm/message"
"github.com/sygmaprotocol/sygma-core/chains/evm/transactor"
"github.com/sygmaprotocol/sygma-core/relayer/proposal"
)

type StepSubmitter interface {
Step(args message.SyncStepInput, poseidonCommitment [32]byte, opts transactor.TransactOptions) (*common.Hash, error)
}

type EVMStepExecutor struct {
domainID uint8

stepSubmitter StepSubmitter
}

func NewEVMStepExecutor(domainID uint8, stepSubmitter StepSubmitter) *EVMStepExecutor {
return &EVMStepExecutor{
stepSubmitter: stepSubmitter,
domainID: domainID,
}
}

func (e *EVMStepExecutor) Execute(props []*proposal.Proposal) error {
stepData := props[0].Data.(message.StepData)
hash, err := e.stepSubmitter.Step(stepData.Args, stepData.Proof, transactor.TransactOptions{})
if err != nil {
return err
}

log.Info().Uint8("domainID", e.domainID).Msgf("Sent EVM step with hash: %s", hash)
return nil
}
54 changes: 54 additions & 0 deletions chains/evm/executor/step_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// The Licensed Work is (c) 2023 Sygma
// SPDX-License-Identifier: LGPL-3.0-only

package executor_test

import (
"fmt"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/suite"
"github.com/sygmaprotocol/spectre-node/chains/evm/executor"
"github.com/sygmaprotocol/spectre-node/chains/evm/message"
"github.com/sygmaprotocol/spectre-node/mock"
"github.com/sygmaprotocol/sygma-core/relayer/proposal"
"go.uber.org/mock/gomock"
)

type StepTestSuite struct {
suite.Suite

mockStepSubmitter *mock.MockStepSubmitter
executor *executor.EVMStepExecutor
}

func TestRunStepTestSuite(t *testing.T) {
suite.Run(t, new(StepTestSuite))
}

func (s *StepTestSuite) SetupTest() {
ctrl := gomock.NewController(s.T())
s.mockStepSubmitter = mock.NewMockStepSubmitter(ctrl)
s.executor = executor.NewEVMStepExecutor(1, s.mockStepSubmitter)
}

func (s *StepTestSuite) Test_Execute_SubmissionFails() {
s.mockStepSubmitter.EXPECT().Step(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, fmt.Errorf("error"))

err := s.executor.Execute([]*proposal.Proposal{{
Data: message.StepData{},
}})

s.NotNil(err)
}

func (s *StepTestSuite) Test_Execute_Successful() {
s.mockStepSubmitter.EXPECT().Step(gomock.Any(), gomock.Any(), gomock.Any()).Return(&common.Hash{}, nil)

err := s.executor.Execute([]*proposal.Proposal{{
Data: message.StepData{},
}})

s.Nil(err)
}
Loading
Loading