Skip to content

Commit

Permalink
Try to use call for DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
pcw109550 committed Feb 5, 2024
1 parent 8c8fea8 commit d2cf72a
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions rvsol/src/Step.sol
Original file line number Diff line number Diff line change
Expand Up @@ -774,24 +774,28 @@ contract Step {
}

function localize(preImageKey, localContext_) -> localizedKey {
// Grab the current free memory pointer to restore later.
let ptr := mload(0x40)
// Store the local data key and caller next to each other in memory for hashing.
mstore(0, preImageKey)
mstore(0x20, caller())
mstore(0x40, localContext_)
// Localize the key with the above `localize` operation.
localizedKey := or(and(keccak256(0, 0x60), not(shl(248, 0xFF))), shl(248, 1))
// Restore the free memory pointer.
mstore(0x40, ptr)

// let memPtr := mload(0x40) // get pointer to free memory for preimage interactions
let addr := sload(preimageOraclePos())
let memPtr := mload(0x40) // get pointer to free memory for preimage interactions
mstore(memPtr, shl(224, 0x1aae47f0)) // (32-4)*8=224: right-pad the function selector, and then store it as prefix
mstore(add(memPtr, 0x04), preImageKey)
mstore(add(memPtr, 0x24), localContext_)
let cgas := 100000 // TODO change call gas
let res := call(cgas, addr, 0, memPtr, 0x44, 0x00, 0x20) // output into scratch space
if res { // 1 on success
localizedKey := mload(0x00)
}
revertWithCode(0xbadf00d0)

// // Grab the current free memory pointer to restore later.
// let ptr := mload(0x40)
// // Store the local data key and caller next to each other in memory for hashing.
// mstore(memPtr, preImageKey)
// mstore(add(memPtr, 0x20), caller())
// mstore(add(memPtr, 0x40), localContext_)
// // Localize the key
// localizedKey := or(and(keccak256(memPtr, 0x60), not(shl(248, 0xFF))), shl(248, 1))
// mstore(0, preImageKey)
// mstore(0x20, caller())
// mstore(0x40, localContext_)
// // Localize the key with the above `localize` operation.
// localizedKey := or(and(keccak256(0, 0x60), not(shl(248, 0xFF))), shl(248, 1))
// // Restore the free memory pointer.
// mstore(0x40, ptr)
}

function readPreimageValue(addr, count, localContext_) -> out {
Expand Down

0 comments on commit d2cf72a

Please sign in to comment.