Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Stateful v1.11.4 #27

Merged
merged 67 commits into from
May 30, 2023
Merged
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
cc1238a
stateful
Jan 16, 2023
527b51d
use PrecompileExecutor
calbera Jan 18, 2023
fa71e1c
use host terminology
calbera Jan 18, 2023
bd7853d
return precompiledContract and bool
calbera Jan 18, 2023
2e58beb
use ctx in Run instead of statedb
calbera Jan 18, 2023
23abedc
change to ph
Jan 19, 2023
252a807
bing bong
Jan 19, 2023
d024add
rename to runner
calbera Jan 23, 2023
e181e29
rename constructor
calbera Jan 23, 2023
b68f406
new precompile function types
calbera Jan 24, 2023
6738bc9
precompile controller
calbera Jan 24, 2023
c1877f5
make PrecompileController public
calbera Jan 25, 2023
e677eab
ctx setter
calbera Jan 25, 2023
4500de4
add statedb in contract.Run
calbera Jan 25, 2023
52ba783
use Prepare on controller
calbera Jan 25, 2023
1a7ad27
prepare for state transition
calbera Jan 25, 2023
c40db52
contract has registry key
calbera Feb 2, 2023
205de59
has and get
calbera Feb 2, 2023
ddff03c
controller > manager
calbera Feb 2, 2023
c032807
with statedb
calbera Feb 3, 2023
dfc88fb
with ctx
calbera Feb 3, 2023
3bcbe77
simple precompile manager
calbera Feb 6, 2023
d04e4af
allow setting block context to evm
calbera Feb 10, 2023
f7ab8a6
remove unneded evm funcs
calbera Feb 10, 2023
7fde4c9
simplify precompile manager
calbera Feb 16, 2023
553a202
updated go.sum
Feb 17, 2023
9ca5cc4
removing extra bits
Feb 17, 2023
bd59462
typo fixes
Feb 17, 2023
b9c956b
ethapi
Feb 18, 2023
6f9e9af
cleanup precomp manager
calbera Feb 19, 2023
c90cd37
add get chain id
Feb 22, 2023
85c513b
make access list public
calbera Feb 23, 2023
becca16
make access list struct public
calbera Feb 23, 2023
900690c
fix typos
calbera Feb 23, 2023
86a96c5
ethpub
Feb 23, 2023
9fdaf4f
use the StateDB interface in the API
calbera Feb 23, 2023
991a177
make compatible
calbera Feb 24, 2023
d8cad92
fixed merge conflicts
Feb 28, 2023
ec6ffde
Merge pull request #11 from berachain/stateful-test
transmissions12 Feb 28, 2023
f629cbb
remove unecessary vm imports
calbera Feb 28, 2023
364e922
add signature to signer interface
calbera Mar 6, 2023
547360b
fix merge conflicts
calbera Mar 13, 2023
9d914f4
resolve more
calbera Mar 13, 2023
08692ab
get all tests passing
calbera Mar 13, 2023
b18b15f
Merge pull request #14 from berachain/migrate-v1.11.4
calbera Mar 13, 2023
4b0f68e
remove code check for precompiles
calbera Mar 20, 2023
6a08dd2
setup
calbera Mar 20, 2023
db20350
Merge pull request #16 from berachain/add-evm-precompile
calbera Mar 20, 2023
29251e5
disabling m.txsub check (#17)
transmissions12 Mar 21, 2023
e3ca3ff
Disable event check (#18)
transmissions12 Mar 21, 2023
019945f
removing txsSub reference everywhere (#19)
transmissions12 Mar 21, 2023
a71eb94
use GetEVM for tracing txs
calbera Mar 23, 2023
844cad7
check wrapped errors for execution revert
calbera Mar 29, 2023
1dbe903
fix fuzz test compile
calbera Mar 31, 2023
eabc299
remove unneeded print line
calbera Apr 4, 2023
de6c523
check statedb errors
calbera Apr 25, 2023
bf6ba6c
revert #17, #18, #19
calbera Apr 25, 2023
f10e9d8
use precompile manager for active precompiles list
calbera May 8, 2023
367aa06
cleanup
calbera May 8, 2023
d337874
get-block-context
neverDefined May 8, 2023
88564f8
fix read only flag for callcode
calbera May 16, 2023
74b6873
apply tx with evm
May 17, 2023
8e46b86
flashbots: bundle API and mev-geth integration (#24)
shampoobera May 18, 2023
fc19d4f
match applyTransaction function signatures
calbera May 24, 2023
fee9e00
allow reuse of blockhash
calbera May 24, 2023
bbb70ba
graphql registrable
May 29, 2023
37091fd
register filter
May 29, 2023
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
Next Next commit
new precompile function types
  • Loading branch information
calbera authored and t12s committed Feb 28, 2023
commit b68f40663ef1b38248ee80c85f530324c3129a44
49 changes: 27 additions & 22 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,14 @@ type (
GetHashFunc func(uint64) common.Hash
)

// `PrecompileRunner` is allows the EVM to execute a precompiled contract.
type PrecompileRunner interface {
// `Exists` returns if a precompiled contract was found at `addr`.
Exists(addr common.Address) (PrecompiledContract, bool)

// `Run` runs a precompiled contract and returns the leftover gas.
Run(p PrecompiledContract, input []byte, caller common.Address,
value *big.Int, suppliedGas uint64, readonly bool,
) (ret []byte, remainingGas uint64, err error)
}
// `PrecompileExists` returns if a precompiled contract was found at `addr`.
type PrecompileExists func(addr common.Address) (p PrecompiledContract, found bool)

// `RunPrecompile` runs a precompiled contract and returns the remaining gas.
type RunPrecompile func(
p PrecompiledContract, input []byte, caller common.Address,
value *big.Int, suppliedGas uint64, readonly bool,
) (ret []byte, remainingGas uint64, err error)

// BlockContext provides the EVM with auxiliary information. Once provided
// it shouldn't be modified.
Expand Down Expand Up @@ -95,8 +93,11 @@ type EVM struct {
TxContext
// StateDB gives access to the underlying state
StateDB StateDB
// precompileRunner gives access to the precompiled contracts
precompileRunner PrecompileRunner
// precompileExists searches an address for a precompiled
// contract
precompileExists PrecompileExists
// runPrecompile gives access running a precompiled contract
runPrecompile RunPrecompile
// Depth is the current call stack
depth int

Expand Down Expand Up @@ -134,9 +135,13 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig
return evm
}

func NewEVMWithPrecompiles(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig *params.ChainConfig, config Config, precompileRunner PrecompileRunner) *EVM {
func NewEVMWithPrecompiles(
blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig *params.ChainConfig,
config Config, precompileExists PrecompileExists, runPrecompile RunPrecompile,
) *EVM {
evm := NewEVM(blockCtx, txCtx, statedb, chainConfig, config)
evm.precompileRunner = precompileRunner
evm.precompileExists = precompileExists
evm.runPrecompile = runPrecompile
return evm
}

Expand Down Expand Up @@ -185,7 +190,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
return nil, gas, ErrInsufficientBalance
}
snapshot := evm.StateDB.Snapshot()
p, isPrecompile := evm.precompileRunner.Exists(addr)
p, isPrecompile := evm.precompileExists(addr)

if !evm.StateDB.Exist(addr) {
if !isPrecompile && evm.chainRules.IsEIP158 && value.Sign() == 0 {
Expand Down Expand Up @@ -222,7 +227,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
}

if isPrecompile {
ret, gas, err = evm.precompileRunner.Run(p, input, caller.Address(), value, gas, false)
ret, gas, err = evm.runPrecompile(p, input, caller.Address(), value, gas, false)
} else {
// Initialise a new contract and set the code that is to be used by the EVM.
// The contract is a scoped environment for this execution context only.
Expand Down Expand Up @@ -284,8 +289,8 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
}

// It is allowed to call precompiles, even via delegatecall
if p, isPrecompile := evm.precompileRunner.Exists(addr); isPrecompile {
ret, gas, err = evm.precompileRunner.Run(p, input, caller.Address(), value, gas, true)
if p, isPrecompile := evm.precompileExists(addr); isPrecompile {
ret, gas, err = evm.runPrecompile(p, input, caller.Address(), value, gas, true)
} else {
addrCopy := addr
// Initialise a new contract and set the code that is to be used by the EVM.
Expand Down Expand Up @@ -329,9 +334,9 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
}

// It is allowed to call precompiles, even via delegatecall
if p, isPrecompile := evm.precompileRunner.Exists(addr); isPrecompile {
if p, isPrecompile := evm.precompileExists(addr); isPrecompile {
parent := caller.(*Contract)
ret, gas, err = evm.precompileRunner.Run(p, input, parent.CallerAddress, parent.value, gas, false)
ret, gas, err = evm.runPrecompile(p, input, parent.CallerAddress, parent.value, gas, false)
} else {
addrCopy := addr
// Initialise a new contract and make initialise the delegate values
Expand Down Expand Up @@ -379,8 +384,8 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
}(gas)
}

if p, isPrecompile := evm.precompileRunner.Exists(addr); isPrecompile {
ret, gas, err = evm.precompileRunner.Run(p, input, caller.Address(), new(big.Int), gas, true)
if p, isPrecompile := evm.precompileExists(addr); isPrecompile {
ret, gas, err = evm.runPrecompile(p, input, caller.Address(), new(big.Int), gas, true)
} else {
// At this point, we use a copy of address. If we don't, the go compiler will
// leak the 'contract' to the outer scope, and make allocation for 'contract'
Expand Down