cmd/evm: add state transition tool for testing (#20958)

This PR implements the EVM state transition tool, which is intended
to be the replacement for our retesteth client implementation.
Documentation is present in the cmd/evm/README.md file.

Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
Martin Holst Swende
2020-06-30 10:12:51 +02:00
committed by GitHub
parent dd91c7ce6a
commit e376d2fb31
37 changed files with 1509 additions and 48 deletions

View File

@ -18,30 +18,44 @@ package vm
import (
"fmt"
"sort"
"github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"
)
var activators = map[int]func(*JumpTable){
2200: enable2200,
1884: enable1884,
1344: enable1344,
2315: enable2315,
}
// EnableEIP enables the given EIP on the config.
// This operation writes in-place, and callers need to ensure that the globally
// defined jump tables are not polluted.
func EnableEIP(eipNum int, jt *JumpTable) error {
switch eipNum {
case 2200:
enable2200(jt)
case 1884:
enable1884(jt)
case 1344:
enable1344(jt)
case 2315:
enable2315(jt)
default:
enablerFn, ok := activators[eipNum]
if !ok {
return fmt.Errorf("undefined eip %d", eipNum)
}
enablerFn(jt)
return nil
}
func ValidEip(eipNum int) bool {
_, ok := activators[eipNum]
return ok
}
func ActivateableEips() []string {
var nums []string
for k := range activators {
nums = append(nums, fmt.Sprintf("%d", k))
}
sort.Strings(nums)
return nums
}
// enable1884 applies EIP-1884 to the given jump table:
// - Increase cost of BALANCE to 700
// - Increase cost of EXTCODEHASH to 700