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

Execute the read hotshot commitment opcode #3

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion src/osp/OneStepProofEntry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ contract OneStepProofEntry is IOneStepProofEntry {
} else if (
(opcode >= Instructions.GET_GLOBAL_STATE_BYTES32 &&
opcode <= Instructions.SET_GLOBAL_STATE_U64) ||
(opcode >= Instructions.READ_PRE_IMAGE && opcode <= Instructions.HALT_AND_SET_FINISHED)
(opcode >= Instructions.READ_PRE_IMAGE && opcode <= Instructions.HALT_AND_SET_FINISHED) ||
(opcode == Instructions.READ_HOTSHOT_COMMITMENT)
) {
prover = proverHostIo;
} else {
Expand Down
43 changes: 43 additions & 0 deletions src/osp/OneStepProverHostIo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,47 @@ contract OneStepProverHostIo is IOneStepProver {
return true;
}

function executeReadHotShotCommitment(
ExecutionContext calldata execCtx,
Machine memory mach,
Module memory mod,
Instruction calldata,
bytes calldata proof
) internal view {
uint256 height = mach.valueStack.pop().assumeI64();
uint256 ptr = mach.valueStack.pop().assumeI32();

if (ptr + 32 > mod.moduleMemory.size || ptr % LEAF_SIZE != 0) {
mach.status = MachineStatus.ERRORED;
return;
}

uint256 leafIdx = ptr / LEAF_SIZE;
uint256 proofOffset = 0;
bytes32 leafContents;
MerkleProof memory merkleProof;
(leafContents, proofOffset, merkleProof) = mod.moduleMemory.proveLeaf(
leafIdx,
proof,
proofOffset
);

bytes calldata commitment = proof[proofOffset:proofOffset+32];
bool success = validateHotShotCommitment(execCtx, height, commitment);
if (!success) {
return;
}
}

function validateHotShotCommitment(
ExecutionContext calldata,
uint256 ,
bytes calldata
) internal view returns (bool) {
// Get the hotshot commitment via the height
return true;
}

function executeReadInboxMessage(
ExecutionContext calldata execCtx,
Machine memory mach,
Expand Down Expand Up @@ -348,6 +389,8 @@ contract OneStepProverHostIo is IOneStepProver {
impl = executeReadInboxMessage;
} else if (opcode == Instructions.HALT_AND_SET_FINISHED) {
impl = executeHaltAndSetFinished;
} else if (opcode == Instructions.READ_HOTSHOT_COMMITMENT) {
impl = executeReadHotShotCommitment;
} else {
revert("INVALID_MEMORY_OPCODE");
}
Expand Down
2 changes: 2 additions & 0 deletions src/state/Instructions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ library Instructions {
uint16 internal constant READ_INBOX_MESSAGE = 0x8021;
uint16 internal constant HALT_AND_SET_FINISHED = 0x8022;

uint16 internal constant READ_HOTSHOT_COMMITMENT = 0x9001;

uint256 internal constant INBOX_INDEX_SEQUENCER = 0;
uint256 internal constant INBOX_INDEX_DELAYED = 1;

Expand Down