From d2cf72acbcf7b7242ac4ca65cb16d88280145daf Mon Sep 17 00:00:00 2001 From: pcw109550 Date: Mon, 5 Feb 2024 13:12:57 +0900 Subject: [PATCH] Try to use call for DRY --- rvsol/src/Step.sol | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/rvsol/src/Step.sol b/rvsol/src/Step.sol index 424ef042..6cb4fabd 100644 --- a/rvsol/src/Step.sol +++ b/rvsol/src/Step.sol @@ -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 {