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
5c5305de
Commit
5c5305de
authored
Dec 10, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor to revertWithHex, and nil -> null
parent
3e56fb71
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
20 deletions
+20
-20
MIPSMemory.sol
contracts/MIPSMemory.sol
+1
-10
Lib_BytesUtils.sol
contracts/lib/Lib_BytesUtils.sol
+17
-0
Lib_MerkleTrie.sol
contracts/lib/Lib_MerkleTrie.sol
+1
-9
mips_test_execwtrie_dynamic.js
test/mips_test_execwtrie_dynamic.js
+1
-1
No files found.
contracts/MIPSMemory.sol
View file @
5c5305de
...
@@ -19,17 +19,8 @@ contract MIPSMemory {
...
@@ -19,17 +19,8 @@ contract MIPSMemory {
mapping(bytes32 => Preimage) public preimage;
mapping(bytes32 => Preimage) public preimage;
// TODO: can share code with getTrieNode
function MissingPreimageRevert(bytes32 outhash, uint offset) internal pure {
function MissingPreimageRevert(bytes32 outhash, uint offset) internal pure {
bytes memory node = Lib_BytesUtils.toNibbles(abi.encodePacked(outhash, offset));
Lib_BytesUtils.revertWithHex(abi.encodePacked(outhash, offset));
for (uint i = 0; i < node.length; i++) {
if (node[i] < bytes1(uint8(10))) {
node[i] = bytes1(uint8(node[i]) + uint8(0x30));
} else {
node[i] = bytes1(uint8(node[i]) + uint8(0x61-10));
}
}
revert(string(node));
}
}
function GetPreimageLength(bytes32 outhash) public view returns (uint32) {
function GetPreimageLength(bytes32 outhash) public view returns (uint32) {
...
...
contracts/lib/Lib_BytesUtils.sol
View file @
5c5305de
...
@@ -253,6 +253,23 @@ library Lib_BytesUtils {
...
@@ -253,6 +253,23 @@ library Lib_BytesUtils {
return tempAddress;
return tempAddress;
}
}
function revertWithHex(
bytes memory _bytes
)
internal
pure
{
bytes memory node = Lib_BytesUtils.toNibbles(_bytes);
for (uint i = 0; i < node.length; i++) {
if (node[i] < bytes1(uint8(10))) {
node[i] = bytes1(uint8(node[i]) + uint8(0x30));
} else {
node[i] = bytes1(uint8(node[i]) + uint8(0x61-10));
}
}
revert(string(node));
}
function toNibbles(
function toNibbles(
bytes memory _bytes
bytes memory _bytes
)
)
...
...
contracts/lib/Lib_MerkleTrie.sol
View file @
5c5305de
...
@@ -103,15 +103,7 @@ library Lib_MerkleTrie {
...
@@ -103,15 +103,7 @@ library Lib_MerkleTrie {
function getTrieNode(bytes32 nodeId) private view returns (TrieNode memory) {
function getTrieNode(bytes32 nodeId) private view returns (TrieNode memory) {
bytes memory encoded = GetTrie()[nodeId];
bytes memory encoded = GetTrie()[nodeId];
if (encoded.length == 0) {
if (encoded.length == 0) {
bytes memory node = Lib_BytesUtils.toNibbles(abi.encodePacked(nodeId));
Lib_BytesUtils.revertWithHex(abi.encodePacked(nodeId));
for (uint i = 0; i < node.length; i++) {
if (node[i] < bytes1(uint8(10))) {
node[i] = bytes1(uint8(node[i]) + uint8(0x30));
} else {
node[i] = bytes1(uint8(node[i]) + uint8(0x61-10));
}
}
revert(string(node));
}
}
require(keccak256(encoded) == nodeId, "bad hash in trie lookup");
require(keccak256(encoded) == nodeId, "bad hash in trie lookup");
return getRawNode(encoded);
return getRawNode(encoded);
...
...
test/mips_test_execwtrie_dynamic.js
View file @
5c5305de
...
@@ -56,7 +56,7 @@ describe("Exec with trie dynamic", function () {
...
@@ -56,7 +56,7 @@ describe("Exec with trie dynamic", function () {
it
(
"
add should work
"
,
async
function
()
{
it
(
"
add should work
"
,
async
function
()
{
let
root
=
trieAdd
[
'
root
'
]
let
root
=
trieAdd
[
'
root
'
]
for
(
let
i
=
0
;
i
<
12
;
i
++
)
{
for
(
let
i
=
0
;
i
<
12
;
i
++
)
{
root
=
await
dynamicExecWithTrie
(
c
,
m
,
mm
,
root
,
trieAdd
[
'
preimages
'
],
n
i
l
)
root
=
await
dynamicExecWithTrie
(
c
,
m
,
mm
,
root
,
trieAdd
[
'
preimages
'
],
n
ul
l
)
console
.
log
(
i
,
root
)
console
.
log
(
i
,
root
)
}
}
})
})
...
...
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