Skip to content

Commit

Permalink
Submit message with execution proof (Snowfork#1158)
Browse files Browse the repository at this point in the history
* Submit message with execution update

* Update beacon fixture

* Update relayer/cmd/generate_beacon_data.go

Co-authored-by: Clara van Staden <[email protected]>

* Update relayer/cmd/generate_beacon_data.go

Co-authored-by: Clara van Staden <[email protected]>

* Update relayer/relays/execution/main.go

Co-authored-by: Clara van Staden <[email protected]>

* Add separated command for inbound fixture

* Remove irrelevant fields from proof

---------

Co-authored-by: Clara van Staden <[email protected]>
  • Loading branch information
yrong and claravanstaden authored Mar 20, 2024
1 parent f893a78 commit 96aea30
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 178 deletions.
14 changes: 1 addition & 13 deletions relayer/chain/ethereum/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import (
etypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
etrie "github.com/ethereum/go-ethereum/trie"
"github.com/sirupsen/logrus"
"github.com/snowfork/go-substrate-rpc-client/v4/types"
"github.com/snowfork/snowbridge/relayer/chain/parachain"

log "github.com/sirupsen/logrus"
)

func MakeMessageFromEvent(event *etypes.Log, receiptsTrie *etrie.Trie) (*parachain.Message, error) {
Expand Down Expand Up @@ -47,18 +44,9 @@ func MakeMessageFromEvent(event *etypes.Log, receiptsTrie *etrie.Trie) (*paracha
Data: event.Data,
},
Proof: parachain.Proof{
BlockHash: types.NewH256(event.BlockHash.Bytes()),
TxIndex: types.NewU32(uint32(event.TxIndex)),
Data: proof,
ReceiptProof: proof,
},
}

log.WithFields(logrus.Fields{
"EventLog": m.EventLog,
"Proof": m.Proof,
"txHash": event.TxHash.Hex(),
"BlockNumber": event.BlockNumber,
}).Debug("Generated message from Ethereum log")

return &m, nil
}
2 changes: 1 addition & 1 deletion relayer/chain/ethereum/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestMessage_Proof(t *testing.T) {
if err != nil {
panic(err)
}
proofNodes := TestProof(*msg.Proof.Data)
proofNodes := TestProof(*msg.Proof.ReceiptProof)
provenReceipt, err := gethTrie.VerifyProof(block.ReceiptHash(), key, &proofNodes)
assert.Nil(t, err)
assert.Equal(t, provenReceipt, receipt5Encoded)
Expand Down
27 changes: 13 additions & 14 deletions relayer/chain/parachain/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

gethCommon "github.com/ethereum/go-ethereum/common"
"github.com/snowfork/go-substrate-rpc-client/v4/types"
"github.com/snowfork/snowbridge/relayer/relays/beacon/header/syncer/json"
"github.com/snowfork/snowbridge/relayer/relays/beacon/header/syncer/scale"
"github.com/snowfork/snowbridge/relayer/relays/util"
)

Expand All @@ -24,9 +26,8 @@ type Message struct {
}

type Proof struct {
BlockHash types.H256
TxIndex types.U32
Data *ProofData
ReceiptProof *ProofData
ExecutionProof scale.HeaderUpdatePayload
}

type ProofData struct {
Expand All @@ -36,7 +37,7 @@ type ProofData struct {

type MessageJSON struct {
EventLog EventLogJSON `json:"event_log"`
Proof ProofJSON
Proof ProofJSON `json:"proof"`
}

type EventLogJSON struct {
Expand All @@ -46,9 +47,8 @@ type EventLogJSON struct {
}

type ProofJSON struct {
BlockHash string `json:"block_hash"`
TxIndex uint32 `json:"tx_index"`
Data *ProofDataJSON `json:"data"`
ReceiptProof *ProofDataJSON `json:"receipt_proof"`
ExecutionProof json.HeaderUpdate `json:"execution_proof"`
}

type ProofDataJSON struct {
Expand Down Expand Up @@ -83,12 +83,11 @@ func (m Message) ToJSON() MessageJSON {
Data: m.EventLog.Data.Hex(),
},
Proof: ProofJSON{
BlockHash: m.Proof.BlockHash.Hex(),
TxIndex: uint32(m.Proof.TxIndex),
Data: &ProofDataJSON{
Keys: util.ScaleBytesToArrayHexArray(m.Proof.Data.Keys),
Values: util.ScaleBytesToArrayHexArray(m.Proof.Data.Values),
ReceiptProof: &ProofDataJSON{
Keys: util.ScaleBytesToArrayHexArray(m.Proof.ReceiptProof.Keys),
Values: util.ScaleBytesToArrayHexArray(m.Proof.ReceiptProof.Values),
},
ExecutionProof: m.Proof.ExecutionProof.ToJSON(),
},
}
}
Expand All @@ -105,8 +104,8 @@ func (e *EventLogJSON) RemoveLeadingZeroHashes() {
}

func (p *ProofJSON) RemoveLeadingZeroHashes() {
p.BlockHash = removeLeadingZeroHash(p.BlockHash)
p.Data.RemoveLeadingZeroHashes()
p.ReceiptProof.RemoveLeadingZeroHashes()
p.ExecutionProof.RemoveLeadingZeroHashes()
}

func (p *ProofDataJSON) RemoveLeadingZeroHashes() {
Expand Down
21 changes: 0 additions & 21 deletions relayer/chain/parachain/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,27 +361,6 @@ func (wr *ParachainWriter) getNumberFromParachain(pallet, storage string) (uint6
return uint64(number), nil
}

func (wr *ParachainWriter) GetCompactExecutionHeaderStateByBlockHash(blockHash types.H256) (state.CompactExecutionHeaderState, error) {
var headerState state.CompactExecutionHeaderState
key, err := types.CreateStorageKey(wr.conn.Metadata(), "EthereumBeaconClient", "ExecutionHeaders", blockHash[:], nil)
if err != nil {
return headerState, fmt.Errorf("create storage key for ExecutionHeaders: %w", err)
}

var compactExecutionHeader scale.CompactExecutionHeader
_, err = wr.conn.API().RPC.State.GetStorageLatest(key, &compactExecutionHeader)
if err != nil {
return headerState, fmt.Errorf("get storage for ExecutionHeaders (err): %w", err)
}
headerState = state.CompactExecutionHeaderState{
ParentHash: common.Hash(compactExecutionHeader.ParentHash),
BlockNumber: uint64(compactExecutionHeader.BlockNumber.Int64()),
StateRoot: common.Hash(compactExecutionHeader.StateRoot),
ReceiptsRoot: common.Hash(compactExecutionHeader.ReceiptsRoot),
}
return headerState, nil
}

func (wr *ParachainWriter) GetLastFinalizedStateIndex() (types.U32, error) {
var index types.U32
key, err := types.CreateStorageKey(wr.conn.Metadata(), "EthereumBeaconClient", "FinalizedBeaconStateIndex", nil, nil)
Expand Down
Loading

0 comments on commit 96aea30

Please sign in to comment.