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
481daf75
Commit
481daf75
authored
Oct 11, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix lib_keccak256
parent
d3088b7a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
5 deletions
+17
-5
MIPSMemory.sol
contracts/MIPSMemory.sol
+1
-4
Lib_Keccak256.sol
contracts/lib/Lib_Keccak256.sol
+14
-0
libkeccak.js
test/libkeccak.js
+2
-1
No files found.
contracts/MIPSMemory.sol
View file @
481daf75
...
...
@@ -44,10 +44,7 @@ contract MIPSMemory {
c.A = largePreimage[msg.sender];
// TODO: do this properly and save the hash
// when this is updated, it won't be "view"
return bytes32((uint256(c.A[0]) << 192) |
(uint256(c.A[1]) << 128) |
(uint256(c.A[2]) << 64) |
(uint256(c.A[3]) << 0));
return Lib_Keccak256.get_hash(c);
}
function AddMerkleState(bytes32 stateHash, uint32 addr, uint32 value, string calldata proof) public {
...
...
contracts/lib/Lib_Keccak256.sol
View file @
481daf75
...
...
@@ -101,4 +101,18 @@ library Lib_Keccak256 {
}
}
// https://stackoverflow.com/questions/2182002/convert-big-endian-to-little-endian-in-c-without-using-provided-func
function flip(uint64 val) internal pure returns (uint64) {
val = ((val << 8) & 0xFF00FF00FF00FF00 ) | ((val >> 8) & 0x00FF00FF00FF00FF );
val = ((val << 16) & 0xFFFF0000FFFF0000 ) | ((val >> 16) & 0x0000FFFF0000FFFF );
return (val << 32) | (val >> 32);
}
function get_hash(CTX memory c) internal pure returns (bytes32) {
return bytes32((uint256(flip(c.A[0])) << 192) |
(uint256(flip(c.A[1])) << 128) |
(uint256(flip(c.A[2])) << 64) |
(uint256(flip(c.A[3])) << 0));
}
}
\ No newline at end of file
test/libkeccak.js
View file @
481daf75
...
...
@@ -13,7 +13,8 @@ describe("MIPSMemory contract", function () {
console
.
log
(
"
preimage initted
"
);
// block size is 136
const
a
=
[
"
0x0100000000000000
"
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0x80
];
//const a = ["0x0100000000000000",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80];
const
a
=
[
0x1
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
"
0x8000000000000000
"
];
await
mm
.
AddLargePreimageUpdate
(
a
);
console
.
log
(
"
preimage updated
"
);
...
...
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