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
5f9697f6
Commit
5f9697f6
authored
Dec 08, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor refactor, 0 length doesn't work
parent
112f076a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
13 deletions
+12
-13
MIPSMemory.sol
contracts/MIPSMemory.sol
+11
-12
libkeccak.js
test/libkeccak.js
+1
-1
No files found.
contracts/MIPSMemory.sol
View file @
5f9697f6
...
@@ -62,11 +62,7 @@ contract MIPSMemory {
...
@@ -62,11 +62,7 @@ contract MIPSMemory {
int offset = int(largePreimage[msg.sender].offset) - int(largePreimage[msg.sender].len);
int offset = int(largePreimage[msg.sender].offset) - int(largePreimage[msg.sender].len);
if (offset >= 0 && offset < 136) {
if (offset >= 0 && offset < 136) {
largePreimage[msg.sender].data =
largePreimage[msg.sender].data = fbo(dat, uint(offset));
uint32(uint8(dat[uint256(offset)+0])) << 24 |
uint32(uint8(dat[uint256(offset)+1])) << 16 |
uint32(uint8(dat[uint256(offset)+2])) << 8 |
uint32(uint8(dat[uint256(offset)+3])) << 0;
}
}
Lib_Keccak256.sha3_xor_input(c, dat);
Lib_Keccak256.sha3_xor_input(c, dat);
Lib_Keccak256.sha3_permutation(c);
Lib_Keccak256.sha3_permutation(c);
...
@@ -77,7 +73,7 @@ contract MIPSMemory {
...
@@ -77,7 +73,7 @@ contract MIPSMemory {
function AddLargePreimageFinal(bytes calldata idat) public view returns (bytes32, uint, uint32) {
function AddLargePreimageFinal(bytes calldata idat) public view returns (bytes32, uint, uint32) {
require(idat.length < 136, "final must be less than 136");
require(idat.length < 136, "final must be less than 136");
int offset = int(largePreimage[msg.sender].offset) - int(largePreimage[msg.sender].len);
int offset = int(largePreimage[msg.sender].offset) - int(largePreimage[msg.sender].len);
require(offset < i
dat.length
, "offset must be less than length");
require(offset < i
nt(idat.length)
, "offset must be less than length");
Lib_Keccak256.CTX memory c;
Lib_Keccak256.CTX memory c;
c.A = largePreimageState[msg.sender];
c.A = largePreimageState[msg.sender];
...
@@ -90,12 +86,7 @@ contract MIPSMemory {
...
@@ -90,12 +86,7 @@ contract MIPSMemory {
uint len = largePreimage[msg.sender].len + idat.length;
uint len = largePreimage[msg.sender].len + idat.length;
uint32 data = largePreimage[msg.sender].data;
uint32 data = largePreimage[msg.sender].data;
if (offset >= 0) {
if (offset >= 0) {
// comes from this block
data = fbo(dat, uint(offset));
data =
uint32(uint8(dat[uint256(offset)+0])) << 24 |
uint32(uint8(dat[uint256(offset)+1])) << 16 |
uint32(uint8(dat[uint256(offset)+2])) << 8 |
uint32(uint8(dat[uint256(offset)+3])) << 0;
}
}
dat[135] = bytes1(uint8(0x80));
dat[135] = bytes1(uint8(0x80));
dat[idat.length] |= bytes1(uint8(0x1));
dat[idat.length] |= bytes1(uint8(0x1));
...
@@ -138,6 +129,14 @@ contract MIPSMemory {
...
@@ -138,6 +129,14 @@ contract MIPSMemory {
return ret;
return ret;
}
}
function fbo(bytes memory dat, uint offset) internal pure returns (uint32) {
uint32 ret = uint32(uint8(dat[offset+0])) << 24 |
uint32(uint8(dat[offset+1])) << 16 |
uint32(uint8(dat[offset+2])) << 8 |
uint32(uint8(dat[offset+3]));
return ret;
}
function WriteMemory(bytes32 stateHash, uint32 addr, uint32 value) public returns (bytes32) {
function WriteMemory(bytes32 stateHash, uint32 addr, uint32 value) public returns (bytes32) {
require(addr & 3 == 0, "write memory must be 32-bit aligned");
require(addr & 3 == 0, "write memory must be 32-bit aligned");
return Lib_MerkleTrie.update(tb(addr>>2), tb(value), stateHash);
return Lib_MerkleTrie.update(tb(addr>>2), tb(value), stateHash);
...
...
test/libkeccak.js
View file @
5f9697f6
...
@@ -18,7 +18,7 @@ describe("MIPSMemory contract", function () {
...
@@ -18,7 +18,7 @@ describe("MIPSMemory contract", function () {
console
.
log
(
"
test size
"
,
n
)
console
.
log
(
"
test size
"
,
n
)
expect
((
await
mm
.
AddLargePreimageFinal
(
test
))[
0
]).
to
.
equal
(
keccak256
(
test
));
expect
((
await
mm
.
AddLargePreimageFinal
(
test
))[
0
]).
to
.
equal
(
keccak256
(
test
));
}
}
await
tl
(
0
)
await
tl
(
1
)
await
tl
(
100
)
await
tl
(
100
)
await
tl
(
134
)
await
tl
(
134
)
await
tl
(
135
)
await
tl
(
135
)
...
...
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