Skip to content

Commit

Permalink
Removed all references to EIPs 3198, 3529, 3541, 3554
Browse files Browse the repository at this point in the history
  • Loading branch information
jdowning100 committed May 9, 2023
1 parent 61106bc commit 263aed1
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 148 deletions.
3 changes: 1 addition & 2 deletions consensus/blake3pow/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ func (blake3pow *Blake3pow) verifyHeader(chain consensus.ChainHeaderReader, head
}
// Verify the block's gas usage and verify the base fee.
// Verify that the gas limit remains within allowed bounds
parentGasLimit := parent.GasLimit()
if err := misc.VerifyGaslimit(parentGasLimit, header.GasLimit()); err != nil {
if err := misc.VerifyGaslimit(parent.GasLimit(), header.GasLimit()); err != nil {
return err
}
// Verify the header is not malformed
Expand Down
6 changes: 0 additions & 6 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis) (*params
}
// Get the existing chain configuration.
newcfg := genesis.configOrDefault(stored)
if err := newcfg.CheckConfigForkOrder(); err != nil {
return newcfg, common.Hash{}, err
}
storedcfg := rawdb.ReadChainConfig(db, stored)
if storedcfg == nil {
log.Warn("Found genesis block without chain config")
Expand Down Expand Up @@ -283,9 +280,6 @@ func (g *Genesis) Commit(db ethdb.Database) (*types.Block, error) {
if config == nil {
config = params.AllBlake3powProtocolChanges
}
if err := config.CheckConfigForkOrder(); err != nil {
return nil, err
}
rawdb.WriteTermini(db, block.Hash(), nil)
rawdb.WriteBlock(db, block)
rawdb.WriteReceipts(db, block.Hash(), block.NumberU64(), nil)
Expand Down
4 changes: 2 additions & 2 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
st.evm.ETXCache = make([]*types.Transaction, 0)
st.evm.ETXCacheLock.Unlock()

// After EIP-3529: refunds are capped to gasUsed / 5
st.refundGas(params.RefundQuotientEIP3529)
// refunds are capped to gasUsed / 5
st.refundGas(params.RefundQuotient)

effectiveTip := cmath.BigMin(st.gasTipCap, new(big.Int).Sub(st.gasFeeCap, st.evm.Context.BaseFee))
coinbase, err := st.evm.Context.Coinbase.InternalAddress()
Expand Down
54 changes: 0 additions & 54 deletions core/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,9 @@
package vm

import (
"fmt"
"sort"

"github.com/holiman/uint256"
)

var activators = map[int]func(*JumpTable){
3529: enable3529,
3198: enable3198,
}

// 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 {
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
}

func opSelfBalance(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
internalAddr, err := scope.Contract.Address().InternalAddress()
if err != nil {
Expand All @@ -70,27 +37,6 @@ func opChainID(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]
return nil, nil
}

// enable3529 enabled "EIP-3529: Reduction in refunds":
// - Removes refunds for selfdestructs
// - Reduces refunds for SSTORE
// - Reduces max refunds to 20% gas
func enable3529(jt *JumpTable) {
jt[SSTORE].dynamicGas = gasSStoreEIP3529
jt[SELFDESTRUCT].dynamicGas = gasSelfdestructEIP3529
}

// enable3198 applies EIP-3198 (BASEFEE Opcode)
// - Adds an opcode that returns the current block's base fee.
func enable3198(jt *JumpTable) {
// New opcode
jt[BASEFEE] = &operation{
execute: opBaseFee,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
maxStack: maxStack(0, 1),
}
}

// opBaseFee implements BASEFEE opcode
func opBaseFee(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
baseFee, _ := uint256.FromBig(interpreter.evm.Context.BaseFee)
Expand Down
2 changes: 1 addition & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
err = ErrMaxCodeSizeExceeded
}

// Reject code starting with 0xEF if EIP-3541 is enabled.
// Reject code starting with 0xEF
if err == nil && len(ret) >= 1 && ret[0] == 0xEF {
err = ErrInvalidCode
}
Expand Down
10 changes: 0 additions & 10 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/dominant-strategies/go-quai/common"
"github.com/dominant-strategies/go-quai/common/math"
"github.com/dominant-strategies/go-quai/log"
)

// Config are the configuration options for the Interpreter
Expand All @@ -34,8 +33,6 @@ type Config struct {
EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages

JumpTable [256]*operation // EVM instruction table, automatically populated if unset

ExtraEips []int // Additional EIPS that are to be enabled
}

// ScopeContext contains the things that are per-call, such as stack and memory,
Expand Down Expand Up @@ -73,13 +70,6 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter {
// we'll set the default jump table.
if cfg.JumpTable[STOP] == nil {
jt := instructionSet
for i, eip := range cfg.ExtraEips {
if err := EnableEIP(eip, &jt); err != nil {
// Disable it, so caller can check if it's activated or not
cfg.ExtraEips = append(cfg.ExtraEips[:i], cfg.ExtraEips[i+1:]...)
log.Error("EIP activation failed", "eip", eip, "error", err)
}
}
cfg.JumpTable = jt
}

Expand Down
8 changes: 6 additions & 2 deletions core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ func NewInstructionSet() JumpTable {
minStack: minStack(0, 1),
maxStack: maxStack(0, 1),
}
enable3529(&instructionSet) // EIP-3529: Reduction in refunds https://eips.ethereum.org/EIPS/eip-3529
enable3198(&instructionSet) // Base fee opcode https://eips.ethereum.org/EIPS/eip-3198
return instructionSet
}

Expand Down Expand Up @@ -974,6 +972,12 @@ func newInstructionSet() JumpTable {
halts: true,
writes: true,
},
BASEFEE: {
execute: opBaseFee,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
maxStack: maxStack(0, 1),
},
ETX: {
execute: opETX,
constantGas: params.ETXGas,
Expand Down
20 changes: 4 additions & 16 deletions core/vm/operations_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,12 @@ var (
gasDelegateCallVariant = makeCallVariantGasCall(gasDelegateCall)
gasStaticCallVariant = makeCallVariantGasCall(gasStaticCall)
gasCallCodeVariant = makeCallVariantGasCall(gasCallCode)
gasSelfdestructVariant = makeSelfdestructGasFn(true)
// gasSelfdestructEIP3529 implements the changes in EIP-2539 (no refunds)
gasSelfdestructEIP3529 = makeSelfdestructGasFn(false)
// gasSelfdestructVariant implements self destruct with no refunds
gasSelfdestructVariant = makeSelfdestructGasFn(false)

// gasSStore implements gas cost for SSTORE
//
// When calling SSTORE, check if the (address, storage_key) pair is in accessed_storage_keys.
// If it is not, charge an additional COLD_SLOAD_COST gas, and add the pair to accessed_storage_keys.
// Additionally, modify the parameters as follows:
//
// Parameter Old value New value
// SLOAD_GAS 800 = WARM_STORAGE_READ_COST
// SSTORE_RESET_GAS 5000 5000 - COLD_SLOAD_COST
gasSStoreVariant = makeGasSStoreFunc(params.SstoreClearsScheduleRefund)

// gasSStoreEIP2539 implements gas cost for SSTORE according to EPI-2539
// gasSStoreVariant implements gas cost for SSTORE
// Replace `SSTORE_CLEARS_SCHEDULE` with `SSTORE_RESET_GAS + ACCESS_LIST_STORAGE_KEY_COST` (4,800)
gasSStoreEIP3529 = makeGasSStoreFunc(params.SstoreClearsScheduleRefundEIP3529)
gasSStoreVariant = makeGasSStoreFunc(params.SstoreClearsScheduleRefund)
)

// makeSelfdestructGasFn can create the selfdestruct dynamic gas function
Expand Down
45 changes: 0 additions & 45 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,51 +114,6 @@ func (c *ChainConfig) String() string {
)
}

// CheckConfigForkOrder checks that we don't "skip" any forks, geth isn't pluggable enough
// to guarantee that forks can be implemented in a different order than on official networks
func (c *ChainConfig) CheckConfigForkOrder() error {
type fork struct {
name string
block *big.Int
optional bool // if true, the fork may be nil and next fork is still allowed
}
var lastFork fork
for _, cur := range []fork{} {
if lastFork.name != "" {
// Next one must be higher number
if lastFork.block == nil && cur.block != nil {
return fmt.Errorf("unsupported fork ordering: %v not enabled, but %v enabled at %v",
lastFork.name, cur.name, cur.block)
}
if lastFork.block != nil && cur.block != nil {
if lastFork.block.Cmp(cur.block) > 0 {
return fmt.Errorf("unsupported fork ordering: %v enabled at %v, but %v enabled at %v",
lastFork.name, lastFork.block, cur.name, cur.block)
}
}
}
// If it was optional and not set, then ignore it
if !cur.optional || cur.block != nil {
lastFork = cur
}
}
return nil
}

// isForkIncompatible returns true if a fork scheduled at s1 cannot be rescheduled to
// block s2 because head is already past the fork.
func isForkIncompatible(s1, s2, head *big.Int) bool {
return (isForked(s1, head) || isForked(s2, head)) && !configNumEqual(s1, s2)
}

// isForked returns whether a fork scheduled at block s is active at the given head block.
func isForked(s, head *big.Int) bool {
if s == nil || head == nil {
return false
}
return s.Cmp(head) <= 0
}

func configNumEqual(x, y *big.Int) bool {
if x == nil {
return y == nil
Expand Down
17 changes: 7 additions & 10 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,17 @@ const (
NetSstoreResetRefund uint64 = 4800 // Once per SSTORE operation for resetting to the original non-zero value
NetSstoreResetClearRefund uint64 = 19800 // Once per SSTORE operation for resetting to the original zero value

SstoreSentryGas uint64 = 2300 // Minimum gas required to be present for an SSTORE call, not consumed
SstoreSetGas uint64 = 20000 // Once per SSTORE operation from clean zero to non-zero
SstoreResetGas uint64 = 5000 // Once per SSTORE operation from clean non-zero to something else
SstoreClearsScheduleRefund uint64 = 15000 // Once per SSTORE operation for clearing an originally existing storage slot
SstoreSentryGas uint64 = 2300 // Minimum gas required to be present for an SSTORE call, not consumed
SstoreSetGas uint64 = 20000 // Once per SSTORE operation from clean zero to non-zero
SstoreResetGas uint64 = 5000 // Once per SSTORE operation from clean non-zero to something else

ColdAccountAccessCost = uint64(2600) // COLD_ACCOUNT_ACCESS_COST
ColdSloadCost = uint64(2100) // COLD_SLOAD_COST
WarmStorageReadCost = uint64(100) // WARM_STORAGE_READ_COST

// In EIP-3529: SSTORE_CLEARS_SCHEDULE is defined as SSTORE_RESET_GAS + ACCESS_LIST_STORAGE_KEY_COST
// SSTORE_CLEARS_SCHEDULE is defined as SSTORE_RESET_GAS + ACCESS_LIST_STORAGE_KEY_COST
// Which becomes: 5000 - 2100 + 1900 = 4800
SstoreClearsScheduleRefundEIP3529 uint64 = SstoreResetGas - ColdSloadCost + TxAccessListStorageKeyGas
SstoreClearsScheduleRefund uint64 = SstoreResetGas - ColdSloadCost + TxAccessListStorageKeyGas // Once per SSTORE operation for clearing an originally existing storage slot

JumpdestGas uint64 = 1 // Once per JUMPDEST operation.
EpochDuration uint64 = 30000 // Duration between proof-of-work epochs.
Expand Down Expand Up @@ -125,10 +124,8 @@ const (
Bn256PairingBaseGas uint64 = 45000 // Base price for an elliptic curve pairing check
Bn256PairingPerPointGas uint64 = 34000 // Per-point price for an elliptic curve pairing check

// The Refund Quotient is the cap on how much of the used gas can be refunded. Before EIP-3529,
// up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529
RefundQuotient uint64 = 2
RefundQuotientEIP3529 uint64 = 5
// The Refund Quotient is the cap on how much of the used gas can be refunded
RefundQuotient uint64 = 5
)

var (
Expand Down

0 comments on commit 263aed1

Please sign in to comment.