Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eip4399 state test in cmd/evm #3220

Merged
merged 5 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type stEnv struct {
BlockHashes map[math.HexOrDecimal64]common.Hash `json:"blockHashes,omitempty"`
Ommers []ommer `json:"ommers,omitempty"`
BaseFee *big.Int `json:"currentBaseFee,omitempty"`
Random *common.Hash `json:"currentRandom,omitempty"`
}

type rejectedTx struct {
Expand Down Expand Up @@ -126,14 +127,23 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
txIndex = 0
)
gaspool.AddGas(pre.Env.GasLimit)

difficulty := new(big.Int)
if pre.Env.Random == nil {
difficulty = pre.Env.Difficulty
} else {
// We are on POS hence difficulty opcode is now supplant with RANDOM
random := pre.Env.Random.Bytes()
difficulty.SetBytes(random)
}
vmContext := vm.BlockContext{
CanTransfer: core.CanTransfer,
Transfer: core.Transfer,
Coinbase: pre.Env.Coinbase,
BlockNumber: pre.Env.Number,
ContractHasTEVM: func(common.Hash) (bool, error) { return false, nil },
Time: pre.Env.Timestamp,
Difficulty: pre.Env.Difficulty,
Difficulty: difficulty,
GasLimit: pre.Env.GasLimit,
GetHash: getHash,
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/evm/internal/t8ntool/gen_stenv.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"os"
"path"

"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/commands"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/hexutil"
"github.com/ledgerwatch/erigon/core"
Expand Down Expand Up @@ -259,12 +261,30 @@ func (t *txWithKey) UnmarshalJSON(input []byte) error {
return err
}
}
gasPrice, value := uint256.NewInt(0), uint256.NewInt(0)
var overflow bool
// Now, read the transaction itself
var tx types.Transaction
if err := json.Unmarshal(input, &tx); err != nil {
var txJson commands.RPCTransaction

if err := json.Unmarshal(input, &txJson); err != nil {
return err
}
t.tx = tx

if txJson.Value != nil {
value, overflow = uint256.FromBig((*big.Int)(txJson.Value))
if overflow {
return fmt.Errorf("value field caused an overflow (uint256)")
}
}

if txJson.GasPrice != nil {
gasPrice, overflow = uint256.FromBig((*big.Int)(txJson.GasPrice))
if overflow {
return fmt.Errorf("gasPrice field caused an overflow (uint256)")
}
}
// assemble transaction
t.tx = types.NewTransaction(uint64(txJson.Nonce), *txJson.To, value, uint64(txJson.Gas), gasPrice, txJson.Input)
return nil
}

Expand Down
19 changes: 19 additions & 0 deletions cmd/evm/testdata/9/alloc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"balance": "0x100000000000000000",
"nonce": "0x00"
},
"0x00000000000000000000000000000000b0b0face": {
"code":"0x40600052",
"storage":{},
"balance":"0x0",
"nonce":
"0x0"
},
"0x000000000000000000000000000000ca1100f022": {
"code":"0x60806040527f248f18b25d9b5856c092f62a7d329b239f4a0a77e6ee6c58637f56745b9803f3446040518082815260200191505060405180910390a100fea265627a7a72315820eea50cf12e938601a56dcdef0ab1446f14ba25367299eb81834af54e1672f5d864736f6c63430005110032",
"storage":{},
"balance":"0x0",
"nonce":"0x0"
}
}
8 changes: 8 additions & 0 deletions cmd/evm/testdata/9/env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"currentCoinbase": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty": "0x20000",
"currentGasLimit": "0x1000000000",
"currentNumber": "0x1000000",
"currentTimestamp": "0x04",
"currentRandom": "0x1000000000000000000000000000000000000000000000000000000000000001"
}
14 changes: 14 additions & 0 deletions cmd/evm/testdata/9/txs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"gasPrice":"0x80",
"nonce":"0x0",
"to":"0x000000000000000000000000000000ca1100f022",
"input": "",
"gas":"0x1312d00",
"value": "0x0",
"v": "0x0",
"r": "0x0",
"s": "0x0",
"secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
}
]