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

refactor: static stake table simplication, simpler LightClientState #1939

Conversation

alysiahuggins
Copy link
Contributor

@alysiahuggins alysiahuggins commented Aug 29, 2024

… finalized state

Closes #1938

This PR:

  • removes states mapping
  • added global variable for genesisState, genesisStakeState and finalizedState
  • removes fields from the LightClientState and adds a new struct StakeState
  • WIP

This PR does not:

Key places to review:

@philippecamacho
Copy link
Contributor

philippecamacho commented Aug 31, 2024

Made some progress fixing the compilation errors but not there yet:

  • Created a new branch of HotShot (fork of tag = "0.5.72") and added the StakeState struct.
  • Have the espresso-sequencer repository point to this branch
  • Fixed several compilation errors.

Right now, for some reason the espresso-types crates does not compile.

cc @alysiahuggins @alxiong

…branch, lc-contract-updates and ensure that all references to the StakeState compiles
@alysiahuggins
Copy link
Contributor Author

alysiahuggins commented Sep 3, 2024

the branch, lc-contract-updates, has been added to the following repos so that we can support the new types introduced by this ticket by pointing all repos that rely on hotshot to that branch d391f7e:

…he process of updating the related adapte and hotshot-state-prover code e.g. the MockGenesis action
@alysiahuggins
Copy link
Contributor Author

  • removed fields from the LightClientState struct so it now looks like this
struct LightClientState {
        uint64 viewNum;
        uint64 blockHeight;
        BN254.ScalarField blockCommRoot;
    }
  • updated related rust code such as the lightclient adapter and MockGenesis action in the diff-tests, to continue, one would have to also update the MockConsecutiveFinalizedStates, MockSkipBlocks, MockMissEndingBlock etc

3a27dda
this git commit ignored verification checks so that anyone can pick up from where i left off.

contracts/src/LightClient.sol Outdated Show resolved Hide resolved
contracts/src/LightClient.sol Outdated Show resolved Hide resolved
contracts/src/LightClient.sol Outdated Show resolved Hide resolved
contracts/src/LightClient.sol Outdated Show resolved Hide resolved
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.

I've looked at adapter/*, diff-test , hotshot-state-prover
they all look very good to me. Alysia is doing great work. 👏 (chore, but she does them with precision)

I have addressed all of my own comments in #1986

contracts/rust/adapter/src/light_client.rs Outdated Show resolved Hide resolved
hotshot-state-prover/src/mock_ledger.rs Outdated Show resolved Hide resolved
hotshot-state-prover/src/mock_ledger.rs Outdated Show resolved Hide resolved
hotshot-state-prover/src/circuit.rs Show resolved Hide resolved
hotshot-state-prover/src/service.rs Outdated Show resolved Hide resolved
@alxiong
Copy link
Contributor

alxiong commented Sep 4, 2024

@mrain can you also take a look at Alysia's changes to the circuit.rs. The changes look good to me at least.

for reference, we are simplifying light client state as specified in #1938

thanks!

@mrain
Copy link
Contributor

mrain commented Sep 4, 2024

@mrain can you also take a look at Alysia's changes to the circuit.rs. The changes look good to me at least.

for reference, we are simplifying light client state as specified in #1938

thanks!

LGTM. Changes are simple enough.

schnorr_key_comm: field_to_u256(stt.stake_table_schnorr_key_comm),
amount_comm: field_to_u256(stt.stake_table_amount_comm),
};
stake_stakes.push(parsed_stake_state.into());
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like stake_stakes vector is not returned. Why is that?

Copy link
Contributor

Choose a reason for hiding this comment

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

this will be removed in my future commit of mine

Copy link
Contributor

Choose a reason for hiding this comment

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

removed in af51261

Comment on lines -71 to -74
circuit.create_public_variable(state.fee_ledger_comm)?,
circuit.create_public_variable(state.stake_table_comm.0)?,
circuit.create_public_variable(state.stake_table_comm.1)?,
circuit.create_public_variable(state.stake_table_comm.2)?,
Copy link
Contributor

@alxiong alxiong Sep 5, 2024

Choose a reason for hiding this comment

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

ah this is wrong actually. 🤦
(i missed it yesterday when I reviewed it, and wasted some time today assuming our Public input is reduced to 4)

we should still keep the stake table commitments in the public inputs for security/integrity!!

but we can safely remove fee_ledger_comm, so PI.length is 7 now.

cc @mrain @alysiahuggins

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, I need to fix HotShot side as well for the struct declaration.

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed in ab81b0b

Comment on lines 310 to 320
let stake_amount_comm = RescueNativeGadget::<F>::rescue_sponge_with_padding(
let _stake_amount_comm = RescueNativeGadget::<F>::rescue_sponge_with_padding(
&mut circuit,
&stake_amount_preimage_vars,
1,
)?[0];
circuit.enforce_equal(
stake_amount_comm,
lightclient_state_pub_var
.stake_table_comm()
.stake_amount_comm,
)?;
Copy link
Contributor

@alxiong alxiong Sep 5, 2024

Choose a reason for hiding this comment

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

realized that these are wrong, we need these to ensure security.

sry that I miss it during my last review.

(p.s. I'm fixing these locally, will push soon)

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed in ab81b0b

alxiong and others added 6 commits September 6, 2024 01:02
…e-struct-and-remove-states-mapping' into 1938-update-state-prover
* update PublicInput length from 8 to 4

* Revert "update PublicInput length from 8 to 4"

This reverts commit 40e2c67.

* update PublicInput length from 8 to 7.

---------

Co-authored-by: Philippe Camacho <[email protected]>
@alxiong alxiong marked this pull request as ready for review September 9, 2024 15:24
@alxiong alxiong changed the title switch from states mapping to two state variables for the genesis and… refactor: static stake table simplication, simpler LightClientState Sep 9, 2024
@alxiong alxiong enabled auto-merge September 9, 2024 15:29
@alxiong alxiong merged commit 745d468 into main Sep 9, 2024
15 checks passed
@alxiong alxiong deleted the 1938-simplify-light-client-contract-create-genesis-state-struct-and-remove-states-mapping branch September 9, 2024 15:42
sveitser added a commit to EspressoSystems/nitro-testnode that referenced this pull request Sep 16, 2024
In EspressoSystems/espresso-sequencer#1939
the light client ABI changed and as a result we need to make changes in
multiple places.

The tracking issue for the changes in our nitro integration is

https://github.com/EspressoSystems/nitro-contracts/issues/20
sveitser added a commit to EspressoSystems/nitro-testnode that referenced this pull request Sep 16, 2024
* CI: print docker logs on failure

* Pin version before LC ABI changes

In EspressoSystems/espresso-sequencer#1939
the light client ABI changed and as a result we need to make changes in
multiple places.

The tracking issue for the changes in our nitro integration is

https://github.com/EspressoSystems/nitro-contracts/issues/20

* Pin the espresso-dev-node image
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.

simplify light client contract: create genesis state struct and remove states mapping
5 participants