Skip to content

Commit

Permalink
Fix espresso block config and rename E to espresso (ethereum#1766)
Browse files Browse the repository at this point in the history
### Description

This enables mycelo and e2e tests to set the espresso block number.
This is was done to test celo typed transactions and espresso.

This commit also renames any reference of "E" hardfork or block
to "Espresso".

Also updates the mycelo load bot to use the latest signer instead of
the homestead signer.

### Tested

Unit test, CI. Tested that e2e tests can activate the Espresso fork.

### Backwards compatibility
Yes
  • Loading branch information
trianglesphere committed Dec 2, 2021
1 parent e0c4338 commit f5a1fc1
Show file tree
Hide file tree
Showing 30 changed files with 86 additions and 84 deletions.
4 changes: 2 additions & 2 deletions accounts/abi/bind/backends/simulated.go
Expand Up @@ -564,7 +564,7 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
return nil, errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
}
head := b.blockchain.CurrentHeader()
if !b.blockchain.Config().IsEHardfork(head.Number) {
if !b.blockchain.Config().IsEspresso(head.Number) {
// If there's no basefee, then it must be a non-1559 execution
if call.GasPrice == nil {
call.GasPrice = new(big.Int)
Expand Down Expand Up @@ -615,7 +615,7 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
gasPool := new(core.GasPool).AddGas(math.MaxUint64)
vmRunner := b.blockchain.NewEVMRunner(block.Header(), stateDB)
var sysCtx *core.SysContractCallCtx
if b.config.IsEHardfork(block.Number()) {
if b.config.IsEspresso(block.Number()) {
parent := b.blockchain.GetBlockByNumber(block.NumberU64() - 1)
sysStateDB, err := b.blockchain.StateAt(parent.Root())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/transition.go
Expand Up @@ -250,7 +250,7 @@ func Main(ctx *cli.Context) error {
return NewError(ErrorJson, fmt.Errorf("failed signing transactions: %v", err))
}
// Sanity check, to not `panic` in state_transition
if chainConfig.IsEHardfork(big.NewInt(int64(prestate.Env.Number))) {
if chainConfig.IsEspresso(big.NewInt(int64(prestate.Env.Number))) {
if prestate.Env.BaseFee == nil {
return NewError(ErrorVMConfig, errors.New("EIP-1559 config but missing 'currentBaseFee' in env section"))
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/utils/flags.go
Expand Up @@ -240,8 +240,8 @@ var (

// Hard fork activation overrides
OverrideEHardforkFlag = cli.Uint64Flag{
Name: "override.eHardfork",
Usage: "Manually specify E fork-block, overriding the bundled setting",
Name: "override.espresso",
Usage: "Manually specify the espresso fork block, overriding the bundled setting",
}

BloomFilterSizeFlag = cli.Uint64Flag{
Expand Down
2 changes: 1 addition & 1 deletion consensus/istanbul/core/core.go
Expand Up @@ -724,7 +724,7 @@ func (c *core) getRoundChangeTimeout() time.Duration {
if round == 0 {
return baseTimeout + blockTime
} else {
if c.backend.ChainConfig().IsEHardfork(c.current.Sequence()) {
if c.backend.ChainConfig().IsEspresso(c.current.Sequence()) {
return baseTimeout + blockTime + time.Duration(math.Pow(2, float64(round)))*time.Duration(c.config.TimeoutBackoffFactor)*time.Millisecond
} else {
return baseTimeout + time.Duration(math.Pow(2, float64(round)))*time.Duration(c.config.TimeoutBackoffFactor)*time.Millisecond
Expand Down
2 changes: 1 addition & 1 deletion core/genesis.go
Expand Up @@ -203,7 +203,7 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
// Get the existing chain configuration.
newcfg := genesis.configOrDefault(stored)
if overrideEHardfork != nil {
newcfg.EBlock = overrideEHardfork
newcfg.EspressoBlock = overrideEHardfork
}

if err := newcfg.CheckConfigForkOrder(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions core/state_prefetcher.go
Expand Up @@ -60,7 +60,7 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c
)
// Iterate over and process the individual transactions
byzantium := p.config.IsByzantium(block.Number())
espresso := p.bc.chainConfig.IsEHardfork(block.Number())
espresso := p.bc.chainConfig.IsEspresso(block.Number())
if espresso {
sysCtx = NewSysContractCallCtx(p.bc.NewEVMRunner(header, statedb))
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func precacheTransaction(config *params.ChainConfig, bc *BlockChain, author *com
vm := vm.NewEVM(context, txContext, statedb, config, cfg)

var sysCtx *SysContractCallCtx
if config.IsEHardfork(header.Number) {
if config.IsEspresso(header.Number) {
sysVmRunner := bc.NewEVMRunner(header, statedb)
sysCtx = NewSysContractCallCtx(sysVmRunner)
}
Expand Down
6 changes: 3 additions & 3 deletions core/state_processor.go
Expand Up @@ -85,7 +85,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
baseFee *big.Int
sysCtx *SysContractCallCtx
)
if p.bc.Config().IsEHardfork(blockNumber) {
if p.bc.Config().IsEspresso(blockNumber) {
sysVmRunner := p.bc.NewEVMRunner(header, statedb)
sysCtx = NewSysContractCallCtx(sysVmRunner)
if p.bc.Config().Faker {
Expand All @@ -96,7 +96,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, p.config, cfg)
// Iterate over and process the individual transactions
for i, tx := range block.Transactions() {
if p.bc.chainConfig.IsEHardfork(header.Number) {
if p.bc.chainConfig.IsEspresso(header.Number) {
baseFee = sysCtx.GetGasPriceMinimum(tx.FeeCurrency())
}
msg, err := tx.AsMessage(types.MakeSigner(p.config, header.Number), baseFee)
Expand Down Expand Up @@ -175,7 +175,7 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, gp *GasPool
// indicating the block was invalid.
func ApplyTransaction(config *params.ChainConfig, bc ChainContext, txFeeRecipient *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config, vmRunner vm.EVMRunner, sysCtx *SysContractCallCtx) (*types.Receipt, error) {
var baseFee *big.Int
if config.IsEHardfork(header.Number) {
if config.IsEspresso(header.Number) {
baseFee = sysCtx.GetGasPriceMinimum(tx.FeeCurrency())
}
msg, err := tx.AsMessage(types.MakeSigner(config, header.Number), baseFee)
Expand Down
2 changes: 1 addition & 1 deletion core/state_processor_test.go
Expand Up @@ -50,7 +50,7 @@ func TestStateProcessorErrors(t *testing.T) {
IstanbulBlock: big.NewInt(0),
ChurritoBlock: big.NewInt(0),
DonutBlock: big.NewInt(0),
EBlock: big.NewInt(0),
EspressoBlock: big.NewInt(0),
Faker: true,
}
signer = types.LatestSigner(config)
Expand Down
22 changes: 11 additions & 11 deletions core/state_transition.go
Expand Up @@ -208,7 +208,7 @@ func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation b
// NewStateTransition initialises and returns a new state transition object.
func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool, vmRunner vm.EVMRunner, sysCtx *SysContractCallCtx) *StateTransition {
var gasPriceMinimum *big.Int
if evm.ChainConfig().IsEHardfork(evm.Context.BlockNumber) {
if evm.ChainConfig().IsEspresso(evm.Context.BlockNumber) {
gasPriceMinimum = sysCtx.GetGasPriceMinimum(msg.FeeCurrency())
} else {
gasPriceMinimum, _ = gpm.GetGasPriceMinimum(vmRunner, msg.FeeCurrency())
Expand Down Expand Up @@ -262,9 +262,9 @@ func (st *StateTransition) to() common.Address {
}

// payFees deducts gas and gateway fees from sender balance and adds the purchased amount of gas to the state.
func (st *StateTransition) payFees(eHardFork bool) error {
func (st *StateTransition) payFees(espresso bool) error {
var isWhiteListed bool
if eHardFork {
if espresso {
isWhiteListed = st.sysCtx.IsWhitelisted(st.msg.FeeCurrency())
} else {
isWhiteListed = currency.IsWhitelisted(st.vmRunner, st.msg.FeeCurrency())
Expand All @@ -274,7 +274,7 @@ func (st *StateTransition) payFees(eHardFork bool) error {
return ErrNonWhitelistedFeeCurrency
}

if err := st.canPayFee(st.msg.From(), st.msg.FeeCurrency(), eHardFork); err != nil {
if err := st.canPayFee(st.msg.From(), st.msg.FeeCurrency(), espresso); err != nil {
return err
}
if err := st.gp.SubGas(st.msg.Gas()); err != nil {
Expand Down Expand Up @@ -437,7 +437,7 @@ func (st *StateTransition) preCheck() error {
}

// Make sure that transaction gasFeeCap >= baseFee (post Espresso)
if st.evm.ChainConfig().IsEHardfork(st.evm.Context.BlockNumber) {
if st.evm.ChainConfig().IsEspresso(st.evm.Context.BlockNumber) {
// Skip the checks if gas fields are zero and baseFee was explicitly disabled (eth_call)
if !st.evm.Config.NoBaseFee || st.gasFeeCap.BitLen() > 0 || st.gasTipCap.BitLen() > 0 {
if l := st.gasFeeCap.BitLen(); l > 256 {
Expand Down Expand Up @@ -516,14 +516,14 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
msg := st.msg
sender := vm.AccountRef(msg.From())
istanbul := st.evm.ChainConfig().IsIstanbul(st.evm.Context.BlockNumber)
eHardfork := st.evm.ChainConfig().IsEHardfork(st.evm.Context.BlockNumber)
espresso := st.evm.ChainConfig().IsEspresso(st.evm.Context.BlockNumber)
contractCreation := msg.To() == nil

// Calculate intrinsic gas, check clauses 5-6
gasForAlternativeCurrency := uint64(0)
// If the fee currency is nil, do not retrieve the intrinsic gas adjustment from the chain state, as it will not be used.
if msg.FeeCurrency() != nil {
if eHardfork {
if espresso {
gasForAlternativeCurrency = st.sysCtx.GetIntrinsicGasForAlternativeFeeCurrency()
} else {
gasForAlternativeCurrency = blockchain_parameters.GetIntrinsicGasForAlternativeFeeCurrencyOrDefault(st.vmRunner)
Expand All @@ -539,7 +539,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
return nil, fmt.Errorf("%w: have %d, want %d", ErrIntrinsicGas, st.msg.Gas(), gas)
}
// Check clauses 3-4, pay the fees (which buys gas), and subtract the intrinsic gas
err = st.payFees(eHardfork)
err = st.payFees(espresso)
if err != nil {
log.Error("Transaction failed to buy gas", "err", err, "gas", gas)
return nil, err
Expand All @@ -552,7 +552,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
}

// Set up the initial access list.
if rules := st.evm.ChainConfig().Rules(st.evm.Context.BlockNumber); eHardfork {
if rules := st.evm.ChainConfig().Rules(st.evm.Context.BlockNumber); espresso {
st.state.PrepareAccessList(msg.From(), msg.To(), vm.ActivePrecompiles(rules), msg.AccessList())
}
var (
Expand All @@ -567,7 +567,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
ret, st.gas, vmerr = st.evm.Call(sender, st.to(), st.data, st.gas, st.value)
}

if !eHardfork {
if !espresso {
// Before EIP-3529: refunds were capped to gasUsed / 2
st.refundGas(params.RefundQuotient)
} else {
Expand Down Expand Up @@ -600,7 +600,7 @@ func (st *StateTransition) distributeTxFees() error {
totalTxFee := new(big.Int).Mul(gasUsed, st.gasPrice)
from := st.msg.From()

// Divide the transaction into a base (the minimum transaction fee) and tip (any extra, or min(max tip, feecap - GPM) if ehardfork).
// Divide the transaction into a base (the minimum transaction fee) and tip (any extra, or min(max tip, feecap - GPM) if espresso).
baseTxFee := new(big.Int).Mul(gasUsed, st.gasPriceMinimum)
// No need to do effectiveTip calculation, because st.gasPrice == effectiveGasPrice, and effectiveTip = effectiveGasPrice - baseTxFee
tipTxFee := new(big.Int).Sub(totalTxFee, baseTxFee)
Expand Down
16 changes: 8 additions & 8 deletions core/tx_pool.go
Expand Up @@ -266,9 +266,9 @@ type TxPool struct {
signer types.Signer
mu sync.RWMutex

istanbul bool // Fork indicator whether we are in the istanbul stage.
donut bool // Fork indicator for the Donut fork.
eHardfork bool // Fork indicator for the E fork.
istanbul bool // Fork indicator whether we are in the istanbul stage.
donut bool // Fork indicator for the Donut fork.
espresso bool // Fork indicator for the Espresso fork.

currentState *state.StateDB // Current state in the blockchain head
currentVMRunner vm.EVMRunner // Current EVMRunner
Expand Down Expand Up @@ -660,11 +660,11 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
}

// Accept only legacy transactions until EIP-2718/2930 activates.
if !pool.eHardfork && tx.Type() != types.LegacyTxType {
if !pool.espresso && tx.Type() != types.LegacyTxType {
return ErrTxTypeNotSupported
}
// Reject dynamic fee transactions until EIP-1559 activates.
if !pool.eHardfork && tx.Type() == types.DynamicFeeTxType {
if !pool.espresso && tx.Type() == types.DynamicFeeTxType {
return ErrTxTypeNotSupported
}
// Reject transactions over defined size to prevent DOS attacks
Expand Down Expand Up @@ -712,7 +712,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return ErrNonceTooLow
}
// Transactor should have enough funds to cover the costs
err = ValidateTransactorBalanceCoversTx(tx, from, pool.currentState, pool.currentVMRunner, pool.eHardfork)
err = ValidateTransactorBalanceCoversTx(tx, from, pool.currentState, pool.currentVMRunner, pool.espresso)
if err != nil {
return err
}
Expand Down Expand Up @@ -1255,7 +1255,7 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt
// because of another transaction (e.g. higher gas price).
if reset != nil {
pool.demoteUnexecutables()
if reset.newHead != nil && pool.chainconfig.IsEHardfork(new(big.Int).Add(reset.newHead.Number, big.NewInt(1))) {
if reset.newHead != nil && pool.chainconfig.IsEspresso(new(big.Int).Add(reset.newHead.Number, big.NewInt(1))) {
pool.priced.SetBaseFee(pool.ctx())
}
}
Expand Down Expand Up @@ -1387,7 +1387,7 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
if pool.donut && !wasDonut {
pool.handleDonutActivation()
}
pool.eHardfork = pool.chainconfig.IsEHardfork(next)
pool.espresso = pool.chainconfig.IsEspresso(next)
}

// promoteExecutables moves transactions that have become processable from the
Expand Down
2 changes: 1 addition & 1 deletion core/tx_pool_test.go
Expand Up @@ -59,7 +59,7 @@ func init() {

cpy := *params.TestChainConfig
eip1559Config = &cpy
eip1559Config.EBlock = common.Big0
eip1559Config.EspressoBlock = common.Big0
}

type testBlockChain struct {
Expand Down
4 changes: 2 additions & 2 deletions core/types/transaction_signing.go
Expand Up @@ -40,7 +40,7 @@ type sigCache struct {
func MakeSigner(config *params.ChainConfig, blockNumber *big.Int) Signer {
var signer Signer
switch {
case config.IsEHardfork(blockNumber):
case config.IsEspresso(blockNumber):
signer = NewLondonSigner(config.ChainID)
case config.IsEIP155(blockNumber):
signer = NewEIP155Signer(config.ChainID)
Expand All @@ -61,7 +61,7 @@ func MakeSigner(config *params.ChainConfig, blockNumber *big.Int) Signer {
// have the current block number available, use MakeSigner instead.
func LatestSigner(config *params.ChainConfig) Signer {
if config.ChainID != nil {
if config.EBlock != nil {
if config.EspressoBlock != nil {
return NewLondonSigner(config.ChainID)
}
if config.EIP155Block != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/vm/contracts.go
Expand Up @@ -275,7 +275,7 @@ func init() {
// ActivePrecompiles returns the precompiles enabled with the current configuration.
func ActivePrecompiles(rules params.Rules) []common.Address {
switch {
case rules.IsEHardfork:
case rules.IsEspresso:
return PrecompiledAddressesE
case rules.IsDonut:
return PrecompiledAddressesDonut
Expand Down
6 changes: 3 additions & 3 deletions core/vm/evm.go
Expand Up @@ -57,7 +57,7 @@ type (
func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
var precompiles map[common.Address]PrecompiledContract
switch {
case evm.chainRules.IsEHardfork:
case evm.chainRules.IsEspresso:
precompiles = PrecompiledContractsE
case evm.chainRules.IsDonut:
precompiles = PrecompiledContractsDonut
Expand Down Expand Up @@ -429,7 +429,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,

// We add this to the access list _before_ taking a snapshot. Even if the creation fails,
// the access-list change should not be rolled back
if evm.chainRules.IsEHardfork {
if evm.chainRules.IsEspresso {
evm.StateDB.AddAddressToAccessList(address)
}
// Ensure there's no existing contract already at the designated address
Expand Down Expand Up @@ -467,7 +467,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
}

// Reject code starting with 0xEF if EIP-3541 is enabled.
if err == nil && len(ret) >= 1 && ret[0] == 0xEF && evm.chainRules.IsEHardfork {
if err == nil && len(ret) >= 1 && ret[0] == 0xEF && evm.chainRules.IsEspresso {
err = ErrInvalidCode
}

Expand Down
2 changes: 1 addition & 1 deletion core/vm/interpreter.go
Expand Up @@ -74,7 +74,7 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
if cfg.JumpTable[STOP] == nil {
var jt JumpTable
switch {
case evm.chainRules.IsEHardfork:
case evm.chainRules.IsEspresso:
jt = espressoInstructionSet
case evm.chainRules.IsIstanbul:
jt = istanbulInstructionSet
Expand Down
8 changes: 4 additions & 4 deletions core/vm/runtime/runtime.go
Expand Up @@ -66,7 +66,7 @@ func setDefaults(cfg *Config) {
IstanbulBlock: new(big.Int),
ChurritoBlock: new(big.Int),
DonutBlock: new(big.Int),
EBlock: new(big.Int),
EspressoBlock: new(big.Int),
}
}
if cfg.Time == nil {
Expand Down Expand Up @@ -110,7 +110,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
vmenv = NewEnv(cfg)
sender = vm.AccountRef(cfg.Origin)
)
if rules := cfg.ChainConfig.Rules(vmenv.Context.BlockNumber); rules.IsEHardfork {
if rules := cfg.ChainConfig.Rules(vmenv.Context.BlockNumber); rules.IsEspresso {
cfg.State.PrepareAccessList(cfg.Origin, &address, vm.ActivePrecompiles(rules), nil)
}
cfg.State.CreateAccount(address)
Expand Down Expand Up @@ -143,7 +143,7 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {
sender = vm.AccountRef(cfg.Origin)
)

if rules := cfg.ChainConfig.Rules(vmenv.Context.BlockNumber); rules.IsEHardfork {
if rules := cfg.ChainConfig.Rules(vmenv.Context.BlockNumber); rules.IsEspresso {
cfg.State.PrepareAccessList(cfg.Origin, nil, vm.ActivePrecompiles(rules), nil)
}
// Call the code with the given configuration.
Expand All @@ -169,7 +169,7 @@ func Call(address common.Address, input []byte, cfg *Config) ([]byte, uint64, er
sender := cfg.State.GetOrNewStateObject(cfg.Origin)
statedb := cfg.State

if rules := cfg.ChainConfig.Rules(vmenv.Context.BlockNumber); rules.IsEHardfork {
if rules := cfg.ChainConfig.Rules(vmenv.Context.BlockNumber); rules.IsEspresso {
statedb.PrepareAccessList(cfg.Origin, &address, vm.ActivePrecompiles(rules), nil)
}
// Call the code with the given configuration.
Expand Down
2 changes: 1 addition & 1 deletion eth/state_accessor.go
Expand Up @@ -161,7 +161,7 @@ func (eth *Ethereum) stateAtTransaction(block *types.Block, txIndex int, reexec
}
// Get the SysContractCallCtx
var sysCtx *core.SysContractCallCtx
espresso := eth.blockchain.Config().IsEHardfork(block.Number())
espresso := eth.blockchain.Config().IsEspresso(block.Number())
if espresso {
sysCtx = core.NewSysContractCallCtx(eth.blockchain.NewEVMRunner(block.Header(), statedb))
}
Expand Down

0 comments on commit f5a1fc1

Please sign in to comment.