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

Freeze l1 height in the mock contract #1650

Merged
merged 3 commits into from
Jul 2, 2024
Merged
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

Large diffs are not rendered by default.

104 changes: 102 additions & 2 deletions contract-bindings/src/light_client_mock.rs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions contracts/src/LightClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,11 @@ contract LightClient is Initializable, OwnableUpgradeable, UUPSUpgradeable {
/// L1 Block Number
/// @param blockNumber The L1 block number
/// @param threshold The number of blocks updates to this contract is allowed to lag behind
/// Marked as `virtual` for easily testing.
function lagOverEscapeHatchThreshold(uint256 blockNumber, uint256 threshold)
public
view
virtual
returns (bool)
{
uint256 updatesCount = stateUpdateBlockNumbers.length;
Expand Down
25 changes: 25 additions & 0 deletions contracts/test/mocks/LightClientMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { LightClientStateUpdateVKMock as VkLib } from "./LightClientStateUpdateV

/// @dev A helper that wraps LightClient contract for testing
contract LightClientMock is LC {
bool internal hotShotDown;
uint256 internal frozenL1Height;

constructor(LC.LightClientState memory genesis, uint32 numBlockPerEpoch) LC() {
_initializeState(genesis, numBlockPerEpoch);
}
Expand Down Expand Up @@ -65,4 +68,26 @@ contract LightClientMock is LC {
hotShotCommitments.push(values[i]);
}
}

function setHotShotDownSince(uint256 l1Height) public {
hotShotDown = true;
frozenL1Height = l1Height;
}

function setHotShotUp() public {
hotShotDown = false;
}

/// @dev override the production-implementation with frozen data
function lagOverEscapeHatchThreshold(uint256 blockNumber, uint256 threshold)
public
view
override
returns (bool)
{
if (hotShotDown) {
return blockNumber - frozenL1Height > threshold;
}
return super.lagOverEscapeHatchThreshold(blockNumber, threshold);
}
}
Loading