Skip to content

Commit

Permalink
Filling fixes (#516)
Browse files Browse the repository at this point in the history
* fix makeCallVariantGasEIP4762

Signed-off-by: Ignacio Hagopian <[email protected]>

* fix

Signed-off-by: Ignacio Hagopian <[email protected]>

* fix

Signed-off-by: Ignacio Hagopian <[email protected]>

* fix

Signed-off-by: Ignacio Hagopian <[email protected]>

* ci: target v0.0.6

Signed-off-by: Ignacio Hagopian <[email protected]>

* improve fix

Signed-off-by: Ignacio Hagopian <[email protected]>

* add witness gas to "old" gas upon error

Signed-off-by: Guillaume Ballet <[email protected]>

* workflow: remove target branch from list of branches

---------

Signed-off-by: Ignacio Hagopian <[email protected]>
Signed-off-by: Guillaume Ballet <[email protected]>
Co-authored-by: Guillaume Ballet <[email protected]>
  • Loading branch information
jsign and gballet authored Oct 23, 2024
1 parent f855ec5 commit d2e5de3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stable-spec-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:

env:
FIXTURES_TAG: "[email protected].5"
FIXTURES_TAG: "[email protected].6"

jobs:
setup:
Expand Down
2 changes: 1 addition & 1 deletion core/state/access_witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (aw *AccessWitness) TouchFullAccount(addr []byte, isWrite bool, availableGa
for i := utils.BasicDataLeafKey; i <= utils.CodeHashLeafKey; i++ {
consumed, wanted := aw.touchAddressAndChargeGas(addr, zeroTreeIndex, byte(i), isWrite, availableGas)
if consumed < wanted {
return wanted
return wanted + gas
}
availableGas -= consumed
gas += consumed
Expand Down
50 changes: 25 additions & 25 deletions core/vm/operations_verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,58 +53,58 @@ func gasExtCodeHash4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory,
return evm.Accesses.TouchCodeHash(address[:], false, contract.Gas, true), nil
}

func makeCallVariantGasEIP4762(oldCalculator gasFunc) gasFunc {
func makeCallVariantGasEIP4762(oldCalculator gasFunc, withTransferCosts bool) gasFunc {
return func(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
var (
target = common.Address(stack.Back(1).Bytes20())
transfersValue = !stack.Back(2).IsZero()
witnessGas uint64
_, isPrecompile = evm.precompile(target)
isSystemContract = evm.isSystemContract(target)
)

// If value is transferred, it is charged before 1/64th
// is subtracted from the available gas pool.
if transfersValue {
if withTransferCosts && !stack.Back(2).IsZero() {
wantedValueTransferWitnessGas := evm.Accesses.TouchAndChargeValueTransfer(contract.Address().Bytes()[:], target[:], contract.Gas)
if wantedValueTransferWitnessGas > contract.Gas {
return wantedValueTransferWitnessGas, nil
}
witnessGas = wantedValueTransferWitnessGas
} else if isPrecompile || isSystemContract {
witnessGas = params.WarmStorageReadCostEIP2929
} else {
// The charging for the value transfer is done BEFORE subtracting
// the 1/64th gas, as this is considered part of the CALL instruction.
// (so before we get to this point)
// But the message call is part of the subcall, for which only 63/64th
// of the gas should be available.
wantedMessageCallWitnessGas := evm.Accesses.TouchAndChargeMessageCall(target.Bytes(), contract.Gas-witnessGas)
var overflow bool
if witnessGas, overflow = math.SafeAdd(witnessGas, wantedMessageCallWitnessGas); overflow {
return 0, ErrGasUintOverflow
}
if witnessGas > contract.Gas {
return witnessGas, nil
}
}

// The charging for the value transfer is done BEFORE subtracting
// the 1/64th gas, as this is considered part of the CALL instruction.
// (so before we get to this point)
// But the message call is part of the subcall, for which only 63/64th
// of the gas should be available.
wantedMessageCallWitnessGas := evm.Accesses.TouchAndChargeMessageCall(target.Bytes(), contract.Gas-witnessGas)
var overflow bool
if witnessGas, overflow = math.SafeAdd(witnessGas, wantedMessageCallWitnessGas); overflow {
return 0, ErrGasUintOverflow
}
if witnessGas > contract.Gas {
return witnessGas, nil
}

contract.Gas -= witnessGas
// if the operation fails, adds witness gas to the gas before returning the error
gas, err := oldCalculator(evm, contract, stack, mem, memorySize)
if err != nil {
return 0, err
}
contract.Gas += witnessGas // restore witness gas so that it can be charged at the callsite
var overflow bool
if gas, overflow = math.SafeAdd(gas, witnessGas); overflow {
return 0, ErrGasUintOverflow
}
return gas, nil
return gas, err
}
}

var (
gasCallEIP4762 = makeCallVariantGasEIP4762(gasCall)
gasCallCodeEIP4762 = makeCallVariantGasEIP4762(gasCallCode)
gasStaticCallEIP4762 = makeCallVariantGasEIP4762(gasStaticCall)
gasDelegateCallEIP4762 = makeCallVariantGasEIP4762(gasDelegateCall)
gasCallEIP4762 = makeCallVariantGasEIP4762(gasCall, true)
gasCallCodeEIP4762 = makeCallVariantGasEIP4762(gasCallCode, false)
gasStaticCallEIP4762 = makeCallVariantGasEIP4762(gasStaticCall, false)
gasDelegateCallEIP4762 = makeCallVariantGasEIP4762(gasDelegateCall, false)
)

func gasSelfdestructEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
Expand Down

0 comments on commit d2e5de3

Please sign in to comment.