Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit 41425fc

Browse files
authored
fix(rpc): different result from eth_getProof comparing with Ethereum (#1431)
* align with eth_getProof for more info, see https://eips.ethereum.org/EIPS/eip-1186 * add GetHexProofs * add change doc * keep default res * fix lint * add e2e test * Apply suggestions from code review * fix lint * nix run -f ./nix gomod2nix
1 parent 708e781 commit 41425fc

File tree

7 files changed

+114
-36
lines changed

7 files changed

+114
-36
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
7777
* (cli) [#1362](https://github.com/evmos/ethermint/pull/1362) Fix `index-eth-tx` error when the indexer db is empty.
7878
* (state) [#1320](https://github.com/evmos/ethermint/pull/1320) Fix codehash check mismatch when the code has been deleted in the evm state.
7979
* (rpc) [#1392](https://github.com/evmos/ethermint/pull/1392) Allow fill the proposer address in json-rpc through tendermint api, and pass explicitly to grpc query handler.
80+
* (rpc) [#1431](https://github.com/evmos/ethermint/pull/1431) Align hex-strings proof fields in `eth_getProof` as Ethereum.
8081

8182
## [v0.19.3] - 2022-10-14
8283

gomod2nix.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ schema = 3
362362
version = "v2.4.0"
363363
hash = "sha256-Z+bch118Akc5wGkOM7ZePNqw7vW5euXE7ec4Y297HNw="
364364
[mod."github.com/onsi/gomega"]
365-
version = "v1.23.0"
366-
hash = "sha256-g5FaFLUK8ZAR9VgFTTH0ax0t45tZkYbIHbq/gANIOTM="
365+
version = "v1.24.0"
366+
hash = "sha256-pOth47IZsI9c16TKLqW8HMObd1KiqWbe0iem+ue4bTw="
367367
[mod."github.com/pelletier/go-toml"]
368368
version = "v1.9.5"
369369
hash = "sha256-RJ9K1BTId0Mled7S66iGgxHkZ5JKEIsrrNaEfM8aImc="

rpc/backend/account_info.go

+2-14
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,10 @@ func (b *Backend) GetProof(address common.Address, storageKeys []string, blockNr
7575
return nil, err
7676
}
7777

78-
// check for proof
79-
var proofStr string
80-
if proof != nil {
81-
proofStr = proof.String()
82-
}
83-
8478
storageProofs[i] = rpctypes.StorageResult{
8579
Key: key,
8680
Value: (*hexutil.Big)(new(big.Int).SetBytes(valueBz)),
87-
Proof: []string{proofStr},
81+
Proof: GetHexProofs(proof),
8882
}
8983
}
9084

@@ -105,20 +99,14 @@ func (b *Backend) GetProof(address common.Address, storageKeys []string, blockNr
10599
return nil, err
106100
}
107101

108-
// check for proof
109-
var accProofStr string
110-
if proof != nil {
111-
accProofStr = proof.String()
112-
}
113-
114102
balance, ok := sdkmath.NewIntFromString(res.Balance)
115103
if !ok {
116104
return nil, errors.New("invalid balance")
117105
}
118106

119107
return &rpctypes.AccountResult{
120108
Address: address,
121-
AccountProof: []string{accProofStr},
109+
AccountProof: GetHexProofs(proof),
122110
Balance: (*hexutil.Big)(balance.BigInt()),
123111
CodeHash: common.HexToHash(res.CodeHash),
124112
Nonce: hexutil.Uint64(res.Nonce),

rpc/backend/utils.go

+18
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/evmos/ethermint/rpc/types"
2323
evmtypes "github.com/evmos/ethermint/x/evm/types"
24+
"github.com/tendermint/tendermint/proto/tendermint/crypto"
2425
)
2526

2627
type txGasAndReward struct {
@@ -263,3 +264,20 @@ func GetLogsFromBlockResults(blockRes *tmrpctypes.ResultBlockResults) ([][]*etht
263264

264265
return blockLogs, nil
265266
}
267+
268+
// GetHexProofs returns list of hex data of proof op
269+
func GetHexProofs(proof *crypto.ProofOps) []string {
270+
if proof == nil {
271+
return []string{""}
272+
}
273+
proofs := []string{}
274+
// check for proof
275+
for _, p := range proof.Ops {
276+
proof := ""
277+
if len(p.Data) > 0 {
278+
proof = hexutil.Encode(p.Data)
279+
}
280+
proofs = append(proofs, proof)
281+
}
282+
return proofs
283+
}

rpc/backend/utils_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package backend
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/tendermint/tendermint/proto/tendermint/crypto"
7+
)
8+
9+
func mookProofs(num int, withData bool) *crypto.ProofOps {
10+
var proofOps *crypto.ProofOps
11+
if num > 0 {
12+
proofOps = new(crypto.ProofOps)
13+
for i := 0; i < num; i++ {
14+
proof := crypto.ProofOp{}
15+
if withData {
16+
proof.Data = []byte("\n\031\n\003KEY\022\005VALUE\032\013\010\001\030\001 \001*\003\000\002\002")
17+
}
18+
proofOps.Ops = append(proofOps.Ops, proof)
19+
}
20+
}
21+
return proofOps
22+
}
23+
24+
func (suite *BackendTestSuite) TestGetHexProofs() {
25+
defaultRes := []string{""}
26+
testCases := []struct {
27+
name string
28+
proof *crypto.ProofOps
29+
exp []string
30+
}{
31+
{
32+
"no proof provided",
33+
mookProofs(0, false),
34+
defaultRes,
35+
},
36+
{
37+
"no proof data provided",
38+
mookProofs(1, false),
39+
defaultRes,
40+
},
41+
{
42+
"valid proof provided",
43+
mookProofs(1, true),
44+
[]string{"0x0a190a034b4559120556414c55451a0b0801180120012a03000202"},
45+
},
46+
}
47+
for _, tc := range testCases {
48+
suite.Run(fmt.Sprintf("Case %s", tc.name), func() {
49+
suite.Require().Equal(tc.exp, GetHexProofs(tc.proof))
50+
})
51+
}
52+
}

tests/integration_tests/expected_constants.py

+10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
],
2727
}
2828

29+
EXPECTED_ACCOUNT_PROOF = [
30+
"0x0ac1030a150157f96e6b86cdefdb3d412547816a82e3e0ebf9d212e8010a1e2f65746865726d696e742e74797065732e76312e4574684163636f756e7412c5010a7f0a2a63726331326c756b75367578656868616b303270793472637a36357a753073776837776a737277307070124f0a282f65746865726d696e742e63727970746f2e76312e657468736563703235366b312e5075624b657912230a21026e710a62a342de0ed4d7c4532dcbcbbafbf19652ed67b237efab70e8b207efac200112423078633564323436303138366637323333633932376537646232646363373033633065353030623635336361383232373362376266616438303435643835613437301a0b0801180120012a03000202222b08011204020402201a2120e2a580b805b8b4d1f80793092cefe57965d9582ba8e31505a72cf31a55fa173d222b08011204040802201a21206c0bd60f0d887a5f99dd023f133dfd12412b074c0c442ab8a25b17048ff34ae022290801122506100220a66ec49c8058aef1eabb21a9610e16227d95982482db0ab5b032f823d457c2b920222b080112040a2e02201a2120af3944b847407590f1b2a95edcd1c2c5408e27a404e0b22267bcc2d46df700ed", # noqa: E501
31+
"0x0aff010a0361636312205632d1620b29d277324e7473898ac9e587a99a62022931b33ce6d0be3b19137b1a090801180120012a0100222708011201011a20f5b8da7f66d134e34242575499b1f125c07af21b36685c31f9a8999c71a21daf222708011201011a20b8ef619094b2b40ae87dd1d3413c5af70d9c43256dfea123ca835baa53ad54a4222708011201011a20b7d06a60784c017041761d99ed17a2d2d68ceb4eccf39bd9a527773f21e5b688222708011201011a20a54531b68a71accb459f478724bde077a82c9079ef2be7e0b8dc47764f1b96d2222708011201011a204f83dd3fed3f48e1dff2fe125c5d22f578b613ddb45bdc12d4bc1841232d9a8b", # noqa: E501
32+
]
33+
34+
EXPECTED_STORAGE_PROOF = [
35+
"0x12370a350257f96e6b86cdefdb3d412547816a82e3e0ebf9d20000000000000000000000000000000000000000000000000000000000000000", # noqa: E501
36+
"0x0af9010a0365766d1220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8551a090801180120012a0100222508011221010842b5561422ad68d28682baffad7f99cd8a64a339d4bd62b72916894d3d9a19222508011221010b1d3ff3c723ae07cea430234113b9d2b3b4218b7661f596b39b0592aedf9b60222508011221019975643a5ffdd52f7ef9a9cc57244008e5e7269e55587af4e4f137e5ef8ed6d3222708011201011a20a54531b68a71accb459f478724bde077a82c9079ef2be7e0b8dc47764f1b96d2222708011201011a204f83dd3fed3f48e1dff2fe125c5d22f578b613ddb45bdc12d4bc1841232d9a8b", # noqa: E501
37+
]
38+
2939
EXPECTED_GET_TRANSACTION = {
3040
"jsonrpc": "2.0",
3141
"id": 0,

tests/integration_tests/test_types.py

+29-20
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from web3 import Web3
22

33
from .expected_constants import (
4+
EXPECTED_ACCOUNT_PROOF,
45
EXPECTED_FEE_HISTORY,
56
EXPECTED_GET_PROOF,
67
EXPECTED_GET_STORAGE_AT,
78
EXPECTED_GET_TRANSACTION,
89
EXPECTED_GET_TRANSACTION_RECEIPT,
10+
EXPECTED_STORAGE_PROOF,
911
)
1012
from .utils import (
1113
ADDRS,
@@ -181,11 +183,15 @@ def test_get_storage_at(ethermint_rpc_ws, geth):
181183
assert res, err
182184

183185

184-
def send_and_get_hash(w3, tx_value=10):
186+
def send_tnx(w3, tx_value=10):
185187
# Do an ethereum transfer
186188
gas_price = w3.eth.gas_price
187189
tx = {"to": ADDRS["community"], "value": tx_value, "gasPrice": gas_price}
188-
return send_transaction(w3, tx, KEYS["validator"])["transactionHash"].hex()
190+
return send_transaction(w3, tx, KEYS["validator"])
191+
192+
193+
def send_and_get_hash(w3, tx_value=10):
194+
return send_tnx(w3, tx_value)["transactionHash"].hex()
189195

190196

191197
def test_get_proof(ethermint_rpc_ws, geth):
@@ -195,26 +201,29 @@ def test_get_proof(ethermint_rpc_ws, geth):
195201
eth_rpc = w3.provider
196202
w3_wait_for_block(w3, 3)
197203
geth_rpc = geth.w3.provider
198-
make_same_rpc_calls(
199-
eth_rpc,
200-
geth_rpc,
201-
"eth_getProof",
202-
["0x57f96e6b86cdefdb3d412547816a82e3e0ebf9d2", ["0x0"], "latest"],
203-
)
204-
205-
make_same_rpc_calls(
206-
eth_rpc,
207-
geth_rpc,
208-
"eth_getProof",
209-
["0x57f96e6b86cdefdb3d412547816a82e3e0ebf9d2", ["0x0"], "0x1024"],
210-
)
204+
validator = ADDRS["validator"]
205+
method = "eth_getProof"
206+
for quantity in ["latest", "0x1024"]:
207+
res = make_same_rpc_calls(
208+
eth_rpc,
209+
geth_rpc,
210+
method,
211+
[validator, ["0x0"], quantity],
212+
)
213+
res = send_tnx(w3)
211214

212-
_ = send_and_get_hash(w3)
215+
proof = (eth_rpc.make_request(
216+
method, [validator, ["0x0"], hex(res["blockNumber"])]
217+
))["result"]
218+
res, err = same_types(proof, EXPECTED_GET_PROOF)
219+
assert res, err
220+
assert proof["accountProof"], EXPECTED_ACCOUNT_PROOF
221+
assert proof["storageProof"][0]["proof"], EXPECTED_STORAGE_PROOF
213222

214-
proof = eth_rpc.make_request(
215-
"eth_getProof", [ADDRS["validator"], ["0x0"], "latest"]
216-
)
217-
res, err = same_types(proof["result"], EXPECTED_GET_PROOF)
223+
proof = (geth_rpc.make_request(
224+
method, [validator, ["0x0"], "latest"]
225+
))["result"]
226+
res, err = same_types(proof, EXPECTED_GET_PROOF)
218227
assert res, err
219228

220229

0 commit comments

Comments
 (0)