Skip to content

Commit

Permalink
feat: maybe add proof node (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendanzhentan authored Mar 21, 2024
1 parent ab1d4c1 commit 83a9bb6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 11 additions & 1 deletion core/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rlp"
"github.com/status-im/keycard-go/hexutils"
"golang.org/x/crypto/sha3"
"math/big"
"strings"
"time"
Expand Down Expand Up @@ -143,8 +144,11 @@ func (b *Processor) ProveWithdrawalTransaction(ctx context.Context, wi *Withdraw
}

withdrawalProof := accountResult.StorageProof[0]

key := Keccak256(common.FromHex("0x" + messageSlot))
maybeModifiedProof := MaybeAddProofNode(key, withdrawalProof.Proof)
withdrawalProof2Bytes := make([][]byte, 0)
for _, p1 := range withdrawalProof.Proof {
for _, p1 := range maybeModifiedProof {
withdrawalProof2Bytes = append(withdrawalProof2Bytes, p1)
}

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

return proof
}

func Keccak256(data []byte) []byte {
hash := sha3.NewLegacyKeccak256()
hash.Write(data)
return hash.Sum(nil)
}
11 changes: 2 additions & 9 deletions core/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package core_test
import (
"bnbchain/opbnb-bridge-bot/core"
"github.com/ethereum/go-ethereum/common/hexutil"
"golang.org/x/crypto/sha3"
"testing"

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

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

proof := []hexutil.Bytes{
common.FromHex("0xf90211a08c7918779c1c4435737b269573de96df28e1ec8c5847d7317906971b4c5fa73fa018679d112e60f815616a167692ea7d821691f34bed06df12c7b121a4c7b8384ba06b0a09649c9e7df1bde1c7448243c954dfecae8301b7f6bbe7d8f0b781733194a0258988e63a01754eafaffa3837ccc321c4f99d50869d04c09e7ab587988ecfa6a0a5b325ae646fd16ad7daac9d6da2ea244d456fa1a219f828cb9a5785f01bbf4ea0532b1427977ae09ee5344667910500207fd500912f9e1c6f5e7aa6b8b333a717a04a32b16d0d56f217216a9dae9eea953883ff3bcf1a9578d60d6bb28bbf4b6655a009e8cabb94c504eeb5cf15a151ed4b99be678bf969ee30be5d8aaf1312210079a0938dedf6ad32b04a9a2da09f29e481c51d7cf440d62651ed570355e12a4858d8a0b6bae212efc7179842abc76e9d6b2850b05336720b81dac467e942f7f6cd6b9ba0be45a8205c8c75ebe83c10cc9e87a597820d7e3ca691f9d1549e12a6f050a296a0c65bd95874adb4054ae8b346f2d2ccc88e76555c662b230d62072db36933508ca0e21442e3384b11c414e4a6bc2d56e71dbbbc672c38ac00bd63386ad55c590955a0d3d178f5be5f808d97ce22d48adce909ecf326cc5d9a0e7b64af616ca2d3e12ca09475833e7206cd83f7301f995617825f6d7050c782e17495ce5eb0556c2b68c4a09638ed778938e150e4c68cbcaf9bd47f97e1a6a6d6d2bbf9bc516450166a1ed980"),
Expand Down Expand Up @@ -107,9 +106,3 @@ func TestIsMinGasLimitValid(t *testing.T) {
func uint32Ptr(n uint32) *uint32 {
return &n
}

func keccak256(data []byte) []byte {
hash := sha3.NewLegacyKeccak256()
hash.Write(data)
return hash.Sum(nil)
}

0 comments on commit 83a9bb6

Please sign in to comment.