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 all 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
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