Use IsCancun where applicable (#56)
* replace Accesses != nil with IsCancun(...) * fix
This commit is contained in:
@ -304,7 +304,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
|
|||||||
if st.gas < gas {
|
if st.gas < gas {
|
||||||
return nil, fmt.Errorf("%w: have %d, want %d", ErrIntrinsicGas, st.gas, gas)
|
return nil, fmt.Errorf("%w: have %d, want %d", ErrIntrinsicGas, st.gas, gas)
|
||||||
}
|
}
|
||||||
if st.evm.Accesses != nil {
|
if st.evm.ChainConfig().IsCancun(st.evm.Context.BlockNumber) {
|
||||||
if msg.To() != nil {
|
if msg.To() != nil {
|
||||||
toBalance := trieUtils.GetTreeKeyBalance(msg.To().Bytes())
|
toBalance := trieUtils.GetTreeKeyBalance(msg.To().Bytes())
|
||||||
pre := st.state.GetBalance(*msg.To())
|
pre := st.state.GetBalance(*msg.To())
|
||||||
|
@ -243,7 +243,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
|
|||||||
if len(code) == 0 {
|
if len(code) == 0 {
|
||||||
ret, err = nil, nil // gas is unchanged
|
ret, err = nil, nil // gas is unchanged
|
||||||
} else {
|
} else {
|
||||||
if evm.Accesses != nil {
|
if evm.chainConfig.IsCancun(evm.Context.BlockNumber) {
|
||||||
// Touch the account data
|
// Touch the account data
|
||||||
var data [32]byte
|
var data [32]byte
|
||||||
evm.Accesses.TouchAddress(utils.GetTreeKeyVersion(addr.Bytes()), data[:])
|
evm.Accesses.TouchAddress(utils.GetTreeKeyVersion(addr.Bytes()), data[:])
|
||||||
|
@ -97,7 +97,7 @@ var (
|
|||||||
func gasExtCodeSize(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
func gasExtCodeSize(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
||||||
usedGas := uint64(0)
|
usedGas := uint64(0)
|
||||||
slot := stack.Back(0)
|
slot := stack.Back(0)
|
||||||
if evm.Accesses != nil {
|
if evm.chainConfig.IsCancun(evm.Context.BlockNumber) {
|
||||||
index := trieUtils.GetTreeKeyCodeSize(slot.Bytes())
|
index := trieUtils.GetTreeKeyCodeSize(slot.Bytes())
|
||||||
usedGas += evm.TxContext.Accesses.TouchAddressAndChargeGas(index, nil)
|
usedGas += evm.TxContext.Accesses.TouchAddressAndChargeGas(index, nil)
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ func gasExtCodeSize(evm *EVM, contract *Contract, stack *Stack, mem *Memory, mem
|
|||||||
|
|
||||||
func gasCodeCopy(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
func gasCodeCopy(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
||||||
var statelessGas uint64
|
var statelessGas uint64
|
||||||
if evm.Accesses != nil {
|
if evm.chainConfig.IsCancun(evm.Context.BlockNumber) {
|
||||||
var (
|
var (
|
||||||
codeOffset = stack.Back(1)
|
codeOffset = stack.Back(1)
|
||||||
length = stack.Back(2)
|
length = stack.Back(2)
|
||||||
@ -129,7 +129,7 @@ func gasCodeCopy(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memory
|
|||||||
|
|
||||||
func gasExtCodeCopy(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
func gasExtCodeCopy(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
||||||
var statelessGas uint64
|
var statelessGas uint64
|
||||||
if evm.Accesses != nil {
|
if evm.chainConfig.IsCancun(evm.Context.BlockNumber) {
|
||||||
var (
|
var (
|
||||||
codeOffset = stack.Back(2)
|
codeOffset = stack.Back(2)
|
||||||
length = stack.Back(3)
|
length = stack.Back(3)
|
||||||
@ -158,7 +158,7 @@ func gasExtCodeCopy(evm *EVM, contract *Contract, stack *Stack, mem *Memory, mem
|
|||||||
func gasSLoad(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
func gasSLoad(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
||||||
usedGas := uint64(0)
|
usedGas := uint64(0)
|
||||||
|
|
||||||
if evm.Accesses != nil {
|
if evm.chainConfig.IsCancun(evm.Context.BlockNumber) {
|
||||||
where := stack.Back(0)
|
where := stack.Back(0)
|
||||||
addr := contract.Address()
|
addr := contract.Address()
|
||||||
index := trieUtils.GetTreeKeyStorageSlot(addr[:], where)
|
index := trieUtils.GetTreeKeyStorageSlot(addr[:], where)
|
||||||
@ -408,7 +408,7 @@ func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize
|
|||||||
transfersValue = !stack.Back(2).IsZero()
|
transfersValue = !stack.Back(2).IsZero()
|
||||||
address = common.Address(stack.Back(1).Bytes20())
|
address = common.Address(stack.Back(1).Bytes20())
|
||||||
)
|
)
|
||||||
if evm.Accesses != nil {
|
if evm.chainConfig.IsCancun(evm.Context.BlockNumber) {
|
||||||
// Charge witness costs
|
// Charge witness costs
|
||||||
for i := trieUtils.VersionLeafKey; i <= trieUtils.CodeSizeLeafKey; i++ {
|
for i := trieUtils.VersionLeafKey; i <= trieUtils.CodeSizeLeafKey; i++ {
|
||||||
index := trieUtils.GetTreeKeyAccountLeaf(address[:], byte(i))
|
index := trieUtils.GetTreeKeyAccountLeaf(address[:], byte(i))
|
||||||
|
@ -343,7 +343,7 @@ func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeConte
|
|||||||
func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||||
slot := scope.Stack.peek()
|
slot := scope.Stack.peek()
|
||||||
cs := uint64(interpreter.evm.StateDB.GetCodeSize(slot.Bytes20()))
|
cs := uint64(interpreter.evm.StateDB.GetCodeSize(slot.Bytes20()))
|
||||||
if interpreter.evm.Accesses != nil {
|
if interpreter.evm.chainConfig.IsCancun(interpreter.evm.Context.BlockNumber) {
|
||||||
index := trieUtils.GetTreeKeyCodeSize(slot.Bytes())
|
index := trieUtils.GetTreeKeyCodeSize(slot.Bytes())
|
||||||
statelessGas := interpreter.evm.Accesses.TouchAddressAndChargeGas(index, uint256.NewInt(cs).Bytes())
|
statelessGas := interpreter.evm.Accesses.TouchAddressAndChargeGas(index, uint256.NewInt(cs).Bytes())
|
||||||
scope.Contract.UseGas(statelessGas)
|
scope.Contract.UseGas(statelessGas)
|
||||||
@ -371,7 +371,7 @@ func opCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([
|
|||||||
}
|
}
|
||||||
|
|
||||||
paddedCodeCopy, copyOffset, nonPaddedCopyLength := getDataAndAdjustedBounds(scope.Contract.Code, uint64CodeOffset, length.Uint64())
|
paddedCodeCopy, copyOffset, nonPaddedCopyLength := getDataAndAdjustedBounds(scope.Contract.Code, uint64CodeOffset, length.Uint64())
|
||||||
if interpreter.evm.Accesses != nil {
|
if interpreter.evm.chainConfig.IsCancun(interpreter.evm.Context.BlockNumber) {
|
||||||
touchEachChunksAndChargeGas(copyOffset, nonPaddedCopyLength, scope.Contract.Address().Bytes()[:], scope.Contract.Code, scope.Contract, interpreter.evm.Accesses)
|
touchEachChunksAndChargeGas(copyOffset, nonPaddedCopyLength, scope.Contract.Address().Bytes()[:], scope.Contract.Code, scope.Contract, interpreter.evm.Accesses)
|
||||||
}
|
}
|
||||||
scope.Memory.Set(memOffset.Uint64(), uint64(len(paddedCodeCopy)), paddedCodeCopy)
|
scope.Memory.Set(memOffset.Uint64(), uint64(len(paddedCodeCopy)), paddedCodeCopy)
|
||||||
@ -466,7 +466,7 @@ func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
|
|||||||
uint64CodeOffset = 0xffffffffffffffff
|
uint64CodeOffset = 0xffffffffffffffff
|
||||||
}
|
}
|
||||||
addr := common.Address(a.Bytes20())
|
addr := common.Address(a.Bytes20())
|
||||||
if interpreter.evm.Accesses != nil {
|
if interpreter.evm.chainConfig.IsCancun(interpreter.evm.Context.BlockNumber) {
|
||||||
code := interpreter.evm.StateDB.GetCode(addr)
|
code := interpreter.evm.StateDB.GetCode(addr)
|
||||||
paddedCodeCopy, copyOffset, nonPaddedCopyLength := getDataAndAdjustedBounds(code, uint64CodeOffset, length.Uint64())
|
paddedCodeCopy, copyOffset, nonPaddedCopyLength := getDataAndAdjustedBounds(code, uint64CodeOffset, length.Uint64())
|
||||||
cb := codeBitmap(code)
|
cb := codeBitmap(code)
|
||||||
@ -604,7 +604,7 @@ func opSload(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by
|
|||||||
val := interpreter.evm.StateDB.GetState(scope.Contract.Address(), hash)
|
val := interpreter.evm.StateDB.GetState(scope.Contract.Address(), hash)
|
||||||
loc.SetBytes(val.Bytes())
|
loc.SetBytes(val.Bytes())
|
||||||
|
|
||||||
if interpreter.evm.Accesses != nil {
|
if interpreter.evm.chainConfig.IsCancun(interpreter.evm.Context.BlockNumber) {
|
||||||
index := trieUtils.GetTreeKeyStorageSlot(scope.Contract.Address().Bytes(), loc)
|
index := trieUtils.GetTreeKeyStorageSlot(scope.Contract.Address().Bytes(), loc)
|
||||||
interpreter.evm.Accesses.TouchAddressAndChargeGas(index, val.Bytes())
|
interpreter.evm.Accesses.TouchAddressAndChargeGas(index, val.Bytes())
|
||||||
}
|
}
|
||||||
@ -933,7 +933,7 @@ func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by
|
|||||||
if *pc < codeLen {
|
if *pc < codeLen {
|
||||||
scope.Stack.push(integer.SetUint64(uint64(scope.Contract.Code[*pc])))
|
scope.Stack.push(integer.SetUint64(uint64(scope.Contract.Code[*pc])))
|
||||||
|
|
||||||
if interpreter.evm.Accesses != nil && *pc%31 == 0 {
|
if interpreter.evm.chainConfig.IsCancun(interpreter.evm.Context.BlockNumber) && *pc%31 == 0 {
|
||||||
// touch next chunk if PUSH1 is at the boundary. if so, *pc has
|
// touch next chunk if PUSH1 is at the boundary. if so, *pc has
|
||||||
// advanced past this boundary.
|
// advanced past this boundary.
|
||||||
|
|
||||||
@ -975,7 +975,7 @@ func makePush(size uint64, pushByteSize int) executionFunc {
|
|||||||
endMin = startMin + pushByteSize
|
endMin = startMin + pushByteSize
|
||||||
}
|
}
|
||||||
|
|
||||||
if interpreter.evm.Accesses != nil {
|
if interpreter.evm.chainConfig.IsCancun(interpreter.evm.Context.BlockNumber) {
|
||||||
statelessGas := touchEachChunksAndChargeGas(uint64(startMin), uint64(pushByteSize), scope.Contract.Address().Bytes()[:], scope.Contract.Code, scope.Contract, interpreter.evm.Accesses)
|
statelessGas := touchEachChunksAndChargeGas(uint64(startMin), uint64(pushByteSize), scope.Contract.Address().Bytes()[:], scope.Contract.Code, scope.Contract, interpreter.evm.Accesses)
|
||||||
scope.Contract.UseGas(statelessGas)
|
scope.Contract.UseGas(statelessGas)
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
|
|||||||
logged, pcCopy, gasCopy = false, pc, contract.Gas
|
logged, pcCopy, gasCopy = false, pc, contract.Gas
|
||||||
}
|
}
|
||||||
|
|
||||||
if in.evm.TxContext.Accesses != nil && !contract.IsDeployment {
|
if in.evm.ChainConfig().IsCancun(in.evm.Context.BlockNumber) && !contract.IsDeployment {
|
||||||
// if the PC ends up in a new "page" of verkleized code, charge the
|
// if the PC ends up in a new "page" of verkleized code, charge the
|
||||||
// associated witness costs.
|
// associated witness costs.
|
||||||
contract.Gas -= touchEachChunksAndChargeGas(pc, 1, contract.Address().Bytes()[:], contract.Code, contract, in.evm.TxContext.Accesses)
|
contract.Gas -= touchEachChunksAndChargeGas(pc, 1, contract.Address().Bytes()[:], contract.Code, contract, in.evm.TxContext.Accesses)
|
||||||
|
Reference in New Issue
Block a user