mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-11 17:31:35 +00:00
core: apply fixes for 8037
This commit is contained in:
parent
16ba4de5a0
commit
c6c5536226
2 changed files with 33 additions and 6 deletions
30
core/evm.go
30
core/evm.go
|
|
@ -18,6 +18,7 @@ package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"math/bits"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/consensus"
|
"github.com/ethereum/go-ethereum/consensus"
|
||||||
|
|
@ -85,14 +86,31 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
|
||||||
}
|
}
|
||||||
|
|
||||||
// CostPerStateByte computes the cost per one byte of state creation
|
// CostPerStateByte computes the cost per one byte of state creation
|
||||||
// after EIP-8037
|
// after EIP-8037.
|
||||||
func CostPerStateByte(header *types.Header, config *params.ChainConfig) uint64 {
|
func CostPerStateByte(header *types.Header, config *params.ChainConfig) uint64 {
|
||||||
if config.IsAmsterdam(header.Number, header.Time) {
|
if !config.IsAmsterdam(header.Number, header.Time) {
|
||||||
return 1174
|
return 0
|
||||||
// TODO (MariusVanDerWijden): for devnet-3 we hardcode the costPerStateByte
|
|
||||||
//return ((header.GasLimit / 2) * 7200 * 365) / params.TargetStateGrowthPerYear
|
|
||||||
}
|
}
|
||||||
return 0
|
const (
|
||||||
|
blocksPerYear uint64 = 2_628_000 // 7200 * 365
|
||||||
|
offset uint64 = 9578
|
||||||
|
significantBts uint64 = 5
|
||||||
|
)
|
||||||
|
numerator := header.GasLimit * blocksPerYear
|
||||||
|
denominator := uint64(2) * params.TargetStateGrowthPerYear
|
||||||
|
raw := (numerator + denominator - 1) / denominator
|
||||||
|
shifted := raw + offset
|
||||||
|
// bit length of shifted
|
||||||
|
bitLen := uint64(64 - bits.LeadingZeros64(shifted))
|
||||||
|
var shift uint64
|
||||||
|
if bitLen > significantBts {
|
||||||
|
shift = bitLen - significantBts
|
||||||
|
}
|
||||||
|
quantized := (shifted >> shift) << shift
|
||||||
|
if quantized > offset {
|
||||||
|
return quantized - offset
|
||||||
|
}
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEVMTxContext creates a new transaction context for a single transaction.
|
// NewEVMTxContext creates a new transaction context for a single transaction.
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,15 @@ func IntrinsicGas(data []byte, accessList types.AccessList, authList []types.Set
|
||||||
} else {
|
} else {
|
||||||
gas.RegularGas = params.TxGas
|
gas.RegularGas = params.TxGas
|
||||||
}
|
}
|
||||||
|
// EIP-8037: authorization tuples contribute both regular and state gas.
|
||||||
|
if authList != nil {
|
||||||
|
if rules.IsAmsterdam {
|
||||||
|
gas.RegularGas += uint64(len(authList)) * params.TxAuthTupleRegularGas
|
||||||
|
gas.StateGas += uint64(len(authList)) * (params.AuthorizationCreationSize + params.AccountCreationSize) * costPerStateByte
|
||||||
|
} else {
|
||||||
|
gas.RegularGas += uint64(len(authList)) * params.TxAuthTupleGas
|
||||||
|
}
|
||||||
|
}
|
||||||
dataLen := uint64(len(data))
|
dataLen := uint64(len(data))
|
||||||
// Bump the required gas by the amount of transactional data
|
// Bump the required gas by the amount of transactional data
|
||||||
if dataLen > 0 {
|
if dataLen > 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue