Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Witness charging order with limits #502

Merged
merged 38 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
60ed072
state: access witness with partial cost charging
jsign Sep 12, 2024
ab90f4c
fix most problems
jsign Sep 12, 2024
f1c6f05
rebase fixes
jsign Sep 12, 2024
88cd5cf
fixes
jsign Sep 16, 2024
3138345
fixes
jsign Sep 16, 2024
711d8a1
.
jsign Sep 16, 2024
3ec64b5
remove 4762 gas call wrappers
jsign Sep 19, 2024
628842b
more progress
jsign Sep 19, 2024
89e6155
call gas
jsign Sep 19, 2024
33f8fe1
fix
jsign Sep 19, 2024
246105c
fix
jsign Sep 19, 2024
84f6792
fix
jsign Sep 19, 2024
65880c7
fix
jsign Sep 19, 2024
95a5d65
fix
jsign Sep 19, 2024
14b5b69
fix
jsign Sep 19, 2024
4dc1913
fix
jsign Sep 19, 2024
82f36b3
fix
jsign Sep 19, 2024
89662eb
fix
jsign Sep 20, 2024
e1a70f0
simplify warm costs
jsign Sep 23, 2024
313ef15
cleanup
jsign Sep 25, 2024
c99a94f
commit statedb
jsign Sep 27, 2024
36d4c27
pass upper bound for gas consumption
gballet Sep 24, 2024
cb26a96
fix missing gas sum
jsign Sep 25, 2024
1ee921b
fix: warm storage cost for basic data and code hash
gballet Sep 25, 2024
e4c5d26
fix: return wanted in TouchBasicData gas functions
gballet Sep 25, 2024
e6ce883
fix
jsign Sep 25, 2024
9886ea9
fix: add history contract to TestProcessorVerkle
gballet Sep 27, 2024
7ce760d
ci: new workflows for testing (#504)
jsign Oct 8, 2024
45e2f6c
import fixes from base branch until 51dca93bb04a4f93a2be9422a56ee8ea9…
gballet Oct 11, 2024
c0ba8e5
fix: create init order redux (#510)
gballet Oct 15, 2024
21c73d1
import most changes from jsign-witness-fix
gballet Oct 22, 2024
2ebc8e8
rebase nits
jsign Oct 22, 2024
da72c04
fix: move 1/64 before gas call
gballet Oct 22, 2024
f3abb68
fix: value transfer gas charge before 1/64th + warm costs for precomp…
gballet Oct 22, 2024
a9b0e68
Filling fixes (#516)
jsign Oct 23, 2024
87408a7
nit
jsign Oct 23, 2024
b5f8705
fix compilation error
jsign Oct 23, 2024
99b78be
Fill fixes continued (#519)
jsign Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fill fixes continued (#519)
* fix selfdestruct

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* extcodecopy witness fix

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* blockhash fix

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* run ci

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* Apply suggestions from code review

remove diff used for test

* same thing in other file

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
  • Loading branch information
jsign and gballet authored Oct 24, 2024
commit 99b78be5e7eb206cbe6a2dcd31e481b7eeb15ee2
7 changes: 3 additions & 4 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/binary"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -459,11 +458,11 @@ func opGasprice(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([
return nil, nil
}

func getBlockHashFromContract(number uint64, statedb StateDB, witness *state.AccessWitness) (common.Hash, uint64) {
func getBlockHashFromContract(number uint64, statedb StateDB, witness *state.AccessWitness, availableGas uint64) (common.Hash, uint64) {
ringIndex := number % params.Eip2935BlockHashHistorySize
var pnum common.Hash
binary.BigEndian.PutUint64(pnum[24:], ringIndex)
statelessGas := witness.TouchSlotAndChargeGas(params.HistoryStorageAddress[:], pnum, false, math.MaxUint64, false)
statelessGas := witness.TouchSlotAndChargeGas(params.HistoryStorageAddress[:], pnum, false, availableGas, false)
return statedb.GetState(params.HistoryStorageAddress, pnum), statelessGas
}

Expand All @@ -487,7 +486,7 @@ func opBlockhash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) (
if num64 >= lower && num64 < upper {
// if Verkle is active, read it from the history contract (EIP 2935).
if evm.chainRules.IsVerkle {
blockHash, statelessGas := getBlockHashFromContract(num64, evm.StateDB, evm.Accesses)
blockHash, statelessGas := getBlockHashFromContract(num64, evm.StateDB, evm.Accesses, scope.Contract.Gas)
if interpreter.evm.chainRules.IsEIP4762 {
if !scope.Contract.UseGas(statelessGas) {
return nil, ErrOutOfGas
Expand Down
34 changes: 24 additions & 10 deletions core/vm/operations_verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ func gasSelfdestructEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Mem
beneficiaryAddr := common.Address(stack.peek().Bytes20())
contractAddr := contract.Address()

statelessGas := evm.Accesses.TouchBasicData(contractAddr[:], false, contract.Gas, false)
wanted := evm.Accesses.TouchBasicData(contractAddr[:], false, contract.Gas, false)
if wanted > contract.Gas {
return wanted, nil
}
statelessGas := wanted

balanceIsZero := evm.StateDB.GetBalance(contractAddr).Sign() == 0
_, isPrecompile := evm.precompile(beneficiaryAddr)
isSystemContract := evm.isSystemContract(beneficiaryAddr)
Expand All @@ -121,21 +126,30 @@ func gasSelfdestructEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Mem
}

if contractAddr != beneficiaryAddr {
statelessGas += evm.Accesses.TouchBasicData(beneficiaryAddr[:], false, contract.Gas-statelessGas, false)
wanted := evm.Accesses.TouchBasicData(beneficiaryAddr[:], false, contract.Gas-statelessGas, false)
if wanted > contract.Gas-statelessGas {
return statelessGas + wanted, nil
}
statelessGas += wanted
}
// Charge write costs if it transfers value
if !balanceIsZero {
statelessGas += evm.Accesses.TouchBasicData(contractAddr[:], true, contract.Gas-statelessGas, false)
wanted := evm.Accesses.TouchBasicData(contractAddr[:], true, contract.Gas-statelessGas, false)
if wanted > contract.Gas-statelessGas {
return statelessGas + wanted, nil
}
statelessGas += wanted

if contractAddr != beneficiaryAddr {
if evm.StateDB.Exist(beneficiaryAddr) {
statelessGas += evm.Accesses.TouchBasicData(beneficiaryAddr[:], true, contract.Gas-statelessGas, false)
wanted = evm.Accesses.TouchBasicData(beneficiaryAddr[:], true, contract.Gas-statelessGas, false)
} else {
wanted := evm.Accesses.TouchFullAccount(beneficiaryAddr[:], true, contract.Gas-statelessGas)
if wanted > contract.Gas-statelessGas {
return statelessGas + wanted, nil
}
statelessGas += wanted
wanted = evm.Accesses.TouchFullAccount(beneficiaryAddr[:], true, contract.Gas-statelessGas)
}
if wanted > contract.Gas-statelessGas {
return statelessGas + wanted, nil
}
statelessGas += wanted
}
}
return statelessGas, nil
Expand All @@ -158,7 +172,7 @@ func gasExtCodeCopyEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Memo
}
return gas, nil
}
wgas := evm.Accesses.TouchBasicData(addr[:], false, contract.Gas, true)
wgas := evm.Accesses.TouchBasicData(addr[:], false, contract.Gas-gas, true)
var overflow bool
if gas, overflow = math.SafeAdd(gas, wgas); overflow {
return 0, ErrGasUintOverflow
Expand Down
Loading