Skip to content

Commit 8d640dd

Browse files
committed
changes for ISC wasp
1 parent dd1ebac commit 8d640dd

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

core/vm/evm.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ func (evm *EVM) Call(caller common.Address, addr common.Address, input []byte, g
233233
}
234234
evm.Context.Transfer(evm.StateDB, caller, addr, value)
235235

236-
if isPrecompile {
236+
if evm.Config.MagicContracts != nil && evm.Config.MagicContracts[addr] != nil {
237+
ret, gas, err = evm.Config.MagicContracts[addr].Run(evm, caller, input, value, gas, false)
238+
} else if isPrecompile {
237239
ret, gas, err = RunPrecompiledContract(p, input, gas, evm.Config.Tracer)
238240
} else {
239241
// Initialise a new contract and set the code that is to be used by the EVM.
@@ -296,8 +298,10 @@ func (evm *EVM) CallCode(caller common.Address, addr common.Address, input []byt
296298
}
297299
var snapshot = evm.StateDB.Snapshot()
298300

299-
// It is allowed to call precompiles, even via delegatecall
300-
if p, isPrecompile := evm.precompile(addr); isPrecompile {
301+
if evm.Config.MagicContracts != nil && evm.Config.MagicContracts[addr] != nil {
302+
ret, gas, err = evm.Config.MagicContracts[addr].Run(evm, caller, input, value, gas, false)
303+
} else if p, isPrecompile := evm.precompile(addr); isPrecompile {
304+
// It is allowed to call precompiles, even via delegatecall
301305
ret, gas, err = RunPrecompiledContract(p, input, gas, evm.Config.Tracer)
302306
} else {
303307
// Initialise a new contract and set the code that is to be used by the EVM.
@@ -339,8 +343,9 @@ func (evm *EVM) DelegateCall(originCaller common.Address, caller common.Address,
339343
}
340344
var snapshot = evm.StateDB.Snapshot()
341345

342-
// It is allowed to call precompiles, even via delegatecall
343-
if p, isPrecompile := evm.precompile(addr); isPrecompile {
346+
if evm.Config.MagicContracts != nil && evm.Config.MagicContracts[addr] != nil {
347+
ret, gas, err = evm.Config.MagicContracts[addr].Run(evm, caller, input, new(uint256.Int), gas, false)
348+
} else if p, isPrecompile := evm.precompile(addr); isPrecompile {
344349
ret, gas, err = RunPrecompiledContract(p, input, gas, evm.Config.Tracer)
345350
} else {
346351
// Initialise a new contract and make initialise the delegate values
@@ -392,7 +397,9 @@ func (evm *EVM) StaticCall(caller common.Address, addr common.Address, input []b
392397
// future scenarios
393398
evm.StateDB.AddBalance(addr, new(uint256.Int), tracing.BalanceChangeTouchAccount)
394399

395-
if p, isPrecompile := evm.precompile(addr); isPrecompile {
400+
if evm.Config.MagicContracts != nil && evm.Config.MagicContracts[addr] != nil {
401+
ret, gas, err = evm.Config.MagicContracts[addr].Run(evm, caller, input, new(uint256.Int), gas, true)
402+
} else if p, isPrecompile := evm.precompile(addr); isPrecompile {
396403
ret, gas, err = RunPrecompiledContract(p, input, gas, evm.Config.Tracer)
397404
} else {
398405
// Initialise a new contract and set the code that is to be used by the EVM.

core/vm/interpreter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ type Config struct {
3535
ExtraEips []int // Additional EIPS that are to be enabled
3636

3737
StatelessSelfValidation bool // Generate execution witnesses and self-check against them (testing purpose)
38+
39+
// MagicContracts allows the interpreter to run native code at arbitrary addresses
40+
MagicContracts map[common.Address]ISCMagicContract
3841
}
3942

4043
// ScopeContext contains the things that are per-call, such as stack and memory,

core/vm/isc.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package vm
2+
3+
import (
4+
"github.com/ethereum/go-ethereum/common"
5+
"github.com/holiman/uint256"
6+
)
7+
8+
type ISCMagicContract interface {
9+
Run(evm *EVM, caller common.Address, input []byte, value *uint256.Int, gas uint64, readOnly bool) ([]byte, uint64, error)
10+
}

rpc/websocket_extensions_wasp.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package rpc
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/gorilla/websocket"
7+
)
8+
9+
func NewWebSocketCodec(conn *websocket.Conn, host string, req http.Header, readLimit int64) ServerCodec {
10+
return newWebsocketCodec(conn, host, req, readLimit)
11+
}

0 commit comments

Comments
 (0)