Commit 635af73a authored by George Hotz's avatar George Hotz Committed by GitHub

Merge pull request #36 from geohot/oracletest

oracle test
parents b825df28 ac06c5ed
......@@ -2,6 +2,7 @@ Running MIPS processor on chain
Tests from https://github.com/grantae/OpenMIPS/tree/master/software/test/macro/tests
Licensed GPLv3
Requires https://github.com/sergev/LiteBSD/releases/download/tools/gcc-4.8.1-mips-macosx.tgz to build
Instruction set used by minigeth, 55 instructions:
['addi', 'addiu', 'addu', 'and', 'andi',
......
......@@ -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])
}
hash := common.BytesToHash(oracle_hash)
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)
value, _ := ioutil.ReadFile(key)
value, err := ioutil.ReadFile(key)
if err != nil {
log.Fatal(err)
}
WriteRam(ram, 0x31000000, uint32(len(value)))
value = append(value, 0, 0, 0)
......
......@@ -27,7 +27,7 @@ func TestSimpleEVM(t *testing.T) {
LoadMappedFile(fn, ram, 0)
start := time.Now()
remainingGas, err := RunWithRam(ram, 100, 0, "", nil)
remainingGas, err := RunWithRam(ram, 100, 0, "testoracle/", nil)
elapsed := time.Now().Sub(start)
fmt.Println(err, remainingGas, elapsed,
......
......@@ -83,7 +83,8 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), callback func(int, u
oracle_hash, _ := mu.MemRead(0x30001000, 0x20)
hash := common.BytesToHash(oracle_hash)
key := fmt.Sprintf("%s/%s", root, hash)
value, _ := ioutil.ReadFile(key)
value, err := ioutil.ReadFile(key)
check(err)
tmp := []byte{0, 0, 0, 0}
binary.BigEndian.PutUint32(tmp, uint32(len(value)))
......@@ -179,7 +180,9 @@ func RunUnicorn(fn string, ram map[uint32](uint32), checkIO bool, callback func(
mu.MemWrite(0, dat)
// inputs
inputs, _ := ioutil.ReadFile(fmt.Sprintf("%s/input", root))
inputs, err := ioutil.ReadFile(fmt.Sprintf("%s/input", root))
check(err)
mu.MemWrite(0x30000000, inputs[0:0xc0])
// load into ram
......@@ -191,7 +194,8 @@ func RunUnicorn(fn string, ram map[uint32](uint32), checkIO bool, callback func(
mu.Start(0, 0x5ead0004)
if checkIO {
outputs, _ := ioutil.ReadFile(fmt.Sprintf("%s/output", root))
outputs, err := ioutil.ReadFile(fmt.Sprintf("%s/output", root))
check(err)
real := append([]byte{0x13, 0x37, 0xf0, 0x0d}, outputs...)
output, _ := mu.MemRead(0x30000800, 0x44)
if bytes.Compare(real, output) != 0 {
......
.section .test, "x"
.balign 4
.set noreorder
.global test
.ent test
# load hash at 0x30001000
# 0x47173285 a8d7341e 5e972fc6 77286384 f802f8ef 42a5ec5f 03bbfa25 4cb01fad = "hello world"
test:
lui $s0, 0x3000
ori $s0, 0x1000
lui $t0, 0x4717
ori $t0, 0x3285
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
lui $s1, 0x3100
lw $t0, 0($s1)
# should be len("hello world") == 11
li $t4, 11
subu $t5, $t0, $t4
sltiu $v0, $t5, 1
# data at 0x31000004
# save results
lui $s0, 0xbfff # Load the base address 0xbffffff0
ori $s0, 0xfff0
ori $s1, $0, 1 # Prepare the 'done' status
sw $v0, 8($s0) # Set the test result
sw $s1, 4($s0) # Set 'done'
$done:
jr $ra
nop
.end test
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