Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign committed Sep 19, 2024
1 parent 81940b9 commit 09be3aa
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,28 +760,6 @@ func opCreate2(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]
}

func chargeCallVariantEIP4762(evm *EVM, scope *ScopeContext) bool {
if evm.chainRules.IsEIP4762 {
address := common.Address(scope.Stack.Back(1).Bytes20())
transfersValue := !scope.Stack.Back(2).IsZero()

// If value is transferred, it is charged before 1/64th
// is subtracted from the available gas pool.
if transfersValue {
if !evm.Accesses.TouchAndChargeValueTransfer(scope.Contract.Address().Bytes()[:], address.Bytes()[:], scope.Contract.UseGas) {
return false
}
}
}

var err error
evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, scope.Contract.Gas, 0, scope.Stack.Back(0))
if err != nil {
return false
}
if !scope.Contract.UseGas(evm.callGasTemp) {
return false
}

target := common.Address(scope.Stack.Back(1).Bytes20())
if _, isPrecompile := evm.precompile(target); isPrecompile {
return true
Expand All @@ -800,6 +778,27 @@ func chargeCallVariantEIP4762(evm *EVM, scope *ScopeContext) bool {
}

func opCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
if interpreter.evm.chainRules.IsEIP4762 {
address := common.Address(scope.Stack.Back(1).Bytes20())
transfersValue := !scope.Stack.Back(2).IsZero()

// If value is transferred, it is charged before 1/64th
// is subtracted from the available gas pool.
if transfersValue {
if !interpreter.evm.Accesses.TouchAndChargeValueTransfer(scope.Contract.Address().Bytes()[:], address.Bytes()[:], scope.Contract.UseGas) {
return nil, ErrExecutionReverted
}
}
}

var err error
interpreter.evm.callGasTemp, err = callGas(interpreter.evm.chainRules.IsEIP150, scope.Contract.Gas, 0, scope.Stack.Back(0))
if err != nil {
return nil, err
}
if !scope.Contract.UseGas(interpreter.evm.callGasTemp) {
return nil, ErrOutOfGas
}
if !chargeCallVariantEIP4762(interpreter.evm, scope) {
return nil, ErrExecutionReverted
}
Expand Down

0 comments on commit 09be3aa

Please sign in to comment.