From b77fa9d15e4492e2a18da5c54489825e01fc7854 Mon Sep 17 00:00:00 2001 From: Kang Seokhun Date: Wed, 17 Jul 2024 17:11:28 +0900 Subject: [PATCH 1/5] feature: libplanet merkle trie validate proof --- core/vm/contracts.go | 51 ++++++-- core/vm/contracts_test.go | 5 +- core/vm/libplanet/merkle_trie_node.go | 105 ++++++++++++++++ core/vm/libplanet/merkle_trie_proof.go | 68 ++++++++++ core/vm/libplanet/merkle_trie_proof_utils.go | 117 ++++++++++++++++++ .../precompiles/libplanetVerifyProof.json | 9 ++ go.mod | 9 +- go.sum | 13 +- 8 files changed, 355 insertions(+), 22 deletions(-) create mode 100644 core/vm/libplanet/merkle_trie_node.go create mode 100644 core/vm/libplanet/merkle_trie_proof.go create mode 100644 core/vm/libplanet/merkle_trie_proof_utils.go create mode 100644 core/vm/testdata/precompiles/libplanetVerifyProof.json diff --git a/core/vm/contracts.go b/core/vm/contracts.go index cd819f9e7b..84400ba720 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -25,6 +25,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" + "github.com/ethereum/go-ethereum/core/vm/libplanet" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto/blake2b" "github.com/ethereum/go-ethereum/crypto/bls12381" @@ -82,15 +83,16 @@ var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{ // PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum // contracts used in the Berlin release. var PrecompiledContractsBerlin = map[common.Address]PrecompiledContract{ - common.BytesToAddress([]byte{1}): &ecrecover{}, - common.BytesToAddress([]byte{2}): &sha256hash{}, - common.BytesToAddress([]byte{3}): &ripemd160hash{}, - common.BytesToAddress([]byte{4}): &dataCopy{}, - common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true}, - common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, - common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, - common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, - common.BytesToAddress([]byte{9}): &blake2F{}, + common.BytesToAddress([]byte{1}): &ecrecover{}, + common.BytesToAddress([]byte{2}): &sha256hash{}, + common.BytesToAddress([]byte{3}): &ripemd160hash{}, + common.BytesToAddress([]byte{4}): &dataCopy{}, + common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true}, + common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, + common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, + common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, + common.BytesToAddress([]byte{9}): &blake2F{}, + common.BytesToAddress([]byte{0x02, 0x00}): &libplanetVerifyProof{}, } // PrecompiledContractsCancun contains the default set of pre-compiled Ethereum @@ -201,6 +203,37 @@ func RunPrecompiledContract(p PrecompiledContract, input []byte, suppliedGas uin return output, suppliedGas, err } +type libplanetVerifyProof struct{} + +func (c *libplanetVerifyProof) RequiredGas(input []byte) uint64 { + return uint64(3000) +} + +func (c *libplanetVerifyProof) Run(input []byte) ([]byte, error) { + proofMap := map[string]any{ + "stateRootHash": nil, // sha256(bencoded) []byte + "proof": nil, // bencoded list [][]byte + "key": nil, // keyBytes []byte + "value": nil, // bencoded []byte + } + proofMap, err := libplanet.ParseMerkleTrieProofInput(input) + if err != nil { + return nil, err + } + + stateRootHash := proofMap["stateRootHash"].([]byte) + proof := proofMap["proof"].([][]byte) + key := proofMap["key"].([]byte) + value := proofMap["value"].([]byte) + + valid, err := libplanet.ValidateProof(stateRootHash, proof, key, value) + if err != nil { + return nil, err + } + + return common.CopyBytes(libplanet.BoolAbi(valid)), nil +} + // ECRECOVER implemented as a native contract. type ecrecover struct{} diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index 38781545e1..20d1b3adf1 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -60,6 +60,8 @@ var allPrecompiles = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{}, + common.BytesToAddress([]byte{0x02, 0x00}): &libplanetVerifyProof{}, + common.BytesToAddress([]byte{0x0f, 0x0a}): &bls12381G1Add{}, common.BytesToAddress([]byte{0x0f, 0x0b}): &bls12381G1Mul{}, common.BytesToAddress([]byte{0x0f, 0x0c}): &bls12381G1MultiExp{}, @@ -408,4 +410,5 @@ func BenchmarkPrecompiledP256Verify(bench *testing.B) { benchmarkPrecompiled("100", t, bench) } -func TestPrecompiledP256Verify(t *testing.T) { testJson("p256Verify", "100", t) } +func TestPrecompiledP256Verify(t *testing.T) { testJson("p256Verify", "100", t) } +func TestPrecompiledLibplanetVerifyProof(t *testing.T) { testJson("libplanetVerifyProof", "200", t) } diff --git a/core/vm/libplanet/merkle_trie_node.go b/core/vm/libplanet/merkle_trie_node.go new file mode 100644 index 0000000000..aa9a2e00d5 --- /dev/null +++ b/core/vm/libplanet/merkle_trie_node.go @@ -0,0 +1,105 @@ +package libplanet + +import ( + "fmt" + + "github.com/sircoon4/bencodex-go" +) + +type node interface { + name() string +} + +type ( + fullNode struct { + Children [17]node + } + shortNode struct { + Key []byte + Value node + } + hashNode []byte // sha256(bencoded) + valueNode []byte // bencoded +) + +func (n *fullNode) name() string { + return "fullNode" +} +func (n *shortNode) name() string { + return "shortNode" +} +func (n hashNode) name() string { + return "hashNode" +} +func (n valueNode) name() string { + return "valueNode" +} + +func (n *fullNode) GetValue() node { + return n.Children[16] +} +func (n *shortNode) GetValue() node { + return n.Value +} +func (n hashNode) GetValue() []byte { + return n +} +func (n valueNode) GetValue() []byte { + return n +} + +func nodeFromProof(proof []byte) (node, error) { + data, err := bencodex.Decode(proof) + if err != nil { + return nil, err + } + + return nodeFromData(data) +} + +func nodeFromData(data any) (node, error) { + if data == nil { + return nil, nil + } + + switch data := data.(type) { + case []byte: + return hashNode(data), nil + case []interface{}: + list := data + if len(list) == 2 { + if list[0] == nil { + value, err := bencodex.Encode(list[1]) + if err != nil { + return nil, err + } + return valueNode(value), nil + } else { + value, err := nodeFromData(list[1]) + if err != nil { + return nil, err + } + return &shortNode{ + Key: list[0].([]byte), + Value: value, + }, nil + } + } else if len(list) == 17 { + children := [17]node{} + for i, child := range list { + var err error + children[i], err = nodeFromData(child) + if err != nil { + return nil, err + } + } + return &fullNode{ + Children: children, + }, nil + } + default: + return nil, fmt.Errorf("invalid node") + } + + return nil, fmt.Errorf("invalid node") +} diff --git a/core/vm/libplanet/merkle_trie_proof.go b/core/vm/libplanet/merkle_trie_proof.go new file mode 100644 index 0000000000..87bc9d2a48 --- /dev/null +++ b/core/vm/libplanet/merkle_trie_proof.go @@ -0,0 +1,68 @@ +package libplanet + +import ( + "bytes" + "fmt" +) + +func ValidateProof( + stateRootHash []byte, // []byte + proof [][]byte, // bencoded list + key []byte, // []byte + value []byte, // bencoded +) (bool, error) { + targetHash := stateRootHash + nibbles := keybytesToNibbles(key) + + for i, bencodedProofNode := range proof { + proofNode, err := nodeFromProof(bencodedProofNode) + if err != nil { + return false, err + } + + first := i == 0 + last := i == len(proof)-1 + + if _, ok := proofNode.(hashNode); ok { + return false, fmt.Errorf("proof node cannot be a hash node") + } + + if err := checkProofNodeHash(targetHash, bencodedProofNode, first); err != nil { + return false, err + } + + nextNode, nextNibbles, err := resolveToNextCandidateNode(proofNode, nibbles) + if err != nil { + return false, err + } + + switch nextNode := nextNode.(type) { + case hashNode: + if !last { + nibbles = nextNibbles + targetHash = nextNode.GetValue() + continue + } else { + return false, fmt.Errorf("hash node cannot be the last node") + } + case valueNode: + if last { + if len(nextNibbles) != 0 { + return false, fmt.Errorf("nibbles not exhausted") + } + + if bytes.Equal(nextNode.GetValue(), value) { + return true, nil + } else { + return false, fmt.Errorf("value mismatch") + } + } else { + return false, fmt.Errorf("value node must be the last node") + } + default: + return false, fmt.Errorf("invalid node") + } + } + + return false, fmt.Errorf("proof exhausted") +} diff --git a/core/vm/libplanet/merkle_trie_proof_utils.go b/core/vm/libplanet/merkle_trie_proof_utils.go new file mode 100644 index 0000000000..825a41f43a --- /dev/null +++ b/core/vm/libplanet/merkle_trie_proof_utils.go @@ -0,0 +1,117 @@ +package libplanet + +import ( + "bytes" + "crypto/sha256" + "fmt" + + "github.com/ethereum/go-ethereum/accounts/abi" +) + +func ParseMerkleTrieProofInput(input []byte) (map[string]any, error) { + Bytes, _ := abi.NewType("bytes", "", nil) + BytesArr, _ := abi.NewType("bytes[]", "", nil) + + var arguments = abi.Arguments{ + abi.Argument{Name: "stateRootHash", Type: Bytes, Indexed: false}, + abi.Argument{Name: "proof", Type: BytesArr, Indexed: false}, + abi.Argument{Name: "key", Type: Bytes, Indexed: false}, + abi.Argument{Name: "value", Type: Bytes, Indexed: false}, + } + + decoded := map[string]any{ + "stateRootHash": nil, + "proof": nil, + "key": nil, + "value": nil, + } + err := arguments.UnpackIntoMap(decoded, input) + if err != nil { + return nil, err + } + + return decoded, nil +} + +func BoolAbi(input bool) []byte { + + Bool, _ := abi.NewType("bool", "", nil) + + var arguments = abi.Arguments{ + abi.Argument{Name: "proofResult", Type: Bool, Indexed: false}, + } + + encoded, err := arguments.Pack(input) + if err != nil { + panic(err) + } + return encoded +} + +func keybytesToNibbles(str []byte) []byte { + l := len(str) * 2 + var nibbles = make([]byte, l) + for i, b := range str { + nibbles[i*2] = b / 16 + nibbles[i*2+1] = b % 16 + } + return nibbles +} + +func checkProofNodeHash( + targetHash []byte, // sha256(bencoded) + bencodedProofNode []byte, // bencoded + first bool, +) error { + if !first && len(bencodedProofNode) <= sha256.Size { + return fmt.Errorf("proof node must be longer than hash size") + } + + proofNodeHash := sha256.Sum256(bencodedProofNode) + if !bytes.Equal(proofNodeHash[:], targetHash) { + return fmt.Errorf("proof node hash does not match target hash") + } + + return nil +} + +func resolveToNextCandidateNode( + proofNode node, + nibbles []byte, +) (node, []byte, error) { + switch proofNode := proofNode.(type) { + case hashNode: + hash := proofNode + return hash, nibbles, nil + case valueNode: + value := proofNode + return value, nibbles, nil + case *shortNode: + short := proofNode + if len(nibbles) < len(short.Key) { + return nil, nil, fmt.Errorf("nibbles exhausted") + } + + if bytes.Equal(short.Key, nibbles[:len(short.Key)]) { + return resolveToNextCandidateNode(short.Value, nibbles[len(short.Key):]) + } else { + return nil, nil, fmt.Errorf("key mismatch") + } + case *fullNode: + full := proofNode + if len(nibbles) == 0 { + if full.GetValue() != nil { + return full.GetValue(), nil, nil + } else { + return nil, nil, fmt.Errorf("nibbles exhausted") + } + } + child := full.Children[int(nibbles[0])] + if child == nil { + return nil, nil, fmt.Errorf("child not found") + } + return resolveToNextCandidateNode(child, nibbles[1:]) + } + + return nil, nil, fmt.Errorf("invalid proof node") +} diff --git a/core/vm/testdata/precompiles/libplanetVerifyProof.json b/core/vm/testdata/precompiles/libplanetVerifyProof.json new file mode 100644 index 0000000000..71e1587c26 --- /dev/null +++ b/core/vm/testdata/precompiles/libplanetVerifyProof.json @@ -0,0 +1,9 @@ +[ + { + "Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000575323a3030000000000000000000000000000000000000000000000000000000", + "Expected": "0000000000000000000000000000000000000000000000000000000000000001", + "Name": "sample00", + "Gas": 3000, + "NoBenchmark": false + } +] \ No newline at end of file diff --git a/go.mod b/go.mod index 706b6dd393..6707e6cbf0 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/ethereum/go-ethereum -go 1.21 - -toolchain go1.21.6 +go 1.22.4 require ( github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0 @@ -59,8 +57,9 @@ require ( github.com/protolambda/bls12-381-util v0.0.0-20220416220906-d8552aa452c7 github.com/rs/cors v1.7.0 github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible + github.com/sircoon4/bencodex-go v0.1.1 github.com/status-im/keycard-go v0.2.0 - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/supranational/blst v0.3.11 github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tyler-smith/go-bip39 v1.1.0 @@ -138,7 +137,7 @@ require ( github.com/rivo/uniseg v0.2.0 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/stretchr/objx v0.5.0 // indirect + github.com/stretchr/objx v0.5.2 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect diff --git a/go.sum b/go.sum index 2fd2c4d30d..627a2c0ebc 100644 --- a/go.sum +++ b/go.sum @@ -563,6 +563,8 @@ github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNX github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sircoon4/bencodex-go v0.1.1 h1:jyEhpnp666YXcLX6mfUYJvmkn8McgzTQtSyXeiqgG1o= +github.com/sircoon4/bencodex-go v0.1.1/go.mod h1:ww6XR0kFWZ9IEW6x3/e2s3NxozC+Rrr5nvkGxl0irlg= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= @@ -578,18 +580,15 @@ github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobt github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= From 6c63b148fc236b5eab2f990c7558454da606c571 Mon Sep 17 00:00:00 2001 From: Kang Seokhun Date: Thu, 18 Jul 2024 08:26:56 +0900 Subject: [PATCH 2/5] test: add test cases --- core/vm/contracts.go | 5 +-- .../precompiles/libplanetVerifyProof.json | 45 ++++++++++++++++++- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 84400ba720..4a178d8aa2 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -226,10 +226,7 @@ func (c *libplanetVerifyProof) Run(input []byte) ([]byte, error) { key := proofMap["key"].([]byte) value := proofMap["value"].([]byte) - valid, err := libplanet.ValidateProof(stateRootHash, proof, key, value) - if err != nil { - return nil, err - } + valid, _ := libplanet.ValidateProof(stateRootHash, proof, key, value) return common.CopyBytes(libplanet.BoolAbi(valid)), nil } diff --git a/core/vm/testdata/precompiles/libplanetVerifyProof.json b/core/vm/testdata/precompiles/libplanetVerifyProof.json index 71e1587c26..f6568a0a45 100644 --- a/core/vm/testdata/precompiles/libplanetVerifyProof.json +++ b/core/vm/testdata/precompiles/libplanetVerifyProof.json @@ -3,7 +3,48 @@ "Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000575323a3030000000000000000000000000000000000000000000000000000000", "Expected": "0000000000000000000000000000000000000000000000000000000000000001", "Name": "sample00", - "Gas": 3000, - "NoBenchmark": false + "Gas": 3000 + }, + { + "Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e650000000000000000000000000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000575323a3031000000000000000000000000000000000000000000000000000000", + "Expected": "0000000000000000000000000000000000000000000000000000000000000001", + "Name": "sample01", + "Gas": 3000 + }, + { + "Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000775343a3030303000000000000000000000000000000000000000000000000000", + "Expected": "0000000000000000000000000000000000000000000000000000000000000001", + "Name": "sample0000", + "Gas": 3000 + }, + { + "Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000003c00000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c20000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000286c313a0033323ab16b9db1bce3fedf7dd114b02938f2476c21936a3f30fffecc8db14d377d3dd96500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000276c6e7533323a303030303030303030303030303030303030303030303030303030303030313065000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000247533323a303030303030303030303030303030303030303030303030303030303030313000000000000000000000000000000000000000000000000000000000", + "Expected": "0000000000000000000000000000000000000000000000000000000000000001", + "Name": "sample0010", + "Gas": 3000 + }, + { + "Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000000206cc5c2ca1b7b146268f0d930c58c7e5441b807e72cf16d56f52c869a594b17bf0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000575323a3030000000000000000000000000000000000000000000000000000000", + "Expected": "0000000000000000000000000000000000000000000000000000000000000000", + "Name": "sampleFalseHash", + "Gas": 3000 + }, + { + "Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000575323a3031000000000000000000000000000000000000000000000000000000", + "Expected": "0000000000000000000000000000000000000000000000000000000000000000", + "Name": "sampleFalseValue", + "Gas": 3000 + }, + { + "Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000575323a3030000000000000000000000000000000000000000000000000000000", + "Expected": "0000000000000000000000000000000000000000000000000000000000000000", + "Name": "sampleFalseKey", + "Gas": 3000 + }, + { + "Input": "000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000020979a00921d42d2ca63e98c1c2ac07f0eacbb99e363b8f2f7f8e4d19c854b6c200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000286c313a0033323a84cac50effba60ce08415ff3356839fa032a91658a7740d60ffba4af6245a0c565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c6c33323ab7ba99008cd22b95a8fce03c7d2d72ca2352732ad0a849b91653b12ab07cce4c6c6e75323a3031656e6e6e6e6e6e6e6e6e6e6e6e6e6e6e6500000000000000000000000000000000000000000000000000000000000000000000004a6c6c313a006c6e75343a30303030656533323a3edb1a2151507f2c3853e1b3a8039ec5768b22e71c268f49d12addbb6806b3f16e6e6e6e6e6e6e6e6e6e6e6e6e6e6c6e75323a303065650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000575323a3031000000000000000000000000000000000000000000000000000000", + "Expected": "0000000000000000000000000000000000000000000000000000000000000000", + "Name": "sampleFalseProof", + "Gas": 3000 } ] \ No newline at end of file From 1f233c22f265eaabda8f7a69835fdd2a5d6479fb Mon Sep 17 00:00:00 2001 From: Kang Seokhun Date: Thu, 18 Jul 2024 13:41:36 +0900 Subject: [PATCH 3/5] fix: bencodex-go empty list encoding bug --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 6707e6cbf0..0785f46e91 100644 --- a/go.mod +++ b/go.mod @@ -57,7 +57,7 @@ require ( github.com/protolambda/bls12-381-util v0.0.0-20220416220906-d8552aa452c7 github.com/rs/cors v1.7.0 github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible - github.com/sircoon4/bencodex-go v0.1.1 + github.com/sircoon4/bencodex-go v0.1.2 github.com/status-im/keycard-go v0.2.0 github.com/stretchr/testify v1.9.0 github.com/supranational/blst v0.3.11 diff --git a/go.sum b/go.sum index 627a2c0ebc..73e5d8b5a3 100644 --- a/go.sum +++ b/go.sum @@ -563,8 +563,8 @@ github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNX github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/sircoon4/bencodex-go v0.1.1 h1:jyEhpnp666YXcLX6mfUYJvmkn8McgzTQtSyXeiqgG1o= -github.com/sircoon4/bencodex-go v0.1.1/go.mod h1:ww6XR0kFWZ9IEW6x3/e2s3NxozC+Rrr5nvkGxl0irlg= +github.com/sircoon4/bencodex-go v0.1.2 h1:ss2gVpo2HUhESmmbQgYtDmmkHvuaocKgD1Zj/n/1IYc= +github.com/sircoon4/bencodex-go v0.1.2/go.mod h1:ww6XR0kFWZ9IEW6x3/e2s3NxozC+Rrr5nvkGxl0irlg= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= From 4a64d623a0f5e30be372f692472afff23d434d45 Mon Sep 17 00:00:00 2001 From: Kang Seokhun Date: Thu, 18 Jul 2024 14:37:23 +0900 Subject: [PATCH 4/5] fix: move precompiled contract from berlin to fjord --- core/vm/contracts.go | 20 ++++++++++---------- go.mod | 10 ++++++---- go.sum | 15 +++++++++------ 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 4a178d8aa2..da2487381f 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -83,16 +83,15 @@ var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{ // PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum // contracts used in the Berlin release. var PrecompiledContractsBerlin = map[common.Address]PrecompiledContract{ - common.BytesToAddress([]byte{1}): &ecrecover{}, - common.BytesToAddress([]byte{2}): &sha256hash{}, - common.BytesToAddress([]byte{3}): &ripemd160hash{}, - common.BytesToAddress([]byte{4}): &dataCopy{}, - common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true}, - common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, - common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, - common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, - common.BytesToAddress([]byte{9}): &blake2F{}, - common.BytesToAddress([]byte{0x02, 0x00}): &libplanetVerifyProof{}, + common.BytesToAddress([]byte{1}): &ecrecover{}, + common.BytesToAddress([]byte{2}): &sha256hash{}, + common.BytesToAddress([]byte{3}): &ripemd160hash{}, + common.BytesToAddress([]byte{4}): &dataCopy{}, + common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true}, + common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, + common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, + common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, + common.BytesToAddress([]byte{9}): &blake2F{}, } // PrecompiledContractsCancun contains the default set of pre-compiled Ethereum @@ -124,6 +123,7 @@ var PrecompiledContractsFjord = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{9}): &blake2F{}, common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{}, common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{}, + common.BytesToAddress([]byte{0x02, 0x00}): &libplanetVerifyProof{}, } // PrecompiledContractsBLS contains the set of pre-compiled Ethereum diff --git a/go.mod b/go.mod index 0785f46e91..9635eafe64 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/ethereum/go-ethereum -go 1.22.4 +go 1.21 + +toolchain go1.21.6 require ( github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0 @@ -57,9 +59,9 @@ require ( github.com/protolambda/bls12-381-util v0.0.0-20220416220906-d8552aa452c7 github.com/rs/cors v1.7.0 github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible - github.com/sircoon4/bencodex-go v0.1.2 + github.com/sircoon4/bencodex-go v0.1.6 github.com/status-im/keycard-go v0.2.0 - github.com/stretchr/testify v1.9.0 + github.com/stretchr/testify v1.8.4 github.com/supranational/blst v0.3.11 github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tyler-smith/go-bip39 v1.1.0 @@ -137,7 +139,7 @@ require ( github.com/rivo/uniseg v0.2.0 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/stretchr/objx v0.5.2 // indirect + github.com/stretchr/objx v0.5.0 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect diff --git a/go.sum b/go.sum index 73e5d8b5a3..9ebda8ec18 100644 --- a/go.sum +++ b/go.sum @@ -563,8 +563,8 @@ github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNX github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/sircoon4/bencodex-go v0.1.2 h1:ss2gVpo2HUhESmmbQgYtDmmkHvuaocKgD1Zj/n/1IYc= -github.com/sircoon4/bencodex-go v0.1.2/go.mod h1:ww6XR0kFWZ9IEW6x3/e2s3NxozC+Rrr5nvkGxl0irlg= +github.com/sircoon4/bencodex-go v0.1.6 h1:VdurGt5ZlDcN5WA9e4jfkLdy5XyzJCoE/vwlq0YJeyY= +github.com/sircoon4/bencodex-go v0.1.6/go.mod h1:w0nk0aVNbOpfNQpo4ogLdyCasC3lmYKg4m+ujyNfNg0= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= @@ -580,15 +580,18 @@ github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobt github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= From c54681512062b12b2f8b8de01d97f283aac01e5d Mon Sep 17 00:00:00 2001 From: Kang Seokhun Date: Thu, 18 Jul 2024 15:49:32 +0900 Subject: [PATCH 5/5] refactor: move location of libplanet library --- core/vm/contracts.go | 60 ++++++++++--------- .../merkle_trie_node.go | 0 .../merkle_trie_proof.go | 0 .../merkle_trie_proof_utils.go | 0 params/protocol_params.go | 3 +- 5 files changed, 33 insertions(+), 30 deletions(-) rename {core/vm/libplanet => libplanet}/merkle_trie_node.go (100%) rename {core/vm/libplanet => libplanet}/merkle_trie_proof.go (100%) rename {core/vm/libplanet => libplanet}/merkle_trie_proof_utils.go (100%) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index da2487381f..534ebbd89f 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -25,13 +25,13 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" - "github.com/ethereum/go-ethereum/core/vm/libplanet" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto/blake2b" "github.com/ethereum/go-ethereum/crypto/bls12381" "github.com/ethereum/go-ethereum/crypto/bn256" "github.com/ethereum/go-ethereum/crypto/kzg4844" "github.com/ethereum/go-ethereum/crypto/secp256r1" + "github.com/ethereum/go-ethereum/libplanet" "github.com/ethereum/go-ethereum/params" "golang.org/x/crypto/ripemd160" ) @@ -203,34 +203,6 @@ func RunPrecompiledContract(p PrecompiledContract, input []byte, suppliedGas uin return output, suppliedGas, err } -type libplanetVerifyProof struct{} - -func (c *libplanetVerifyProof) RequiredGas(input []byte) uint64 { - return uint64(3000) -} - -func (c *libplanetVerifyProof) Run(input []byte) ([]byte, error) { - proofMap := map[string]any{ - "stateRootHash": nil, // sha256(bencoded) []byte - "proof": nil, // bencoded list [][]byte - "key": nil, // keyBytes []byte - "value": nil, // bencoded []byte - } - proofMap, err := libplanet.ParseMerkleTrieProofInput(input) - if err != nil { - return nil, err - } - - stateRootHash := proofMap["stateRootHash"].([]byte) - proof := proofMap["proof"].([][]byte) - key := proofMap["key"].([]byte) - value := proofMap["value"].([]byte) - - valid, _ := libplanet.ValidateProof(stateRootHash, proof, key, value) - - return common.CopyBytes(libplanet.BoolAbi(valid)), nil -} - // ECRECOVER implemented as a native contract. type ecrecover struct{} @@ -1221,3 +1193,33 @@ func (c *p256Verify) Run(input []byte) ([]byte, error) { return nil, nil } } + +// LibplanetVerifyProof implemented for verifying merkle trie proof +// from blockchain networks built by Libplanet. +type libplanetVerifyProof struct{} + +func (c *libplanetVerifyProof) RequiredGas(input []byte) uint64 { + return params.LibplanetVerifyProofGas +} + +func (c *libplanetVerifyProof) Run(input []byte) ([]byte, error) { + proofMap := map[string]any{ + "stateRootHash": nil, // sha256(bencoded) []byte + "proof": nil, // bencoded list [][]byte + "key": nil, // keyBytes []byte + "value": nil, // bencoded []byte + } + proofMap, err := libplanet.ParseMerkleTrieProofInput(input) + if err != nil { + return nil, err + } + + stateRootHash := proofMap["stateRootHash"].([]byte) + proof := proofMap["proof"].([][]byte) + key := proofMap["key"].([]byte) + value := proofMap["value"].([]byte) + + valid, _ := libplanet.ValidateProof(stateRootHash, proof, key, value) + + return common.CopyBytes(libplanet.BoolAbi(valid)), nil +} diff --git a/core/vm/libplanet/merkle_trie_node.go b/libplanet/merkle_trie_node.go similarity index 100% rename from core/vm/libplanet/merkle_trie_node.go rename to libplanet/merkle_trie_node.go diff --git a/core/vm/libplanet/merkle_trie_proof.go b/libplanet/merkle_trie_proof.go similarity index 100% rename from core/vm/libplanet/merkle_trie_proof.go rename to libplanet/merkle_trie_proof.go diff --git a/core/vm/libplanet/merkle_trie_proof_utils.go b/libplanet/merkle_trie_proof_utils.go similarity index 100% rename from core/vm/libplanet/merkle_trie_proof_utils.go rename to libplanet/merkle_trie_proof_utils.go diff --git a/params/protocol_params.go b/params/protocol_params.go index 5e2a0632af..3c14f50d8f 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -166,7 +166,8 @@ const ( Bls12381MapG1Gas uint64 = 5500 // Gas price for BLS12-381 mapping field element to G1 operation Bls12381MapG2Gas uint64 = 110000 // Gas price for BLS12-381 mapping field element to G2 operation - P256VerifyGas uint64 = 3450 // secp256r1 elliptic curve signature verifier gas price + P256VerifyGas uint64 = 3450 // secp256r1 elliptic curve signature verifier gas price + LibplanetVerifyProofGas uint64 = 3000 // Libplanet proof verifier gas price // The Refund Quotient is the cap on how much of the used gas can be refunded. Before EIP-3529, // up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529