mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Complete an ovmSSTORE and ovmSLOAD roundtrip test
This commit is contained in:
parent
ccb684b93f
commit
30b157a126
2 changed files with 47 additions and 30 deletions
|
|
@ -19,7 +19,6 @@ package vm
|
|||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
|
@ -768,43 +767,38 @@ func opCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory
|
|||
toAddr := common.BigToAddress(addr)
|
||||
value = math.U256(value)
|
||||
|
||||
fmt.Printf("value %s\n", value)
|
||||
fmt.Printf("inOffset %s\n", inOffset)
|
||||
fmt.Printf("inSize %s\n", inSize)
|
||||
fmt.Printf("retOffset %s\n", retOffset)
|
||||
fmt.Printf("retSize %s\n", retSize)
|
||||
fmt.Printf("address 0x%020x\n", addr)
|
||||
// Get the arguments from the memory.
|
||||
args := memory.GetPtr(inOffset.Int64(), inSize.Int64())
|
||||
fmt.Printf("args 0%x\n", args)
|
||||
|
||||
if bytes.Equal(toAddr.Bytes(), OvmContractAddress) && bytes.Equal(args[0:4], OvmSLOADMethodId) {
|
||||
fmt.Println("SLOAD")
|
||||
}
|
||||
if bytes.Equal(toAddr.Bytes(), OvmContractAddress) && bytes.Equal(args[0:4], OvmSSTOREMethodId) {
|
||||
fmt.Printf("SSTORE %v %v\n", args[4:35], args[36:68])
|
||||
loc := common.BytesToHash(args[4:35])
|
||||
val := interpreter.evm.StateDB.GetState(contract.Address(), loc)
|
||||
stack.push(val.Big())
|
||||
return val.Bytes(), nil
|
||||
} else if bytes.Equal(toAddr.Bytes(), OvmContractAddress) && bytes.Equal(args[0:4], OvmSSTOREMethodId) {
|
||||
loc := common.BytesToHash(args[4:35])
|
||||
val := common.BytesToHash(args[36:68])
|
||||
interpreter.evm.StateDB.SetState(contract.Address(), loc, val)
|
||||
|
||||
interpreter.intPool.put(val.Big())
|
||||
}
|
||||
if value.Sign() != 0 {
|
||||
gas += params.CallStipend
|
||||
}
|
||||
ret, returnGas, err := interpreter.evm.Call(contract, toAddr, args, gas, value)
|
||||
if err != nil {
|
||||
stack.push(interpreter.intPool.getZero())
|
||||
return nil, nil
|
||||
} else {
|
||||
stack.push(interpreter.intPool.get().SetUint64(1))
|
||||
}
|
||||
if err == nil || err == errExecutionReverted {
|
||||
memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
||||
}
|
||||
contract.Gas += returnGas
|
||||
if value.Sign() != 0 {
|
||||
gas += params.CallStipend
|
||||
}
|
||||
ret, returnGas, err := interpreter.evm.Call(contract, toAddr, args, gas, value)
|
||||
if err != nil {
|
||||
stack.push(interpreter.intPool.getZero())
|
||||
} else {
|
||||
stack.push(interpreter.intPool.get().SetUint64(1))
|
||||
}
|
||||
if err == nil || err == errExecutionReverted {
|
||||
memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
||||
}
|
||||
contract.Gas += returnGas
|
||||
|
||||
interpreter.intPool.put(addr, value, inOffset, inSize, retOffset, retSize)
|
||||
return ret, nil
|
||||
interpreter.intPool.put(addr, value, inOffset, inSize, retOffset, retSize)
|
||||
return ret, nil
|
||||
}
|
||||
}
|
||||
|
||||
func opCallCode(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package tests
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
|
@ -11,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
var KEY = common.FromHex("0102030000000000000000000000000000000000000000000000000000000000")
|
||||
var VALUE = common.FromHex("0405060000000000000000000000000000000000000000000000000000000001")
|
||||
var VALUE = common.FromHex("0405060000000000000000000000000000000000000000000000000000000000")
|
||||
|
||||
func mstoreBytes(bytes []byte, offset int) []byte {
|
||||
output := make([]byte, len(bytes)*5)
|
||||
|
|
@ -60,11 +61,33 @@ func TestOvm(t *testing.T) {
|
|||
68,
|
||||
0,
|
||||
0)...)
|
||||
code = append(code, mstoreBytes(vm.OvmSLOADMethodId, 0)...)
|
||||
code = append(code, mstoreBytes(KEY, 4)...)
|
||||
code = append(code,
|
||||
call(
|
||||
vm.OvmContractAddress,
|
||||
0,
|
||||
0,
|
||||
36,
|
||||
0,
|
||||
0)...)
|
||||
code = append(code, []byte{
|
||||
byte(vm.PUSH1), 0,
|
||||
byte(vm.MSTORE),
|
||||
byte(vm.PUSH1), 32,
|
||||
byte(vm.PUSH1), 0,
|
||||
byte(vm.RETURN),
|
||||
}...)
|
||||
|
||||
state.SetCode(address, code)
|
||||
|
||||
_, _, err := runtime.Call(address, nil, &runtime.Config{State: state, Debug: true})
|
||||
returnValue, _, err := runtime.Call(address, nil, &runtime.Config{State: state, Debug: true})
|
||||
if err != nil {
|
||||
t.Fatal("didn't expect error", err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(returnValue, VALUE) {
|
||||
t.Errorf("Expected %020x; got %020x", returnValue, VALUE)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue