From a1048643760777144d48337ace56d8e701769d28 Mon Sep 17 00:00:00 2001 From: pcw109550 Date: Tue, 6 Feb 2024 20:17:33 +0900 Subject: [PATCH] fasdinfasdofasdiofnasodfiasd --- rvsol/src/Step.sol | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/rvsol/src/Step.sol b/rvsol/src/Step.sol index f6d408a4..bd41ab31 100644 --- a/rvsol/src/Step.sol +++ b/rvsol/src/Step.sol @@ -6,11 +6,13 @@ import { PreimageKeyLib } from "./PreimageKeyLib.sol"; contract Step { IPreimageOracle public preimageOracle; - address public preimageKeyLib; constructor(IPreimageOracle _preimageOracle) { preimageOracle = _preimageOracle; - preimageKeyLib = address(PreimageKeyLib); + } + + function localize(bytes32 _key, bytes32 _localContext) public view returns (bytes32 localizedKey_) { + return PreimageKeyLib.localize(_key, _localContext); } // Executes a single RISC-V instruction, starting from @@ -24,10 +26,6 @@ contract Step { function preimageOraclePos() -> out { // slot of preimageOraclePos field out := 0 } - function preimageKeyLibPos() -> out { // slot of preimageKeyLib field - out := 1 - } - // // Yul64 - functions to do 64 bit math - see yul64.go // @@ -784,6 +782,21 @@ contract Step { } function localize(preImageKey, localContext_) -> localizedKey { + // calling address(this).localize(bytes32,bytes32) + // eventually calling PreimageKeyLib.localize(bytes32,bytes32) + 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 := delegatecall(cgas, address(), memPtr, 0x44, 0x00, 0x20) // output into scratch space + if res { // 1 on success + localizedKey := mload(0x00) + leave + } + revertWithCode(0x1234dead) + // let addr := sload(preimageKeyLibPos()) // calling PreimageKeyLib.localize(bytes32,bytes32) // 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 @@ -803,15 +816,15 @@ contract Step { // // TODO: deduplicate definition of localize using lib // // 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 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) } function readPreimageValue(addr, count, localContext_) -> out {