Commit a5e93d4e authored by George Hotz's avatar George Hotz

1m gas to do an update isn't bad at all

parent cda61290
...@@ -16,23 +16,23 @@ contract MIPSMemory { ...@@ -16,23 +16,23 @@ contract MIPSMemory {
} }
// one per owner (at a time) // one per owner (at a time)
mapping(address => uint64[25]) public largePreimages; mapping(address => uint64[25]) public largePreimage;
function AddLargePreimageInit() public { function AddLargePreimageInit() public {
Lib_Keccak256.CTX memory c; Lib_Keccak256.CTX memory c;
Lib_Keccak256.keccak_init(c); Lib_Keccak256.keccak_init(c);
largePreimages[msg.sender] = c.A; largePreimage[msg.sender] = c.A;
} }
function AddLargePreimageUpdate(uint64[17] calldata data) public { function AddLargePreimageUpdate(uint64[17] calldata data) public {
// sha3_process_block // sha3_process_block
Lib_Keccak256.CTX memory c; Lib_Keccak256.CTX memory c;
c.A = largePreimages[msg.sender]; c.A = largePreimage[msg.sender];
for (uint i = 0; i < 17; i++) { for (uint i = 0; i < 17; i++) {
c.A[i] ^= data[i]; c.A[i] ^= data[i];
} }
Lib_Keccak256.sha3_permutation(c); Lib_Keccak256.sha3_permutation(c);
largePreimages[msg.sender] = c.A; largePreimage[msg.sender] = c.A;
} }
function AddLargePreimageFinal(uint64[17] calldata data) public { function AddLargePreimageFinal(uint64[17] calldata data) public {
......
/** /**
* @type import('hardhat/config').HardhatUserConfig * @type import('hardhat/config').HardhatUserConfig
*/ */
require("@nomiclabs/hardhat-ethers");
require("hardhat-gas-reporter");
module.exports = { module.exports = {
solidity: { solidity: {
version: "0.7.3", version: "0.7.3",
......
const { expect } = require("chai");
describe("MIPSMemory contract", function () {
it("Keccak should work", async function () {
const [owner] = await ethers.getSigners();
const MIPSMemory = await ethers.getContractFactory("MIPSMemory");
const mm = await MIPSMemory.deploy();
console.log("deployed at", mm.address, "by", owner.address);
await mm.AddLargePreimageInit();
console.log("preimage initted");
var a = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
await mm.AddLargePreimageUpdate(a);
console.log("preimage updated");
var tst = await mm.largePreimage(owner.address, 0);
console.log(tst);
});
});
\ No newline at end of file
This diff is collapsed.
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