Skip to content

Commit 83a9bb6

Browse files
feat: maybe add proof node (#37)
1 parent ab1d4c1 commit 83a9bb6

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

core/processor.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/ethereum/go-ethereum/common/hexutil"
88
"github.com/ethereum/go-ethereum/rlp"
99
"github.com/status-im/keycard-go/hexutils"
10+
"golang.org/x/crypto/sha3"
1011
"math/big"
1112
"strings"
1213
"time"
@@ -143,8 +144,11 @@ func (b *Processor) ProveWithdrawalTransaction(ctx context.Context, wi *Withdraw
143144
}
144145

145146
withdrawalProof := accountResult.StorageProof[0]
147+
148+
key := Keccak256(common.FromHex("0x" + messageSlot))
149+
maybeModifiedProof := MaybeAddProofNode(key, withdrawalProof.Proof)
146150
withdrawalProof2Bytes := make([][]byte, 0)
147-
for _, p1 := range withdrawalProof.Proof {
151+
for _, p1 := range maybeModifiedProof {
148152
withdrawalProof2Bytes = append(withdrawalProof2Bytes, p1)
149153
}
150154

@@ -697,3 +701,9 @@ func MaybeAddProofNode(key []byte, proof []hexutil.Bytes) []hexutil.Bytes {
697701

698702
return proof
699703
}
704+
705+
func Keccak256(data []byte) []byte {
706+
hash := sha3.NewLegacyKeccak256()
707+
hash.Write(data)
708+
return hash.Sum(nil)
709+
}

core/processor_test.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package core_test
33
import (
44
"bnbchain/opbnb-bridge-bot/core"
55
"github.com/ethereum/go-ethereum/common/hexutil"
6-
"golang.org/x/crypto/sha3"
76
"testing"
87

98
"github.com/ethereum/go-ethereum/common"
@@ -13,7 +12,7 @@ import (
1312
// copy from https://github.com/ethereum-optimism/optimism/blob/d11e89d0bc3ecf993a4c6680ccb59c2959e54bd1/packages/sdk/test/utils/merkle-utils.spec.ts#L9
1413
func TestMaybeAddProofNode_ShouldAddAProofNodeWhenFinalNodeIsInsideOfABranch(t *testing.T) {
1514
slot := "0x5cd60ecef836e75dd12539abe8ad5f4ba0dc4fcaae2c45024c69bd9e20746eba"
16-
key := keccak256(common.FromHex(slot))
15+
key := core.Keccak256(common.FromHex(slot))
1716

1817
proof := []hexutil.Bytes{
1918
common.FromHex("0xf90211a0feb6c6afca5ea568e0b7183d7292c112e9d28a1c846d889636d5c8822463aa77a0df719a24d8049d04a47e0e07ba493110fed0665d897c0ffdb05a7ce474782026a01bec363c069dc337ce16b4ca5cffa11d20e305fd7dcf6d87547b151c31aabf0ca00583d5a451bfa01f5e51d992e129ee17e65adda9495bda77898187484625aa9ea0bd9fef27cd52c2721e519bcd40c63a818095374e505a3bbd88db29c6c4521982a009a31937313c5b2bc06da6fec4075110f19526a9dbde3629ebe36aa8cd8e0851a0555f89002a34f6570bab438e69c5d8b855f2664e31f5dd59b807d0956577cc81a07e6f59ec99405b7afa436bf62abd098a85b43861fd3a9da3214a5d46b2d12543a03e7e883b0406cb781e5bf2a71cafc02ebbcdb0684ac03439633faf339d1259e2a0fa154fcf0bedd25aacac74e9864e4b96742c3d06f58c170cd320ade69db16c88a07e34154a031da5e50a3886efcb15c6681deeb20832726f083f80b03678b56d33a0d24408a39fb57838fdfe85c68f7eac74daab709ec3c22dfd0a579c1dbd64861aa093c1837ab2907fc51de7e918b81b997d60a6c8a18e3538720ee0d0f369530c26a0fca1af24293865f21d18d5eb823e0ecc007306823864f11d59c1c5c370fb22c2a0de8c894b5067d637df401aa6b963a3fc52b774abbedf6688e25bbf9a29672b7ca021c85d42de67601599e605d9ed1257451d1ce403d2478496d0a99d60db643d5280"),
@@ -34,7 +33,7 @@ func TestMaybeAddProofNode_ShouldAddAProofNodeWhenFinalNodeIsInsideOfABranch(t *
3433
// copy from https://github.com/ethereum-optimism/optimism/blob/d11e89d0bc3ecf993a4c6680ccb59c2959e54bd1/packages/sdk/test/utils/merkle-utils.spec.ts#L31
3534
func TestMaybeAddProofNode_ShouldNotAddAProofNodeWhenFinalNodeIsALeafNode(t *testing.T) {
3635
slot := "0x5cd60ecef836e75dd12539abe8ad5f4ba0dc4fcaae2c45024c69bd9e20746eba"
37-
key := keccak256(common.FromHex(slot))
36+
key := core.Keccak256(common.FromHex(slot))
3837

3938
proof := []hexutil.Bytes{
4039
common.FromHex("0xf90211a08c7918779c1c4435737b269573de96df28e1ec8c5847d7317906971b4c5fa73fa018679d112e60f815616a167692ea7d821691f34bed06df12c7b121a4c7b8384ba06b0a09649c9e7df1bde1c7448243c954dfecae8301b7f6bbe7d8f0b781733194a0258988e63a01754eafaffa3837ccc321c4f99d50869d04c09e7ab587988ecfa6a0a5b325ae646fd16ad7daac9d6da2ea244d456fa1a219f828cb9a5785f01bbf4ea0532b1427977ae09ee5344667910500207fd500912f9e1c6f5e7aa6b8b333a717a04a32b16d0d56f217216a9dae9eea953883ff3bcf1a9578d60d6bb28bbf4b6655a009e8cabb94c504eeb5cf15a151ed4b99be678bf969ee30be5d8aaf1312210079a0938dedf6ad32b04a9a2da09f29e481c51d7cf440d62651ed570355e12a4858d8a0b6bae212efc7179842abc76e9d6b2850b05336720b81dac467e942f7f6cd6b9ba0be45a8205c8c75ebe83c10cc9e87a597820d7e3ca691f9d1549e12a6f050a296a0c65bd95874adb4054ae8b346f2d2ccc88e76555c662b230d62072db36933508ca0e21442e3384b11c414e4a6bc2d56e71dbbbc672c38ac00bd63386ad55c590955a0d3d178f5be5f808d97ce22d48adce909ecf326cc5d9a0e7b64af616ca2d3e12ca09475833e7206cd83f7301f995617825f6d7050c782e17495ce5eb0556c2b68c4a09638ed778938e150e4c68cbcaf9bd47f97e1a6a6d6d2bbf9bc516450166a1ed980"),
@@ -107,9 +106,3 @@ func TestIsMinGasLimitValid(t *testing.T) {
107106
func uint32Ptr(n uint32) *uint32 {
108107
return &n
109108
}
110-
111-
func keccak256(data []byte) []byte {
112-
hash := sha3.NewLegacyKeccak256()
113-
hash.Write(data)
114-
return hash.Sum(nil)
115-
}

0 commit comments

Comments
 (0)