Store state on call to ovmSSTORE

This commit is contained in:
Mason Fischer 2020-01-22 16:00:04 -05:00
parent 2ed2db0cbe
commit ccb684b93f
2 changed files with 14 additions and 8 deletions

View file

@ -782,7 +782,12 @@ func opCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory
fmt.Println("SLOAD")
}
if bytes.Equal(toAddr.Bytes(), OvmContractAddress) && bytes.Equal(args[0:4], OvmSSTOREMethodId) {
fmt.Println("SSTORE")
fmt.Printf("SSTORE %v %v\n", args[4:35], args[36:68])
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

View file

@ -10,16 +10,16 @@ import (
"github.com/ethereum/go-ethereum/core/vm/runtime"
)
var KEY = common.FromHex("0000000000000000000000000000000000000000000000000000000000000000")
var VALUE = common.FromHex("0000000000000000000000000000000000000000000000000000000000000001")
var KEY = common.FromHex("0102030000000000000000000000000000000000000000000000000000000000")
var VALUE = common.FromHex("0405060000000000000000000000000000000000000000000000000000000001")
func mstoreBytes(bytes []byte) []byte {
func mstoreBytes(bytes []byte, offset int) []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+3] = byte(offset + i)
output[i*5+4] = byte(vm.MSTORE8)
}
return output
@ -49,14 +49,15 @@ func TestOvm(t *testing.T) {
db := state.NewDatabase(rawdb.NewMemoryDatabase())
state, _ := state.New(common.Hash{}, db)
address := common.HexToAddress("0x0a")
code := mstoreBytes(KEY)
code = append(code, mstoreBytes(vm.OvmSLOADMethodId)...)
code := mstoreBytes(vm.OvmSSTOREMethodId, 0)
code = append(code, mstoreBytes(KEY, 4)...)
code = append(code, mstoreBytes(VALUE, 36)...)
code = append(code,
call(
vm.OvmContractAddress,
0,
0,
36,
68,
0,
0)...)