Skip to content

Commit 30f95dc

Browse files
committed
changes for ISC wasp
1 parent 4263936 commit 30f95dc

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

core/vm/evm.go

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

226-
if isPrecompile {
226+
if evm.Config.MagicContracts != nil && evm.Config.MagicContracts[addr] != nil {
227+
ret, gas, err = evm.Config.MagicContracts[addr].Run(evm, caller, input, value, gas, false)
228+
} else if isPrecompile {
227229
ret, gas, err = RunPrecompiledContract(p, input, gas, evm.Config.Tracer)
228230
} else {
229231
// Initialise a new contract and set the code that is to be used by the EVM.
@@ -286,8 +288,10 @@ func (evm *EVM) CallCode(caller common.Address, addr common.Address, input []byt
286288
}
287289
var snapshot = evm.StateDB.Snapshot()
288290

289-
// It is allowed to call precompiles, even via delegatecall
290-
if p, isPrecompile := evm.precompile(addr); isPrecompile {
291+
if evm.Config.MagicContracts != nil && evm.Config.MagicContracts[addr] != nil {
292+
ret, gas, err = evm.Config.MagicContracts[addr].Run(evm, caller, input, value, gas, false)
293+
} else if p, isPrecompile := evm.precompile(addr); isPrecompile {
294+
// It is allowed to call precompiles, even via delegatecall
291295
ret, gas, err = RunPrecompiledContract(p, input, gas, evm.Config.Tracer)
292296
} else {
293297
// Initialise a new contract and set the code that is to be used by the EVM.
@@ -329,8 +333,9 @@ func (evm *EVM) DelegateCall(originCaller common.Address, caller common.Address,
329333
}
330334
var snapshot = evm.StateDB.Snapshot()
331335

332-
// It is allowed to call precompiles, even via delegatecall
333-
if p, isPrecompile := evm.precompile(addr); isPrecompile {
336+
if evm.Config.MagicContracts != nil && evm.Config.MagicContracts[addr] != nil {
337+
ret, gas, err = evm.Config.MagicContracts[addr].Run(evm, caller, input, new(uint256.Int), gas, false)
338+
} else if p, isPrecompile := evm.precompile(addr); isPrecompile {
334339
ret, gas, err = RunPrecompiledContract(p, input, gas, evm.Config.Tracer)
335340
} else {
336341
// Initialise a new contract and make initialise the delegate values
@@ -382,7 +387,9 @@ func (evm *EVM) StaticCall(caller common.Address, addr common.Address, input []b
382387
// future scenarios
383388
evm.StateDB.AddBalance(addr, new(uint256.Int), tracing.BalanceChangeTouchAccount)
384389

385-
if p, isPrecompile := evm.precompile(addr); isPrecompile {
390+
if evm.Config.MagicContracts != nil && evm.Config.MagicContracts[addr] != nil {
391+
ret, gas, err = evm.Config.MagicContracts[addr].Run(evm, caller, input, new(uint256.Int), gas, true)
392+
} else if p, isPrecompile := evm.precompile(addr); isPrecompile {
386393
ret, gas, err = RunPrecompiledContract(p, input, gas, evm.Config.Tracer)
387394
} else {
388395
// 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+
}

eth/protocols/snap/sync.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,9 +1987,7 @@ func (s *Syncer) processAccountResponse(res *accountResponse) {
19871987
func (s *Syncer) processBytecodeResponse(res *bytecodeResponse) {
19881988
batch := s.db.NewBatch()
19891989

1990-
var (
1991-
codes uint64
1992-
)
1990+
var codes uint64
19931991
for i, hash := range res.hashes {
19941992
code := res.codes[i]
19951993

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)