Skip to content

Commit d710632

Browse files
author
Darioush Jalali
committed
xxx: temporary workarounds
1 parent cb7447e commit d710632

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

core/vm/contracts.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/ethereum/go-ethereum/crypto/bls12381"
3131
"github.com/ethereum/go-ethereum/crypto/bn256"
3232
"github.com/ethereum/go-ethereum/crypto/kzg4844"
33+
"github.com/ethereum/go-ethereum/libevm"
3334
"github.com/ethereum/go-ethereum/params"
3435
"golang.org/x/crypto/ripemd160"
3536
)
@@ -163,12 +164,29 @@ func ActivePrecompiles(rules params.Rules) []common.Address {
163164
}
164165
}
165166

167+
type statefulPrecompileIntf interface {
168+
RunExtra(
169+
chainConifg *params.ChainConfig,
170+
blockNumber *big.Int, blockTime uint64,
171+
predicateResults libevm.PredicateResults,
172+
_ libevm.StateDB, _ *params.Rules, caller, self common.Address, input []byte, suppliedGas uint64, readOnly bool) ([]byte, uint64, error)
173+
}
174+
166175
// RunPrecompiledContract runs and evaluates the output of a precompiled contract.
167176
// It returns
168177
// - the returned bytes,
169178
// - the _remaining_ gas,
170179
// - any error that occurred
171180
func (args *evmCallArgs) RunPrecompiledContract(p PrecompiledContract, input []byte, suppliedGas uint64) (ret []byte, remainingGas uint64, err error) {
181+
if p, ok := p.(statefulPrecompileIntf); ok {
182+
return p.RunExtra(
183+
args.evm.chainConfig,
184+
args.evm.Context.BlockNumber,
185+
args.evm.Context.Time,
186+
args.evm.Context.PredicateResults,
187+
args.evm.StateDB, &args.evm.chainRules, args.caller.Address(), args.addr, input,
188+
suppliedGas, args.evm.interpreter.readOnly)
189+
}
172190
gasCost := p.RequiredGas(input)
173191
if suppliedGas < gasCost {
174192
return nil, 0, ErrOutOfGas

core/vm/evm.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ type BlockContext struct {
7979
BaseFee *big.Int // Provides information for BASEFEE (0 if vm runs with NoBaseFee flag and 0 gas price)
8080
BlobBaseFee *big.Int // Provides information for BLOBBASEFEE (0 if vm runs with NoBaseFee flag and 0 blob gas price)
8181
Random *common.Hash // Provides information for PREVRANDAO
82+
83+
PredicateResults libevm.PredicateResults
8284
}
8385

8486
// TxContext provides the EVM with information about a transaction.

core/vm/interpreter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ type EVMInterpreter struct {
5555
func NewEVMInterpreter(evm *EVM) *EVMInterpreter {
5656
// If jump table was not initialised we set the default one.
5757
var table *JumpTable
58+
customTable := evm.chainRules.Hooks().JumpTable()
5859
switch {
60+
case customTable != nil:
61+
table = customTable.(*JumpTable)
5962
case evm.chainRules.IsCancun:
6063
table = &cancunInstructionSet
6164
case evm.chainRules.IsShanghai:

core/vm/jump_table_ext.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// (c) 2023, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package vm
5+
6+
var (
7+
SubnetEVMInstructionSet = newSubnetEVMInstructionSet()
8+
SubnetEVMDurangoInstructionSet = newSubnetEVMDurangoInstructionSet()
9+
SubnetEVMCancunInstructionSet = newSubnetEVMCancunInstructionSet()
10+
)
11+
12+
func newSubnetEVMCancunInstructionSet() JumpTable {
13+
instructionSet := newSubnetEVMDurangoInstructionSet()
14+
enable4844(&instructionSet) // EIP-4844 (BLOBHASH opcode)
15+
enable7516(&instructionSet) // EIP-7516 (BLOBBASEFEE opcode)
16+
enable1153(&instructionSet) // EIP-1153 "Transient Storage"
17+
enable5656(&instructionSet) // EIP-5656 (MCOPY opcode)
18+
enable6780(&instructionSet) // EIP-6780 SELFDESTRUCT only in same transaction
19+
return validate(instructionSet)
20+
}
21+
22+
// newDurangoInstructionSet returns the frontier, homestead, byzantium,
23+
// constantinople, istanbul, petersburg, subnet-evm, durango instructions.
24+
func newSubnetEVMDurangoInstructionSet() JumpTable {
25+
instructionSet := newSubnetEVMInstructionSet()
26+
enable3855(&instructionSet) // PUSH0 instruction
27+
enable3860(&instructionSet) // Limit and meter initcode
28+
29+
return validate(instructionSet)
30+
}
31+
32+
// newSubnetEVMInstructionSet returns the frontier, homestead, byzantium,
33+
// constantinople, istanbul, petersburg, subnet-evm instructions.
34+
func newSubnetEVMInstructionSet() JumpTable {
35+
instructionSet := newIstanbulInstructionSet()
36+
enable2929(&instructionSet)
37+
enable3198(&instructionSet) // Base fee opcode https://eips.ethereum.org/EIPS/eip-3198
38+
return validate(instructionSet)
39+
}

params/hooks.libevm.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ type RulesHooks interface {
3333
// [PrecompiledContract] is non-nil. If it returns `false` then the default
3434
// precompile behaviour is honoured.
3535
PrecompileOverride(common.Address) (_ libevm.PrecompiledContract, override bool)
36+
37+
JumpTable() interface{}
3638
}
3739

3840
// RulesAllowlistHooks are a subset of [RulesHooks] that gate actions, signalled
@@ -99,3 +101,7 @@ func (NOOPHooks) CanCreateContract(*libevm.AddressContext, libevm.StateReader) e
99101
func (NOOPHooks) PrecompileOverride(common.Address) (libevm.PrecompiledContract, bool) {
100102
return nil, false
101103
}
104+
105+
func (NOOPHooks) JumpTable() interface{} {
106+
return nil
107+
}

0 commit comments

Comments
 (0)