Skip to content

Commit

Permalink
Add IS_HOTSHOT_ALIVE opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJeremyHe committed May 22, 2024
1 parent 75443b7 commit aa56b8b
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_ALIVE)
) {
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 executeIsHotShotAlive(
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]);
validateHotShotLiveness(execCtx, height, liveness > 0);

}

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_ALIVE) {
impl = executeIsHotShotAlive;
}
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_ALIVE = 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 isAlive) external {
availabilities[l1Height] = isAlive;
}
}

0 comments on commit aa56b8b

Please sign in to comment.