cmd/evm: stricter transaction validation (#23694)

* cmd/evm: t9n: validate transaction intrinsic gas

* cmd/evm: t9n: stricter tx validation
verkle/onleaf
Martin Holst Swende 3 years ago committed by GitHub
parent 8a430fbd1c
commit 64da037e99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      cmd/evm/internal/t8ntool/transaction.go
  2. 10
      cmd/evm/t8n_test.go
  3. 6
      cmd/evm/testdata/15/exp.json
  4. 11
      cmd/evm/testdata/16/exp.json
  5. 1
      cmd/evm/testdata/16/signed_txs.rlp
  6. 34
      cmd/evm/testdata/16/unsigned_txs.json

@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
@ -123,12 +124,22 @@ func Transaction(ctx *cli.Context) error {
results = append(results, result{Error: err}) results = append(results, result{Error: err})
continue continue
} }
sender, err := types.Sender(signer, &tx) r := result{Hash: tx.Hash()}
if err != nil { if sender, err := types.Sender(signer, &tx); err != nil {
results = append(results, result{Error: err}) r.Error = err
results = append(results, r)
continue continue
} else {
r.Address = sender
}
if gas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil,
chainConfig.IsHomestead(new(big.Int)), chainConfig.IsIstanbul(new(big.Int))); err != nil {
r.Error = err
} else if tx.Gas() < gas {
r.Error = fmt.Errorf("%w: have %d, want %d", core.ErrIntrinsicGas, tx.Gas(), gas)
} }
results = append(results, result{Address: sender, Hash: tx.Hash()}) results = append(results, r)
} }
out, err := json.MarshalIndent(results, "", " ") out, err := json.MarshalIndent(results, "", " ")
fmt.Println(string(out)) fmt.Println(string(out))

@ -233,7 +233,7 @@ func TestT9n(t *testing.T) {
}, },
expOut: "exp.json", expOut: "exp.json",
}, },
{ // London txs on homestead { // London txs on London
base: "./testdata/15", base: "./testdata/15",
input: t9nInput{ input: t9nInput{
inTxs: "signed_txs.rlp", inTxs: "signed_txs.rlp",
@ -249,6 +249,14 @@ func TestT9n(t *testing.T) {
}, },
expOut: "exp3.json", expOut: "exp3.json",
}, },
{ // Transactions with too low gas
base: "./testdata/16",
input: t9nInput{
inTxs: "signed_txs.rlp",
stFork: "London",
},
expOut: "exp.json",
},
} { } {
args := []string{"t9n"} args := []string{"t9n"}

@ -1,8 +1,10 @@
[ [
{ {
"error": "transaction type not supported" "error": "transaction type not supported",
"hash": "0xa98a24882ea90916c6a86da650fbc6b14238e46f0af04a131ce92be897507476"
}, },
{ {
"error": "transaction type not supported" "error": "transaction type not supported",
"hash": "0x36bad80acce7040c45fd32764b5c2b2d2e6f778669fb41791f73f546d56e739a"
} }
] ]

@ -0,0 +1,11 @@
[
{
"address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"hash": "0x7cc3d1a8540a44736750f03bb4d85c0113be4b3472a71bf82241a3b261b479e6"
},
{
"error": "intrinsic gas too low: have 82, want 21000",
"address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"hash": "0x3b2d2609e4361562edb9169314f4c05afc6dbf5d706bf9dda5abe242ab76a22b"
}
]

@ -0,0 +1 @@
"0xf8cab86401f8610180018252089411111111111111111111111111111111111111112080c001a0937f65ef1deece46c473b99962678fb7c38425cf303d1e8fa9717eb4b9d012b5a01940c5a5647c4940217ffde1051a5fd92ec8551e275c1787f81f50a2ad84de43b86201f85f018001529411111111111111111111111111111111111111112080c001a0241c3aec732205542a87fef8c76346741e85480bce5a42d05a9a73dac892f84ca04f52e2dfce57f3a02ed10e085e1a154edf38a726da34127c85fc53b4921759c8"

@ -0,0 +1,34 @@
[
{
"input" : "0x",
"gas" : "0x5208",
"nonce" : "0x0",
"to" : "0x1111111111111111111111111111111111111111",
"value" : "0x20",
"v" : "0x0",
"r" : "0x0",
"s" : "0x0",
"secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"chainId" : "0x1",
"type" : "0x1",
"gasPrice": "0x1",
"accessList" : [
]
},
{
"input" : "0x",
"gas" : "0x52",
"nonce" : "0x0",
"to" : "0x1111111111111111111111111111111111111111",
"value" : "0x20",
"v" : "0x0",
"r" : "0x0",
"s" : "0x0",
"secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
"chainId" : "0x1",
"type" : "0x1",
"gasPrice": "0x1",
"accessList" : [
]
}
]
Loading…
Cancel
Save