Skip to content

Commit

Permalink
Merge branch 'main' into hotshot/rc-0.5.59
Browse files Browse the repository at this point in the history
  • Loading branch information
jparr721 authored Jun 24, 2024
2 parents 7862a1d + cae4960 commit 89efa27
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion contract-bindings/artifacts/LightClientMock_bytecode.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contract-bindings/artifacts/LightClient_bytecode.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions contract-bindings/src/light_client.rs

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions contracts/src/LightClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -421,19 +421,22 @@ contract LightClient is Initializable, OwnableUpgradeable, UUPSUpgradeable {
return stateUpdateBlockNumbers.length;
}

/// @notice get the HotShot commitment at the specified block height
/// @notice get the HotShot commitment that represents the Merkle root containing the leaf at
/// the provided height
/// @param hotShotBlockHeight hotShotBlockHeight
function getHotShotCommitment(uint256 hotShotBlockHeight)
public
view
returns (HotShotCommitment memory)
{
uint256 commitmentsHeight = hotShotCommitments.length;
if (hotShotBlockHeight > hotShotCommitments[commitmentsHeight - 1].blockHeight) {
if (hotShotBlockHeight >= hotShotCommitments[commitmentsHeight - 1].blockHeight) {
revert InvalidHotShotBlockForCommitmentCheck();
}
for (uint256 i = 0; i < commitmentsHeight; i++) {
if (hotShotCommitments[i].blockHeight >= hotShotBlockHeight) {
// The first commitment greater than the provided height is the root of the tree
// that leaf at that HotShot height
if (hotShotCommitments[i].blockHeight > hotShotBlockHeight) {
return hotShotCommitments[i];
}
}
Expand Down
11 changes: 6 additions & 5 deletions contracts/test/LightClient.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,10 @@ contract LightClient_HotShotCommUpdatesTest is LightClientCommonTest {
assertEq(BN254.ScalarField.unwrap(a), BN254.ScalarField.unwrap(b));
}

function assertNotEqBN254(BN254.ScalarField a, BN254.ScalarField b) public pure {
assertNotEq(BN254.ScalarField.unwrap(a), BN254.ScalarField.unwrap(b));
}

function test_hotShotBlockCommIsUpdated() public {
uint256 blockCommCount = lc.getHotShotBlockCommitmentsCount();

Expand Down Expand Up @@ -899,12 +903,9 @@ contract LightClient_HotShotCommUpdatesTest is LightClientCommonTest {
emit LC.NewState(newState.viewNum, newState.blockHeight, newState.blockCommRoot);
lc.newFinalizedState(newState, newProof);

// Test for a the same hotShotBlockHeight
BN254.ScalarField blockComm = lc.getHotShotCommitment(newState.blockHeight).blockCommRoot;
assertEqBN254(blockComm, newState.blockCommRoot);

// Test for a smaller hotShotBlockHeight
blockComm = lc.getHotShotCommitment(newState.blockHeight - 1).blockCommRoot;
BN254.ScalarField blockComm =
lc.getHotShotCommitment(newState.blockHeight - 1).blockCommRoot;
assertEqBN254(blockComm, newState.blockCommRoot);
}

Expand Down

0 comments on commit 89efa27

Please sign in to comment.