Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
0978b251
Commit
0978b251
authored
Nov 05, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
found bug from fuzzer
parent
2199f863
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
21 deletions
+19
-21
mips_test_memory.js
test/mips_test_memory.js
+19
-21
No files found.
test/mips_test_memory.js
View file @
0978b251
...
@@ -8,6 +8,7 @@ async function write(mm, root, addr, data) {
...
@@ -8,6 +8,7 @@ async function write(mm, root, addr, data) {
root
=
l
.
data
root
=
l
.
data
}
}
}
}
console
.
log
(
"
new hash
"
,
root
)
return
root
return
root
}
}
...
@@ -19,15 +20,13 @@ describe("MIPSMemory contract", function () {
...
@@ -19,15 +20,13 @@ describe("MIPSMemory contract", function () {
beforeEach
(
async
function
()
{
beforeEach
(
async
function
()
{
const
MIPSMemory
=
await
ethers
.
getContractFactory
(
"
MIPSMemory
"
)
const
MIPSMemory
=
await
ethers
.
getContractFactory
(
"
MIPSMemory
"
)
mm
=
await
MIPSMemory
.
deploy
()
mm
=
await
MIPSMemory
.
deploy
()
await
mm
.
AddTrieNode
(
new
Uint8Array
([
0x80
]))
})
})
it
(
"
write from new should work
"
,
async
function
()
{
it
(
"
write from new should work
"
,
async
function
()
{
await
mm
.
AddTrieNode
(
new
Uint8Array
([
0x80
]))
let
root
=
"
0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
"
let
root
=
"
0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
"
root
=
await
write
(
mm
,
root
,
0
,
1
)
root
=
await
write
(
mm
,
root
,
0
,
1
)
console
.
log
(
"
new hash
"
,
root
)
root
=
await
write
(
mm
,
root
,
4
,
2
)
root
=
await
write
(
mm
,
root
,
4
,
2
)
console
.
log
(
"
new hash
"
,
root
)
expect
(
await
mm
.
ReadMemory
(
root
,
0
)).
to
.
equal
(
1
)
expect
(
await
mm
.
ReadMemory
(
root
,
0
)).
to
.
equal
(
1
)
expect
(
await
mm
.
ReadMemory
(
root
,
4
)).
to
.
equal
(
2
)
expect
(
await
mm
.
ReadMemory
(
root
,
4
)).
to
.
equal
(
2
)
...
@@ -37,60 +36,59 @@ describe("MIPSMemory contract", function () {
...
@@ -37,60 +36,59 @@ describe("MIPSMemory contract", function () {
let
root
=
"
0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
"
let
root
=
"
0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
"
root
=
await
write
(
mm
,
root
,
0
,
1
)
root
=
await
write
(
mm
,
root
,
0
,
1
)
console
.
log
(
"
new hash
"
,
root
)
root
=
await
write
(
mm
,
root
,
4
,
2
)
root
=
await
write
(
mm
,
root
,
4
,
2
)
console
.
log
(
"
new hash
"
,
root
)
root
=
await
write
(
mm
,
root
,
0x40
,
3
)
root
=
await
write
(
mm
,
root
,
0x40
,
3
)
console
.
log
(
"
new hash
"
,
root
)
expect
(
await
mm
.
ReadMemory
(
root
,
0
)).
to
.
equal
(
1
)
expect
(
await
mm
.
ReadMemory
(
root
,
0
)).
to
.
equal
(
1
)
expect
(
await
mm
.
ReadMemory
(
root
,
4
)).
to
.
equal
(
2
)
expect
(
await
mm
.
ReadMemory
(
root
,
4
)).
to
.
equal
(
2
)
expect
(
await
mm
.
ReadMemory
(
root
,
0x40
)).
to
.
equal
(
3
)
expect
(
await
mm
.
ReadMemory
(
root
,
0x40
)).
to
.
equal
(
3
)
})
})
it
(
"
write other three should work
"
,
async
function
()
{
it
(
"
write other three should work
"
,
async
function
()
{
await
mm
.
AddTrieNode
(
new
Uint8Array
([
0x80
]))
let
root
=
"
0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
"
let
root
=
"
0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
"
root
=
await
write
(
mm
,
root
,
0x7fffd00c
,
1
)
root
=
await
write
(
mm
,
root
,
0x7fffd00c
,
1
)
console
.
log
(
"
new hash
"
,
root
)
root
=
await
write
(
mm
,
root
,
0x7fffd010
,
2
)
root
=
await
write
(
mm
,
root
,
0x7fffd010
,
2
)
console
.
log
(
"
new hash
"
,
root
)
root
=
await
write
(
mm
,
root
,
0x7fffcffc
,
3
)
root
=
await
write
(
mm
,
root
,
0x7fffcffc
,
3
)
console
.
log
(
"
new hash
"
,
root
)
expect
(
await
mm
.
ReadMemory
(
root
,
0x7fffd00c
)).
to
.
equal
(
1
)
expect
(
await
mm
.
ReadMemory
(
root
,
0x7fffd00c
)).
to
.
equal
(
1
)
expect
(
await
mm
.
ReadMemory
(
root
,
0x7fffd010
)).
to
.
equal
(
2
)
expect
(
await
mm
.
ReadMemory
(
root
,
0x7fffd010
)).
to
.
equal
(
2
)
expect
(
await
mm
.
ReadMemory
(
root
,
0x7fffcffc
)).
to
.
equal
(
3
)
expect
(
await
mm
.
ReadMemory
(
root
,
0x7fffcffc
)).
to
.
equal
(
3
)
})
})
it
(
"
fuzzing should be okay
"
,
async
function
()
{
it
(
"
bug found fuzzing 1
"
,
async
function
()
{
await
mm
.
AddTrieNode
(
new
Uint8Array
([
0x80
]))
let
root
=
"
0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
"
root
=
await
write
(
mm
,
root
,
208
,
3560962548
)
root
=
await
write
(
mm
,
root
,
208
,
1247044781
)
root
=
await
write
(
mm
,
root
,
208
,
688075632
)
})
/*it("fuzzing should be okay", async function() {
let root = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
let root = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
let
keys
=
[]
let kv = {}
let
values
=
[]
for (var i = 0; i < 100; i++) {
for (var i = 0; i < 100; i++) {
const keys = Object.keys(kv)
const choice = Math.random()
const choice = Math.random()
if (choice < 0.5 || keys.length == 0) {
if (choice < 0.5 || keys.length == 0) {
// write new key
// write new key
const
key
=
randint
(
0x
40
00
)
*
4
const key = randint(0x
1
00)*4
const value = randint(0x100000000)
const value = randint(0x100000000)
console.log("writing", key, value)
root = await write(mm, root, key, value)
root = await write(mm, root, key, value)
keys
.
push
(
key
)
kv[key] = value
values
.
push
(
value
)
} else if (choice > 0.7) {
} else if (choice > 0.7) {
// read old key
// read old key
const idx = randint(keys.length)
const idx = randint(keys.length)
const key = keys[idx]
const key = keys[idx]
cons
t
value
=
values
[
idx
]
cons
ole.log("reading", key)
expect
(
await
mm
.
ReadMemory
(
root
,
key
)).
to
.
equal
(
value
)
expect(await mm.ReadMemory(root, key)).to.equal(
kv[key]
)
} else {
} else {
// rewrite old key
// rewrite old key
const idx = randint(keys.length)
const idx = randint(keys.length)
const key = keys[idx]
const key = keys[idx]
const value = randint(0x100000000)
const value = randint(0x100000000)
console.log("writing", key, value)
root = await write(mm, root, key, value)
root = await write(mm, root, key, value)
values
[
idx
]
=
value
kv[key
] = value
}
}
}
}
})
})
*/
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment