Skip to content

Commit

Permalink
fasdinfasdofasdiofnasodfiasd
Browse files Browse the repository at this point in the history
  • Loading branch information
pcw109550 committed Feb 6, 2024
1 parent 418b0f0 commit a104864
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions rvsol/src/Step.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
//
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit a104864

Please sign in to comment.