Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IS_HOTSHOT_LIVE opcode #7

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading