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

Fix light client bug #2509

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Fix light client bug #2509

wants to merge 6 commits into from

Conversation

zacshowa
Copy link
Member

This PR:

Fixes some bugs in the light client that would return invalid snapshots when the snapshot of the height requested was in the last index of stateHistoryCommitments

Key places to review:

contracts/src/LightClient.sol

Things tested:

Consumers of the light client are no longer affected by this bug

For some reason when branching off of main running `just gen-bindings`
also regenerates the LightClientArbitrum_bytecode file and I can't get
the commit to work without including it.
@zacshowa
Copy link
Member Author

The light client test is still failing locally.

I need to figure out how to add one additional entry to its state to give us a valid target as the "max height" to read from. When we only have one state we can't read it with this change, and we can't read from an index less than zero.

I also want to add a case where we expect a revert when trying to read from the most recent state

Copy link
Member

@jbearer jbearer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good to me, pending the additional testing you suggested. It would also be good to have @alysiahuggins @alxiong @0xkato look at this

Copy link
Contributor

@alxiong alxiong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code comment on getHotshotCommitment is wrong. Please update that as well.
Would be nice to include the reason for this boundary condition in the code comment.

Otherwise looks good to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like Alex mentioned update comments here and here otherwise it looks good!

Copy link
Contributor

@alysiahuggins alysiahuggins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm except for the failing test test_GetHotShotCommitmentValid where I've left a comment.

// Get the highest HotShot blockheight recorded
uint256 numCommitments = lc.getStateHistoryCount();
(,, hotShotBlockHeight, hotShotBlockComm) = lc.stateHistoryCommitments(numCommitments - 1);
(,, hotShotBlockHeight, hotShotBlockComm) = lc.stateHistoryCommitments(numCommitments - 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there, There's an integer underflow here because at this point there's only one state history commitment that would have been set so numCommitments = 1. What was the reason for subtracting 2?

Copy link
Member Author

@zacshowa zacshowa Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't fully fixed this test yet. It should be fixed in this commit. We don't actually need to subtract by 2, but now the function semantic is different in that it will return 1 index in the list past what it previously did. Because of this I had to adjust the height passed into the next function.

@zacshowa zacshowa marked this pull request as ready for review January 31, 2025 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants