mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Store state on call to ovmSSTORE
This commit is contained in:
parent
2ed2db0cbe
commit
ccb684b93f
2 changed files with 14 additions and 8 deletions
|
|
@ -782,7 +782,12 @@ func opCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory
|
||||||
fmt.Println("SLOAD")
|
fmt.Println("SLOAD")
|
||||||
}
|
}
|
||||||
if bytes.Equal(toAddr.Bytes(), OvmContractAddress) && bytes.Equal(args[0:4], OvmSSTOREMethodId) {
|
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 {
|
if value.Sign() != 0 {
|
||||||
gas += params.CallStipend
|
gas += params.CallStipend
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,16 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/vm/runtime"
|
"github.com/ethereum/go-ethereum/core/vm/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
var KEY = common.FromHex("0000000000000000000000000000000000000000000000000000000000000000")
|
var KEY = common.FromHex("0102030000000000000000000000000000000000000000000000000000000000")
|
||||||
var VALUE = common.FromHex("0000000000000000000000000000000000000000000000000000000000000001")
|
var VALUE = common.FromHex("0405060000000000000000000000000000000000000000000000000000000001")
|
||||||
|
|
||||||
func mstoreBytes(bytes []byte) []byte {
|
func mstoreBytes(bytes []byte, offset int) []byte {
|
||||||
output := make([]byte, len(bytes)*5)
|
output := make([]byte, len(bytes)*5)
|
||||||
for i, b := range bytes {
|
for i, b := range bytes {
|
||||||
output[i*5] = byte(vm.PUSH1)
|
output[i*5] = byte(vm.PUSH1)
|
||||||
output[i*5+1] = b
|
output[i*5+1] = b
|
||||||
output[i*5+2] = byte(vm.PUSH1)
|
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)
|
output[i*5+4] = byte(vm.MSTORE8)
|
||||||
}
|
}
|
||||||
return output
|
return output
|
||||||
|
|
@ -49,14 +49,15 @@ func TestOvm(t *testing.T) {
|
||||||
db := state.NewDatabase(rawdb.NewMemoryDatabase())
|
db := state.NewDatabase(rawdb.NewMemoryDatabase())
|
||||||
state, _ := state.New(common.Hash{}, db)
|
state, _ := state.New(common.Hash{}, db)
|
||||||
address := common.HexToAddress("0x0a")
|
address := common.HexToAddress("0x0a")
|
||||||
code := mstoreBytes(KEY)
|
code := mstoreBytes(vm.OvmSSTOREMethodId, 0)
|
||||||
code = append(code, mstoreBytes(vm.OvmSLOADMethodId)...)
|
code = append(code, mstoreBytes(KEY, 4)...)
|
||||||
|
code = append(code, mstoreBytes(VALUE, 36)...)
|
||||||
code = append(code,
|
code = append(code,
|
||||||
call(
|
call(
|
||||||
vm.OvmContractAddress,
|
vm.OvmContractAddress,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
36,
|
68,
|
||||||
0,
|
0,
|
||||||
0)...)
|
0)...)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue