Skip to content

Commit

Permalink
Remove HotShot instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJeremyHe committed Dec 6, 2024
1 parent ebeb0fb commit 55c9489
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 176 deletions.
15 changes: 0 additions & 15 deletions src/bridge/IHotShot.sol

This file was deleted.

3 changes: 1 addition & 2 deletions src/osp/OneStepProofEntry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ contract OneStepProofEntry is IOneStepProofEntry {
(opcode >= Instructions.GET_GLOBAL_STATE_BYTES32 &&
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.IS_HOTSHOT_LIVE)
(opcode >= Instructions.NEW_COTHREAD && opcode <= Instructions.SWITCH_COTHREAD)
) {
prover = proverHostIo;
} else {
Expand Down
104 changes: 0 additions & 104 deletions src/osp/OneStepProverHostIo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import "../state/ModuleMemory.sol";
import "./IOneStepProver.sol";
import "../bridge/Messages.sol";
import "../bridge/IBridge.sol";
import "../bridge/IHotShot.sol";

contract OneStepProverHostIo is IOneStepProver {
using GlobalStateLib for GlobalState;
Expand All @@ -25,21 +24,11 @@ contract OneStepProverHostIo is IOneStepProver {
using ValueStackLib for ValueStack;
using StackFrameLib for StackFrameWindow;

IHotShot public hotshot;

constructor(address hotshotAddr) {
hotshot = IHotShot(hotshotAddr);
}

uint256 private constant LEAF_SIZE = 32;
uint256 private constant INBOX_NUM = 2;
uint64 private constant INBOX_HEADER_LEN = 40;
uint64 private constant DELAYED_HEADER_LEN = 112 + 1;

// Hard coded for now. Find out a way to access the arb config
// in this contract and move this constant into the configuration.
uint256 private constant ESPRESSO_ESCAPE_HATCH_DELAY_THRESHOLD = 3;

function setLeafByte(
bytes32 oldLeaf,
uint256 idx,
Expand All @@ -54,10 +43,6 @@ contract OneStepProverHostIo is IOneStepProver {
return bytes32(newLeaf);
}

function _getHotShotCommitment(uint256 h) external view returns (uint256) {
return hotshot.getHotShotCommitment(h).blockCommRoot;
}

function executeGetOrSetBytes32(
Machine memory mach,
Module memory mod,
Expand Down Expand Up @@ -315,91 +300,6 @@ 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();
uint256 threshold = ESPRESSO_ESCAPE_HATCH_DELAY_THRESHOLD;
uint8 liveness = uint8(proof[0]);
require(validateHotShotLiveness(execCtx, height, threshold, liveness > 0), "WRONG_HOTSHOT_LIVENESS");

}

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

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);
require(success, "ERROR_HOTSHOT_COMMITMENT");

for (uint32 i = 0; i < 32; i++) {
leafContents = setLeafByte(leafContents, i, uint8(proof[proofOffset + i]));
}

mod.moduleMemory.merkleRoot = merkleProof.computeRootFromMemory(leafIdx, leafContents);
}

function validateHotShotCommitment(
ExecutionContext calldata,
uint256 height,
bytes calldata commitment
) internal view returns (bool) {
uint256 expected = hotshot.getHotShotCommitment(height).blockCommRoot;
require(expected != 0, "EMPTY HOTSHOT COMMITMENT");
bytes memory b = new bytes(32);
assembly {
mstore(add(b, 32), expected)
}

if (commitment.length != 32) {
return false;
}

for (uint256 i = 0; i < b.length; i++) {
if (b[i] != commitment[i]) {
return false;
}
}

return true;
}

function executeReadInboxMessage(
ExecutionContext calldata execCtx,
Machine memory mach,
Expand Down Expand Up @@ -740,10 +640,6 @@ contract OneStepProverHostIo is IOneStepProver {
impl = executePopCoThread;
} else if (opcode == Instructions.SWITCH_COTHREAD) {
impl = executeSwitchCoThread;
} else if (opcode == Instructions.READ_HOTSHOT_COMMITMENT) {
impl = executeReadHotShotCommitment;
} else if (opcode == Instructions.IS_HOTSHOT_LIVE) {
impl = executeIsHotShotLive;
}
else {
revert("INVALID_MEMORY_OPCODE");
Expand Down
3 changes: 0 additions & 3 deletions src/state/Instructions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ library Instructions {
uint16 internal constant POP_COTHREAD = 0x8031;
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
38 changes: 0 additions & 38 deletions src/test-helpers/HotShot.sol

This file was deleted.

15 changes: 1 addition & 14 deletions test/foundry/RollupCreator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"
import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol";
import {EspressoTEEVerifierMock} from "../../src/mocks/EspressoTEEVerifier.sol";

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

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

contract RollupCreatorTest is Test {
RollupCreator public rollupCreator;
address public rollupOwner = makeAddr("rollupOwner");
Expand All @@ -37,7 +29,6 @@ contract RollupCreatorTest is Test {
IRollupUser public rollupUser;
DeployHelper public deployHelper;
IReader4844 dummyReader4844 = IReader4844(address(137));
MockHotShot public hotshot = new MockHotShot();

// 1 gwei
uint256 public constant MAX_FEE_PER_GAS = 1_000_000_000;
Expand Down Expand Up @@ -67,10 +58,6 @@ contract RollupCreatorTest is Test {
rollupCreator = new RollupCreator();
deployHelper = new DeployHelper();

for (uint256 i = 1; i < 10; i++) {
hotshot.setCommitment(uint256(i), uint256(i));
}

// deploy BridgeCreators
BridgeCreator bridgeCreator = new BridgeCreator(ethBasedTemplates, erc20BasedTemplates);

Expand Down Expand Up @@ -515,7 +502,7 @@ contract RollupCreatorTest is Test {
new OneStepProver0(),
new OneStepProverMemory(),
new OneStepProverMath(),
new OneStepProverHostIo(address(hotshot))
new OneStepProverHostIo()
);
challengeManager = new ChallengeManager();

Expand Down

0 comments on commit 55c9489

Please sign in to comment.