Commit 481daf75 authored by George Hotz's avatar George Hotz

fix lib_keccak256

parent d3088b7a
......@@ -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 {
......
......@@ -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
......@@ -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");
......
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