Skip to content

Commit

Permalink
Update hotshot contract interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJeremyHe committed Jun 17, 2024
1 parent dad781b commit 9837543
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
15 changes: 15 additions & 0 deletions src/bridge/IHotShot.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

struct HotShotCommitment {
uint64 blockHeight;
uint256 blockCommRoot;
}

interface IHotShot {
function getHotShotCommitment(uint256 hotShotBlockHeight) external view returns (HotShotCommitment memory);
function lagOverEscapeHatchThreshold(
uint256 blockNumber,
uint256 threshold
) external view returns (bool);
}
20 changes: 11 additions & 9 deletions src/osp/OneStepProverHostIo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ import "../state/ModuleMemory.sol";
import "./IOneStepProver.sol";
import "../bridge/Messages.sol";
import "../bridge/IBridge.sol";

interface IHotShot {
function commitments(uint256) external view returns (uint256);
function availabilities(uint256) external view returns (bool);
}
import "../bridge/IHotShot.sol";

contract OneStepProverHostIo is IOneStepProver {
using GlobalStateLib for GlobalState;
Expand All @@ -40,6 +36,10 @@ contract OneStepProverHostIo is IOneStepProver {
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 @@ -55,7 +55,7 @@ contract OneStepProverHostIo is IOneStepProver {
}

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

function executeGetOrSetBytes32(
Expand Down Expand Up @@ -323,17 +323,19 @@ contract OneStepProverHostIo is IOneStepProver {
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, liveness > 0), "WRONG_HOTSHOT_LIVENESS");
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.availabilities(height);
bool expected = hotshot.lagOverEscapeHatchThreshold(height, threshold);
return result == expected;
}

Expand Down Expand Up @@ -378,7 +380,7 @@ contract OneStepProverHostIo is IOneStepProver {
uint256 height,
bytes calldata commitment
) internal view returns (bool) {
uint256 expected = hotshot.commitments(height);
uint256 expected = hotshot.getHotShotCommitment(height).blockCommRoot;
require(expected != 0, "EMPTY HOTSHOT COMMITMENT");
bytes memory b = new bytes(32);
assembly {
Expand Down
31 changes: 27 additions & 4 deletions src/test-helpers/HotShot.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

contract MockHotShot {
import "../bridge/IHotShot.sol";

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

function getHotShotCommitment(uint256 hotShotBlockHeight)
external
view
override
returns (HotShotCommitment memory)
{
return HotShotCommitment({
blockHeight: uint64(hotShotBlockHeight),
blockCommRoot: commitments[hotShotBlockHeight]
});
}

function lagOverEscapeHatchThreshold(uint256 blockNumber, uint256 threshold)
external
view
override
returns (bool)
{
return true;
}

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

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

0 comments on commit 9837543

Please sign in to comment.