Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #125 from wangtsiao/pr/add_prue_typo
Browse files Browse the repository at this point in the history
add pure and fix typo 0x44
  • Loading branch information
protolambda committed Jun 16, 2023
2 parents 32c76db + bd63cb3 commit 220b051
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions contracts/src/MIPS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ contract MIPS {
return outputState();
}

function proofOffset(uint8 proofIndex) internal returns (uint256 offset) {
function proofOffset(uint8 proofIndex) internal pure returns (uint256 offset) {
// A proof of 32 bit memory, with 32-byte leaf values, is (32-5)=27 bytes32 entries.
// And the leaf value itself needs to be encoded as well. And proof.offset == 390
offset = 390 + (uint256(proofIndex) * (28*32));
Expand All @@ -318,7 +318,7 @@ contract MIPS {
return offset;
}

function readMem(uint32 addr, uint8 proofIndex) internal returns (uint32 out) {
function readMem(uint32 addr, uint8 proofIndex) internal pure returns (uint32 out) {
uint256 offset = proofOffset(proofIndex);
assembly {
if and(addr, 3) { revert(0, 0) } // quick addr alignment check
Expand Down Expand Up @@ -351,7 +351,7 @@ contract MIPS {
}

// writeMem writes the value by first overwriting the part of the leaf, and then recomputing the memory merkle root.
function writeMem(uint32 addr, uint8 proofIndex, uint32 value) internal {
function writeMem(uint32 addr, uint8 proofIndex, uint32 value) internal pure {
uint256 offset = proofOffset(proofIndex);
assembly {
if and(addr, 3) { revert(0, 0) } // quick addr alignment check
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract Oracle {
bytes32 key;
bytes32 part;
assembly {
size := calldataload(0x44) // len(sig) + len(partOffset) + len(preimage offset) = 4 + 32 + 32 = 0x64
size := calldataload(0x44) // len(sig) + len(partOffset) + len(preimage offset) = 4 + 32 + 32 = 0x44
if iszero(lt(partOffset, add(size, 8))) { // revert if part offset >= size+8 (i.e. parts must be within bounds)
revert(0, 0)
}
Expand Down

0 comments on commit 220b051

Please sign in to comment.