Commit 5af95462 authored by George Hotz's avatar George Hotz

oracle test works

parent 6a3f7ac9
...@@ -127,11 +127,15 @@ func (s *StateDB) GetState(fakeaddr common.Address, hash common.Hash) common.Has ...@@ -127,11 +127,15 @@ func (s *StateDB) GetState(fakeaddr common.Address, hash common.Hash) common.Has
binary.BigEndian.PutUint32(oracle_hash[i:i+4], ram[0x30001000+i]) binary.BigEndian.PutUint32(oracle_hash[i:i+4], ram[0x30001000+i])
} }
hash := common.BytesToHash(oracle_hash) hash := common.BytesToHash(oracle_hash)
if s.root == "" { if s.root == "" {
log.Fatal("need root if using hash oracle") log.Fatal("need root if using oracle for ", hash)
} }
key := fmt.Sprintf("%s/%s", s.root, hash) key := fmt.Sprintf("%s/%s", s.root, hash)
value, _ := ioutil.ReadFile(key) value, err := ioutil.ReadFile(key)
if err != nil {
log.Fatal(err)
}
WriteRam(ram, 0x31000000, uint32(len(value))) WriteRam(ram, 0x31000000, uint32(len(value)))
value = append(value, 0, 0, 0) value = append(value, 0, 0, 0)
......
...@@ -27,7 +27,7 @@ func TestSimpleEVM(t *testing.T) { ...@@ -27,7 +27,7 @@ func TestSimpleEVM(t *testing.T) {
LoadMappedFile(fn, ram, 0) LoadMappedFile(fn, ram, 0)
start := time.Now() start := time.Now()
remainingGas, err := RunWithRam(ram, 100, 0, "", nil) remainingGas, err := RunWithRam(ram, 100, 0, "testoracle/", nil)
elapsed := time.Now().Sub(start) elapsed := time.Now().Sub(start)
fmt.Println(err, remainingGas, elapsed, fmt.Println(err, remainingGas, elapsed,
......
...@@ -5,21 +5,46 @@ ...@@ -5,21 +5,46 @@
.ent test .ent test
# load hash at 0x30001000 # load hash at 0x30001000
# 0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad = "hello world" # 0x47173285 a8d7341e 5e972fc6 77286384 f802f8ef 42a5ec5f 03bbfa25 4cb01fad = "hello world"
test: test:
lui $s0, 0x3000 lui $s0, 0x3000
ori $s0, 0x1000 ori $s0, 0x1000
li $t0, 0x4717
sh $t0, 0($s0) lui $t0, 0x4717
li $t0, 0x3285 ori $t0, 0x3285
sh $t0, 1($s0) sw $t0, 0($s0)
lui $t0, 0xa8d7
ori $t0, 0x341e
sw $t0, 4($s0)
lui $t0, 0x5e97
ori $t0, 0x2fc6
sw $t0, 8($s0)
lui $t0, 0x7728
ori $t0, 0x6384
sw $t0, 0xc($s0)
lui $t0, 0xf802
ori $t0, 0xf8ef
sw $t0, 0x10($s0)
lui $t0, 0x42a5
ori $t0, 0xec5f
sw $t0, 0x14($s0)
lui $t0, 0x03bb
ori $t0, 0xfa25
sw $t0, 0x18($s0)
lui $t0, 0x4cb0
ori $t0, 0x1fad
sw $t0, 0x1c($s0)
# syscall 4020 to trigger
li $v0, 4020
syscall
# length at 0x31000000 # length at 0x31000000
lui $s1, 0x3100 lui $s1, 0x3100
lw $s1, 0($t0) lw $t0, 0($s1)
# should be 9 # should be len("hello world") == 11
li $t4, 9 li $t4, 11
subu $t5, $t0, $t4 subu $t5, $t0, $t4
sltiu $v0, $t5, 1 sltiu $v0, $t5, 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment