From 9837543b05aeab8e022523d1fa927d390e9540b4 Mon Sep 17 00:00:00 2001 From: ImJeremyHe Date: Mon, 17 Jun 2024 10:22:49 +0800 Subject: [PATCH] Update hotshot contract interface --- src/bridge/IHotShot.sol | 15 +++++++++++++++ src/osp/OneStepProverHostIo.sol | 20 +++++++++++--------- src/test-helpers/HotShot.sol | 31 +++++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 src/bridge/IHotShot.sol diff --git a/src/bridge/IHotShot.sol b/src/bridge/IHotShot.sol new file mode 100644 index 00000000..47ef172e --- /dev/null +++ b/src/bridge/IHotShot.sol @@ -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); +} diff --git a/src/osp/OneStepProverHostIo.sol b/src/osp/OneStepProverHostIo.sol index d4d4f9a2..91c28ad9 100644 --- a/src/osp/OneStepProverHostIo.sol +++ b/src/osp/OneStepProverHostIo.sol @@ -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; @@ -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, @@ -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( @@ -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; } @@ -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 { diff --git a/src/test-helpers/HotShot.sol b/src/test-helpers/HotShot.sol index 3de0511e..d002dfb3 100644 --- a/src/test-helpers/HotShot.sol +++ b/src/test-helpers/HotShot.sol @@ -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; } }