mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
a few bug fixes and feedback from Gary
Co-authored-by: Gary Rong <garyrong0905@gmail.com>
This commit is contained in:
parent
72efd71981
commit
7fa2327931
6 changed files with 23 additions and 64 deletions
|
|
@ -130,7 +130,7 @@ func (ae *AccessEvents) ContractCreateInitGas(addr []byte, createSendsValue bool
|
||||||
return gas
|
return gas
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTxOrigin adds the member fields of the sender account to the witness,
|
// AddTxOrigin adds the member fields of the sender account to the access event list,
|
||||||
// so that cold accesses are not charged, since they are covered by the 21000 gas.
|
// so that cold accesses are not charged, since they are covered by the 21000 gas.
|
||||||
func (ae *AccessEvents) AddTxOrigin(originAddr []byte) {
|
func (ae *AccessEvents) AddTxOrigin(originAddr []byte) {
|
||||||
for i := utils.VersionLeafKey; i <= utils.CodeSizeLeafKey; i++ {
|
for i := utils.VersionLeafKey; i <= utils.CodeSizeLeafKey; i++ {
|
||||||
|
|
@ -138,11 +138,11 @@ func (ae *AccessEvents) AddTxOrigin(originAddr []byte) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTxDestination adds the member fields of the sender account to the witness,
|
// AddTxDestination adds the member fields of the sender account to the access event list,
|
||||||
// so that cold accesses are not charged, since they are covered by the 21000 gas.
|
// so that cold accesses are not charged, since they are covered by the 21000 gas.
|
||||||
func (ae *AccessEvents) AddTxDestination(targetAddr []byte, sendsValue bool) {
|
func (ae *AccessEvents) AddTxDestination(targetAddr []byte, sendsValue bool) {
|
||||||
for i := utils.VersionLeafKey; i <= utils.CodeSizeLeafKey; i++ {
|
for i := utils.VersionLeafKey; i <= utils.CodeSizeLeafKey; i++ {
|
||||||
ae.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, byte(i), i == utils.VersionLeafKey && sendsValue)
|
ae.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, byte(i), i == utils.BalanceLeafKey && sendsValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,7 +152,7 @@ func (ae *AccessEvents) SlotGas(addr []byte, slot common.Hash, isWrite bool) uin
|
||||||
return ae.touchAddressAndChargeGas(addr, *treeIndex, subIndex, isWrite)
|
return ae.touchAddressAndChargeGas(addr, *treeIndex, subIndex, isWrite)
|
||||||
}
|
}
|
||||||
|
|
||||||
// touchAddressAndChargeGas adds any missing access event to the witness, and returns the cold
|
// touchAddressAndChargeGas adds any missing access event to the access event list, and returns the cold
|
||||||
// access cost to be charged, if need be.
|
// access cost to be charged, if need be.
|
||||||
func (ae *AccessEvents) touchAddressAndChargeGas(addr []byte, treeIndex uint256.Int, subIndex byte, isWrite bool) uint64 {
|
func (ae *AccessEvents) touchAddressAndChargeGas(addr []byte, treeIndex uint256.Int, subIndex byte, isWrite bool) uint64 {
|
||||||
stemRead, selectorRead, stemWrite, selectorWrite, selectorFill := ae.touchAddress(addr, treeIndex, subIndex, isWrite)
|
stemRead, selectorRead, stemWrite, selectorWrite, selectorFill := ae.touchAddress(addr, treeIndex, subIndex, isWrite)
|
||||||
|
|
@ -176,7 +176,7 @@ func (ae *AccessEvents) touchAddressAndChargeGas(addr []byte, treeIndex uint256.
|
||||||
return gas
|
return gas
|
||||||
}
|
}
|
||||||
|
|
||||||
// touchAddress adds any missing access event to the witness.
|
// touchAddress adds any missing access event to the access event list.
|
||||||
func (ae *AccessEvents) touchAddress(addr []byte, treeIndex uint256.Int, subIndex byte, isWrite bool) (bool, bool, bool, bool, bool) {
|
func (ae *AccessEvents) touchAddress(addr []byte, treeIndex uint256.Int, subIndex byte, isWrite bool) (bool, bool, bool, bool, bool) {
|
||||||
branchKey := newBranchAccessKey(addr, treeIndex)
|
branchKey := newBranchAccessKey(addr, treeIndex)
|
||||||
chunkKey := newChunkAccessKey(branchKey, subIndex)
|
chunkKey := newChunkAccessKey(branchKey, subIndex)
|
||||||
|
|
|
||||||
|
|
@ -199,9 +199,6 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat
|
||||||
}
|
}
|
||||||
txctx := NewEVMTxContext(msg)
|
txctx := NewEVMTxContext(msg)
|
||||||
vmenv.Reset(txctx, statedb)
|
vmenv.Reset(txctx, statedb)
|
||||||
if vmenv.ChainConfig().Rules(vmenv.Context.BlockNumber, true, vmenv.Context.Time).IsEIP2929 {
|
|
||||||
statedb.AddAddressToAccessList(params.BeaconRootsAddress)
|
|
||||||
}
|
|
||||||
_, _, _ = vmenv.Call(vm.AccountRef(msg.From), *msg.To, msg.Data, 30_000_000, common.U2560)
|
_, _, _ = vmenv.Call(vm.AccountRef(msg.From), *msg.To, msg.Data, 30_000_000, common.U2560)
|
||||||
statedb.Finalise(true)
|
statedb.Finalise(true)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/tracing"
|
"github.com/ethereum/go-ethereum/core/tracing"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/holiman/uint256"
|
"github.com/holiman/uint256"
|
||||||
)
|
)
|
||||||
|
|
@ -324,42 +323,6 @@ func enable6780(jt *JumpTable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func opCreateEIP4762(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
||||||
if interpreter.readOnly {
|
|
||||||
return nil, ErrWriteProtection
|
|
||||||
}
|
|
||||||
var endowment = scope.Stack.peek()
|
|
||||||
|
|
||||||
contractAddress := crypto.CreateAddress(scope.Contract.Address(), interpreter.evm.StateDB.GetNonce(scope.Contract.Address()))
|
|
||||||
statelessGas := interpreter.evm.AccessEvents.ContractCreateInitGas(contractAddress.Bytes()[:], endowment.Sign() != 0)
|
|
||||||
if !scope.Contract.UseGas(statelessGas, interpreter.evm.Config.Tracer, tracing.GasChangeUnspecified) {
|
|
||||||
return nil, ErrExecutionReverted
|
|
||||||
}
|
|
||||||
|
|
||||||
return opCreate(pc, interpreter, scope)
|
|
||||||
}
|
|
||||||
|
|
||||||
func opCreate2EIP4762(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
||||||
if interpreter.readOnly {
|
|
||||||
return nil, ErrWriteProtection
|
|
||||||
}
|
|
||||||
var (
|
|
||||||
endowment = scope.Stack.Back(0)
|
|
||||||
offset, size = scope.Stack.Back(1), scope.Stack.Back(2)
|
|
||||||
salt = scope.Stack.Back(3)
|
|
||||||
input = scope.Memory.GetCopy(int64(offset.Uint64()), int64(size.Uint64()))
|
|
||||||
)
|
|
||||||
|
|
||||||
codeAndHash := &codeAndHash{code: input}
|
|
||||||
contractAddress := crypto.CreateAddress2(scope.Contract.Address(), salt.Bytes32(), codeAndHash.Hash().Bytes())
|
|
||||||
statelessGas := interpreter.evm.AccessEvents.ContractCreateInitGas(contractAddress.Bytes()[:], endowment.Sign() != 0)
|
|
||||||
if !scope.Contract.UseGas(statelessGas, interpreter.evm.Config.Tracer, tracing.GasChangeUnspecified) {
|
|
||||||
return nil, ErrExecutionReverted
|
|
||||||
}
|
|
||||||
|
|
||||||
return opCreate2(pc, interpreter, scope)
|
|
||||||
}
|
|
||||||
|
|
||||||
func opExtCodeCopyEIP4762(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
func opExtCodeCopyEIP4762(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||||
var (
|
var (
|
||||||
stack = scope.Stack
|
stack = scope.Stack
|
||||||
|
|
@ -506,7 +469,7 @@ func enable4762(jt *JumpTable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
jt[CREATE] = &operation{
|
jt[CREATE] = &operation{
|
||||||
execute: opCreateEIP4762,
|
execute: opCreate,
|
||||||
constantGas: params.CreateNGasEip4762,
|
constantGas: params.CreateNGasEip4762,
|
||||||
dynamicGas: gasCreateEip3860,
|
dynamicGas: gasCreateEip3860,
|
||||||
minStack: minStack(3, 1),
|
minStack: minStack(3, 1),
|
||||||
|
|
@ -515,7 +478,7 @@ func enable4762(jt *JumpTable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
jt[CREATE2] = &operation{
|
jt[CREATE2] = &operation{
|
||||||
execute: opCreate2EIP4762,
|
execute: opCreate2,
|
||||||
constantGas: params.CreateNGasEip4762,
|
constantGas: params.CreateNGasEip4762,
|
||||||
dynamicGas: gasCreate2Eip3860,
|
dynamicGas: gasCreate2Eip3860,
|
||||||
minStack: minStack(4, 1),
|
minStack: minStack(4, 1),
|
||||||
|
|
|
||||||
|
|
@ -394,14 +394,6 @@ func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize
|
||||||
if gas, overflow = math.SafeAdd(gas, memoryGas); overflow {
|
if gas, overflow = math.SafeAdd(gas, memoryGas); overflow {
|
||||||
return 0, ErrGasUintOverflow
|
return 0, ErrGasUintOverflow
|
||||||
}
|
}
|
||||||
|
|
||||||
evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, contract.Gas, gas, stack.Back(0))
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
if gas, overflow = math.SafeAdd(gas, evm.callGasTemp); overflow {
|
|
||||||
return 0, ErrGasUintOverflow
|
|
||||||
}
|
|
||||||
if evm.chainRules.IsEIP4762 {
|
if evm.chainRules.IsEIP4762 {
|
||||||
if transfersValue {
|
if transfersValue {
|
||||||
gas, overflow = math.SafeAdd(gas, evm.AccessEvents.ValueTransferGas(contract.Address().Bytes()[:], address.Bytes()[:]))
|
gas, overflow = math.SafeAdd(gas, evm.AccessEvents.ValueTransferGas(contract.Address().Bytes()[:], address.Bytes()[:]))
|
||||||
|
|
@ -410,6 +402,13 @@ func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, contract.Gas, gas, stack.Back(0))
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if gas, overflow = math.SafeAdd(gas, evm.callGasTemp); overflow {
|
||||||
|
return 0, ErrGasUintOverflow
|
||||||
|
}
|
||||||
|
|
||||||
return gas, nil
|
return gas, nil
|
||||||
}
|
}
|
||||||
|
|
@ -429,13 +428,6 @@ func gasCallCode(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memory
|
||||||
if gas, overflow = math.SafeAdd(gas, memoryGas); overflow {
|
if gas, overflow = math.SafeAdd(gas, memoryGas); overflow {
|
||||||
return 0, ErrGasUintOverflow
|
return 0, ErrGasUintOverflow
|
||||||
}
|
}
|
||||||
evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, contract.Gas, gas, stack.Back(0))
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
if gas, overflow = math.SafeAdd(gas, evm.callGasTemp); overflow {
|
|
||||||
return 0, ErrGasUintOverflow
|
|
||||||
}
|
|
||||||
if evm.chainRules.IsEIP4762 {
|
if evm.chainRules.IsEIP4762 {
|
||||||
address := common.Address(stack.Back(1).Bytes20())
|
address := common.Address(stack.Back(1).Bytes20())
|
||||||
transfersValue := !stack.Back(2).IsZero()
|
transfersValue := !stack.Back(2).IsZero()
|
||||||
|
|
@ -446,6 +438,13 @@ func gasCallCode(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, contract.Gas, gas, stack.Back(0))
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if gas, overflow = math.SafeAdd(gas, evm.callGasTemp); overflow {
|
||||||
|
return 0, ErrGasUintOverflow
|
||||||
|
}
|
||||||
return gas, nil
|
return gas, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter {
|
||||||
var table *JumpTable
|
var table *JumpTable
|
||||||
switch {
|
switch {
|
||||||
case evm.chainRules.IsVerkle:
|
case evm.chainRules.IsVerkle:
|
||||||
// TODO replace with prooper instruction set when fork is specified
|
// TODO replace with proper instruction set when fork is specified
|
||||||
table = &verkleInstructionSet
|
table = &verkleInstructionSet
|
||||||
case evm.chainRules.IsCancun:
|
case evm.chainRules.IsCancun:
|
||||||
table = &cancunInstructionSet
|
table = &cancunInstructionSet
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ func validate(jt JumpTable) JumpTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newVerkleInstructionSet() JumpTable {
|
func newVerkleInstructionSet() JumpTable {
|
||||||
instructionSet := newShanghaiInstructionSet()
|
instructionSet := newCancunInstructionSet()
|
||||||
enable6780(&instructionSet)
|
enable6780(&instructionSet)
|
||||||
enable4762(&instructionSet)
|
enable4762(&instructionSet)
|
||||||
return validate(instructionSet)
|
return validate(instructionSet)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue