Add mstoreBytes

This commit is contained in:
Mason Fischer 2020-01-22 14:55:39 -05:00
parent 1cf19d88e1
commit 608d3355d5
2 changed files with 24 additions and 19 deletions

View file

@ -32,9 +32,9 @@ import (
var (
bigZero = new(big.Int)
tt255 = math.BigPow(2, 255)
ovmSLOADMethodId = hashSha3([]byte("ovmSLOAD()"))[0:4]
ovmSSTOREMethodId = hashSha3([]byte("ovmSStore()"))[0:4]
ovmContractAddress = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
OvmSLOADMethodId = hashSha3([]byte("ovmSLOAD()"))[0:4]
OvmSSTOREMethodId = hashSha3([]byte("ovmSStore()"))[0:4]
OvmContractAddress = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
errWriteProtection = errors.New("evm: write protection")
errReturnDataOutOfBounds = errors.New("evm: return data out of bounds")
errExecutionReverted = errors.New("evm: execution reverted")
@ -778,10 +778,10 @@ func opCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory
args := memory.GetPtr(inOffset.Int64(), inSize.Int64())
fmt.Printf("args 0%x\n", args)
if bytes.Equal(toAddr.Bytes(), ovmContractAddress) && bytes.Equal(args, ovmSLOADMethodId) {
if bytes.Equal(toAddr.Bytes(), OvmContractAddress) && bytes.Equal(args, OvmSLOADMethodId) {
fmt.Println("SLOAD")
}
if bytes.Equal(toAddr.Bytes(), ovmContractAddress) && bytes.Equal(args, ovmSSTOREMethodId) {
if bytes.Equal(toAddr.Bytes(), OvmContractAddress) && bytes.Equal(args, OvmSSTOREMethodId) {
fmt.Println("SSTORE")
}
if value.Sign() != 0 {

View file

@ -1,6 +1,7 @@
package tests
import (
"fmt"
"testing"
"github.com/ethereum/go-ethereum/common"
@ -10,23 +11,25 @@ import (
"github.com/ethereum/go-ethereum/core/vm/runtime"
)
func mstoreBytes(bytes []byte) []byte {
output := make([]byte, len(bytes)*5)
for i, b := range bytes {
output[i*5] = byte(vm.PUSH1)
output[i*5+1] = b
output[i*5+2] = byte(vm.PUSH1)
output[i*5+3] = byte(i)
output[i*5+4] = byte(vm.MSTORE8)
}
return output
}
func TestOvm(t *testing.T) {
db := state.NewDatabase(rawdb.NewMemoryDatabase())
state, _ := state.New(common.Hash{}, db)
address := common.HexToAddress("0x0a")
code := []byte{
byte(vm.PUSH1), 0x20,
byte(vm.PUSH1), 0,
byte(vm.MSTORE8),
byte(vm.PUSH1), 0x96,
byte(vm.PUSH1), 1,
byte(vm.MSTORE8),
byte(vm.PUSH1), 0x62,
byte(vm.PUSH1), 2,
byte(vm.MSTORE8),
byte(vm.PUSH1), 0x08,
byte(vm.PUSH1), 3,
byte(vm.MSTORE8),
fmt.Printf("%x\n", mstoreBytes(vm.OvmSLOADMethodId))
code := mstoreBytes(vm.OvmSLOADMethodId)
code = append(code, []byte{
byte(vm.PUSH1), 0,
byte(vm.PUSH1), 0,
byte(vm.PUSH1), 0,
@ -38,7 +41,9 @@ func TestOvm(t *testing.T) {
byte(vm.PUSH20), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
byte(vm.GAS),
byte(vm.CALL),
}
}...)
fmt.Printf("%x", code)
state.SetCode(address, code)
_, _, err := runtime.Call(address, nil, &runtime.Config{State: state, Debug: true})