Skip to content

Commit 64da037

Browse files
authored
cmd/evm: stricter transaction validation (#23694)
* cmd/evm: t9n: validate transaction intrinsic gas * cmd/evm: t9n: stricter tx validation
1 parent 8a430fb commit 64da037

File tree

6 files changed

+75
-8
lines changed

6 files changed

+75
-8
lines changed

cmd/evm/internal/t8ntool/transaction.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/ethereum/go-ethereum/common"
2828
"github.com/ethereum/go-ethereum/common/hexutil"
29+
"github.com/ethereum/go-ethereum/core"
2930
"github.com/ethereum/go-ethereum/core/types"
3031
"github.com/ethereum/go-ethereum/log"
3132
"github.com/ethereum/go-ethereum/params"
@@ -123,12 +124,22 @@ func Transaction(ctx *cli.Context) error {
123124
results = append(results, result{Error: err})
124125
continue
125126
}
126-
sender, err := types.Sender(signer, &tx)
127-
if err != nil {
128-
results = append(results, result{Error: err})
127+
r := result{Hash: tx.Hash()}
128+
if sender, err := types.Sender(signer, &tx); err != nil {
129+
r.Error = err
130+
results = append(results, r)
129131
continue
132+
} else {
133+
r.Address = sender
134+
}
135+
136+
if gas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil,
137+
chainConfig.IsHomestead(new(big.Int)), chainConfig.IsIstanbul(new(big.Int))); err != nil {
138+
r.Error = err
139+
} else if tx.Gas() < gas {
140+
r.Error = fmt.Errorf("%w: have %d, want %d", core.ErrIntrinsicGas, tx.Gas(), gas)
130141
}
131-
results = append(results, result{Address: sender, Hash: tx.Hash()})
142+
results = append(results, r)
132143
}
133144
out, err := json.MarshalIndent(results, "", " ")
134145
fmt.Println(string(out))

cmd/evm/t8n_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func TestT9n(t *testing.T) {
233233
},
234234
expOut: "exp.json",
235235
},
236-
{ // London txs on homestead
236+
{ // London txs on London
237237
base: "./testdata/15",
238238
input: t9nInput{
239239
inTxs: "signed_txs.rlp",
@@ -249,6 +249,14 @@ func TestT9n(t *testing.T) {
249249
},
250250
expOut: "exp3.json",
251251
},
252+
{ // Transactions with too low gas
253+
base: "./testdata/16",
254+
input: t9nInput{
255+
inTxs: "signed_txs.rlp",
256+
stFork: "London",
257+
},
258+
expOut: "exp.json",
259+
},
252260
} {
253261

254262
args := []string{"t9n"}

cmd/evm/testdata/15/exp.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
[
22
{
3-
"error": "transaction type not supported"
3+
"error": "transaction type not supported",
4+
"hash": "0xa98a24882ea90916c6a86da650fbc6b14238e46f0af04a131ce92be897507476"
45
},
56
{
6-
"error": "transaction type not supported"
7+
"error": "transaction type not supported",
8+
"hash": "0x36bad80acce7040c45fd32764b5c2b2d2e6f778669fb41791f73f546d56e739a"
79
}
8-
]
10+
]

cmd/evm/testdata/16/exp.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
{
3+
"address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
4+
"hash": "0x7cc3d1a8540a44736750f03bb4d85c0113be4b3472a71bf82241a3b261b479e6"
5+
},
6+
{
7+
"error": "intrinsic gas too low: have 82, want 21000",
8+
"address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
9+
"hash": "0x3b2d2609e4361562edb9169314f4c05afc6dbf5d706bf9dda5abe242ab76a22b"
10+
}
11+
]

cmd/evm/testdata/16/signed_txs.rlp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"0xf8cab86401f8610180018252089411111111111111111111111111111111111111112080c001a0937f65ef1deece46c473b99962678fb7c38425cf303d1e8fa9717eb4b9d012b5a01940c5a5647c4940217ffde1051a5fd92ec8551e275c1787f81f50a2ad84de43b86201f85f018001529411111111111111111111111111111111111111112080c001a0241c3aec732205542a87fef8c76346741e85480bce5a42d05a9a73dac892f84ca04f52e2dfce57f3a02ed10e085e1a154edf38a726da34127c85fc53b4921759c8"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[
2+
{
3+
"input" : "0x",
4+
"gas" : "0x5208",
5+
"nonce" : "0x0",
6+
"to" : "0x1111111111111111111111111111111111111111",
7+
"value" : "0x20",
8+
"v" : "0x0",
9+
"r" : "0x0",
10+
"s" : "0x0",
11+
"secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
12+
"chainId" : "0x1",
13+
"type" : "0x1",
14+
"gasPrice": "0x1",
15+
"accessList" : [
16+
]
17+
},
18+
{
19+
"input" : "0x",
20+
"gas" : "0x52",
21+
"nonce" : "0x0",
22+
"to" : "0x1111111111111111111111111111111111111111",
23+
"value" : "0x20",
24+
"v" : "0x0",
25+
"r" : "0x0",
26+
"s" : "0x0",
27+
"secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
28+
"chainId" : "0x1",
29+
"type" : "0x1",
30+
"gasPrice": "0x1",
31+
"accessList" : [
32+
]
33+
}
34+
]

0 commit comments

Comments
 (0)