Skip to content

Commit

Permalink
Merge pull request #7 from EspressoSystems/jh/escape
Browse files Browse the repository at this point in the history
Add IS_HOTSHOT_LIVE opcode
  • Loading branch information
ImJeremyHe authored May 23, 2024
2 parents 75443b7 + 7c20696 commit dad781b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/osp/OneStepProofEntry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ contract OneStepProofEntry is IOneStepProofEntry {
opcode <= Instructions.SET_GLOBAL_STATE_U64) ||
(opcode >= Instructions.READ_PRE_IMAGE && opcode <= Instructions.UNLINK_MODULE) ||
(opcode >= Instructions.NEW_COTHREAD && opcode <= Instructions.SWITCH_COTHREAD) ||
(opcode == Instructions.READ_HOTSHOT_COMMITMENT)
(opcode == Instructions.READ_HOTSHOT_COMMITMENT || opcode == Instructions.IS_HOTSHOT_LIVE)
) {
prover = proverHostIo;
} else {
Expand Down
28 changes: 27 additions & 1 deletion src/osp/OneStepProverHostIo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import "../bridge/IBridge.sol";

interface IHotShot {
function commitments(uint256) external view returns (uint256);
function availabilities(uint256) external view returns (bool);
}

contract OneStepProverHostIo is IOneStepProver {
Expand Down Expand Up @@ -314,6 +315,28 @@ contract OneStepProverHostIo is IOneStepProver {
return true;
}

function executeIsHotShotLive(
ExecutionContext calldata execCtx,
Machine memory mach,
Module memory,
Instruction calldata,
bytes calldata proof
) internal view {
uint256 height = mach.valueStack.pop().assumeI64();
uint8 liveness = uint8(proof[0]);
require(validateHotShotLiveness(execCtx, height, liveness > 0), "WRONG_HOTSHOT_LIVENESS");

}

function validateHotShotLiveness(
ExecutionContext calldata,
uint256 height,
bool result
) internal view returns (bool) {
bool expected = hotshot.availabilities(height);
return result == expected;
}

function executeReadHotShotCommitment(
ExecutionContext calldata execCtx,
Machine memory mach,
Expand Down Expand Up @@ -717,7 +740,10 @@ contract OneStepProverHostIo is IOneStepProver {
impl = executeSwitchCoThread;
} else if (opcode == Instructions.READ_HOTSHOT_COMMITMENT) {
impl = executeReadHotShotCommitment;
} else {
} else if (opcode == Instructions.IS_HOTSHOT_LIVE) {
impl = executeIsHotShotLive;
}
else {
revert("INVALID_MEMORY_OPCODE");
}

Expand Down
1 change: 1 addition & 0 deletions src/state/Instructions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ library Instructions {
uint16 internal constant SWITCH_COTHREAD = 0x8032;

uint16 internal constant READ_HOTSHOT_COMMITMENT = 0x9001;
uint16 internal constant IS_HOTSHOT_LIVE = 0x9002;

uint256 internal constant INBOX_INDEX_SEQUENCER = 0;
uint256 internal constant INBOX_INDEX_DELAYED = 1;
Expand Down
5 changes: 5 additions & 0 deletions src/test-helpers/HotShot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ pragma solidity ^0.8.0;

contract MockHotShot {
mapping(uint256 => uint256) public commitments;
mapping(uint256 => bool) public availabilities;

function setCommitment(uint256 height, uint256 commitment) external {
commitments[height] = commitment;
}

function setAvailability(uint256 l1Height, bool isLive) external {
availabilities[l1Height] = isLive;
}
}

0 comments on commit dad781b

Please sign in to comment.