Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltea committed Feb 21, 2024
1 parent 93e8d19 commit ce79ee3
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 45 deletions.
3 changes: 1 addition & 2 deletions chains/evm/contracts/spectre.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func (c *Spectre) Step(

func (c *Spectre) Rotate(
domainID uint8,
rotateInput message.RotateInput,
rotateProof []byte,
stepInput message.SyncStepInput,
stepProof []byte,
Expand All @@ -55,6 +54,6 @@ func (c *Spectre) Rotate(
return c.ExecuteTransaction(
"rotate",
opts,
domainID, rotateInput, rotateProof, stepInput, stepProof,
domainID, rotateProof, stepInput, stepProof,
)
}
3 changes: 1 addition & 2 deletions chains/evm/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type ProofSubmitter interface {
) (*common.Hash, error)
Rotate(
domainID uint8,
rotateInput message.RotateInput,
rotateProof []byte,
stepInput message.SyncStepInput,
stepProof []byte,
Expand Down Expand Up @@ -67,6 +66,7 @@ func (e *EVMExecutor) step(domainID uint8, stepData message.StepData) error {
stepData.StateRootProof,
transactor.TransactOptions{})
if err != nil {
fmt.Println(err)
return err
}

Expand All @@ -77,7 +77,6 @@ func (e *EVMExecutor) step(domainID uint8, stepData message.StepData) error {
func (e *EVMExecutor) rotate(domainID uint8, rotateData message.RotateData) error {
hash, err := e.proofSubmitter.Rotate(
domainID,
rotateData.RotateInput,
rotateData.RotateProof,
rotateData.StepInput,
rotateData.StepProof,
Expand Down
1 change: 0 additions & 1 deletion chains/evm/listener/handlers/rotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func (h *RotateHandler) HandleEvents(checkpoint *apiv1.Finality) error {
log.Debug().Uint8("domainID", h.domainID).Msgf("Sending rotate message to domain %d", domain)
h.msgChan <- []*message.Message{
evmMessage.NewEvmRotateMessage(h.domainID, domain, evmMessage.RotateData{
RotateInput: rotateProof.Input,
RotateProof: rotateProof.Proof,
StepProof: stepProof.Proof,
StepInput: stepProof.Input,
Expand Down
2 changes: 1 addition & 1 deletion chains/evm/listener/handlers/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type EventFetcher interface {

type Prover interface {
StepProof(args *prover.StepArgs) (*prover.EvmProof[evmMessage.SyncStepInput], error)
RotateProof(args *prover.RotateArgs) (*prover.EvmProof[evmMessage.RotateInput], error)
RotateProof(args *prover.RotateArgs) (*prover.EvmProof[struct{}], error)
StepArgs() (*prover.StepArgs, error)
RotateArgs(epoch uint64) (*prover.RotateArgs, error)
}
Expand Down
9 changes: 0 additions & 9 deletions chains/evm/message/rotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package message

import (
"math/big"

"github.com/rs/zerolog/log"
"github.com/sygmaprotocol/sygma-core/relayer/message"
"github.com/sygmaprotocol/sygma-core/relayer/proposal"
Expand All @@ -16,15 +14,8 @@ const (
EVMRotateProposal proposal.ProposalType = "EVMRotateProposal"
)

type RotateInput struct {
SyncCommitteeSSZ [32]byte
SyncCommitteePoseidon *big.Int
Accumulator [12]*big.Int
}

type RotateData struct {
RotateProof []byte
RotateInput RotateInput
StepProof []byte
StepInput SyncStepInput
}
Expand Down
3 changes: 0 additions & 3 deletions chains/evm/message/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package message

import (
"math/big"

"github.com/rs/zerolog/log"
"github.com/sygmaprotocol/sygma-core/relayer/message"
"github.com/sygmaprotocol/sygma-core/relayer/proposal"
Expand All @@ -22,7 +20,6 @@ type SyncStepInput struct {
Participation uint64
FinalizedHeaderRoot [32]byte
ExecutionPayloadRoot [32]byte
Accumulator [12]*big.Int
}

type StepData struct {
Expand Down
33 changes: 6 additions & 27 deletions chains/evm/prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package prover
import (
"context"
"fmt"
"math/big"

"github.com/attestantio/go-eth2-client/api"
"github.com/attestantio/go-eth2-client/spec/phase0"
Expand All @@ -31,9 +30,8 @@ type RotateArgs struct {
}

type ProverResponse struct {
Accumulator [12]string `json:"accumulator"`
Proof []uint16 `json:"proof"`
Commitment string `json:"committee_poseidon"`
Proof []uint16 `json:"proof"`
Commitment string `json:"committee_poseidon"`
}

type EvmProof[T any] struct {
Expand Down Expand Up @@ -101,11 +99,6 @@ func (p *Prover) StepProof(args *StepArgs) (*EvmProof[message.SyncStepInput], er
return nil, err
}

accumulator := [12]*big.Int{}
for i, value := range resp.Accumulator {
accumulator[i], _ = new(big.Int).SetString(value[2:], 16)
}

log.Info().Msgf("Generated step proof")

finalizedHeaderRoot, err := args.Update.FinalizedHeader.Header.HashTreeRoot()
Expand All @@ -124,19 +117,14 @@ func (p *Prover) StepProof(args *StepArgs) (*EvmProof[message.SyncStepInput], er
Participation: uint64(CountSetBits(args.Update.SyncAggregate.SyncCommiteeBits)),
FinalizedHeaderRoot: finalizedHeaderRoot,
ExecutionPayloadRoot: executionRoot,
Accumulator: accumulator,
},
}
return proof, nil
}

// RotateProof generates the proof for the sync committee rotation for the period
func (p *Prover) RotateProof(args *RotateArgs) (*EvmProof[message.RotateInput], error) {
func (p *Prover) RotateProof(args *RotateArgs) (*EvmProof[struct{}], error) {
args.Update.AttestedHeader = args.Update.FinalizedHeader
syncCommiteeRoot, err := p.pubkeysRoot(args.Update.NextSyncCommittee.PubKeys)
if err != nil {
return nil, err
}
updateSzz, err := args.Update.MarshalSSZ()
if err != nil {
return nil, err
Expand All @@ -147,26 +135,17 @@ func (p *Prover) RotateProof(args *RotateArgs) (*EvmProof[message.RotateInput],
Spec Spec `json:"spec"`
}
var resp ProverResponse

err = p.proverClient.CallFor(context.Background(), &resp, "genEvmProof_CommitteeUpdateCompressed", rotateArgs{Update: ByteArrayToU16Array(updateSzz), Spec: args.Spec})
if err != nil {
return nil, err
}

log.Info().Msgf("Generated rotate proof")

comm, _ := new(big.Int).SetString(resp.Commitment[2:], 16)
accumulator := [12]*big.Int{}
for i, value := range resp.Accumulator {
accumulator[i], _ = new(big.Int).SetString(value[2:], 16)
}

proof := &EvmProof[message.RotateInput]{
proof := &EvmProof[struct{}]{
Proof: U16ArrayToByteArray(resp.Proof),
Input: message.RotateInput{
SyncCommitteeSSZ: syncCommiteeRoot,
SyncCommitteePoseidon: comm,
Accumulator: accumulator,
},
Input: struct{}{},
}
return proof, nil
}
Expand Down

0 comments on commit ce79ee3

Please sign in to comment.