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 13486f6
Show file tree
Hide file tree
Showing 3 changed files with 49 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);
}
16 changes: 7 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 Down Expand Up @@ -55,7 +51,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 +319,19 @@ contract OneStepProverHostIo is IOneStepProver {
bytes calldata proof
) internal view {
uint256 height = mach.valueStack.pop().assumeI64();
uint256 threshold = mach.valueStack.pop().assumeI64();
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 +376,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 13486f6

Please sign in to comment.