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

Submit message with execution proof #1158

Merged
merged 7 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
16 changes: 3 additions & 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,11 @@ 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,
BlockHash: types.NewH256(event.BlockHash.Bytes()),
TxIndex: types.NewU32(uint32(event.TxIndex)),
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
28 changes: 17 additions & 11 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,10 @@ type Message struct {
}

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

type ProofData struct {
Expand All @@ -36,7 +39,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 +49,10 @@ type EventLogJSON struct {
}

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

type ProofDataJSON struct {
Expand Down Expand Up @@ -85,10 +89,11 @@ func (m Message) ToJSON() MessageJSON {
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 @@ -106,7 +111,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