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

feat: add upper bound for max epoch in zklogin sig #16233

Merged
merged 8 commits into from
Apr 1, 2024
Merged

Conversation

joyqvq
Copy link
Contributor

@joyqvq joyqvq commented Feb 13, 2024

Description

currently a zklogin sig is valid as long as max_epoch is larger than current epoch. this adds a protocol config that the max_epoch cannot be too large, the config sets the upper bound to 30 + current epoch.

based on new testing framework in simtest only.

Test Plan

simtest

If your changes are not user-facing and do not break anything, you can skip the following section. Otherwise, please briefly describe what has changed under the Release Notes section.

Type of Change (Check all that apply)

  • protocol change
  • user-visible impact
  • breaking change for a client SDKs
  • breaking change for FNs (FN binary must upgrade)
  • breaking change for validators or node operators (must upgrade binaries)
  • breaking change for on-chain data layout
  • necessitate either a data wipe or data migration

Release notes

Protocol version upgrades to 42. This adds a feature flag to set the upper bound of the max epoch for a zklogin signature.

Copy link

vercel bot commented Feb 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
explorer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2024 2:44pm
multisig-toolkit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2024 2:44pm
mysten-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2024 2:44pm
sui-core ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2024 2:44pm
sui-kiosk ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2024 2:44pm
sui-typescript-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2024 2:44pm

@@ -106,7 +106,8 @@ pub trait Message {

/// Verify that the message is from the correct epoch (e.g. for CertifiedCheckpointSummary
/// we verify that the checkpoint is from the same epoch as the committee signatures).
fn verify_epoch(&self, epoch: EpochId) -> SuiResult;
fn verify_epoch(&self, epoch: EpochId, upper_bound_for_max_epoch: Option<EpochId>)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is upper_bound_for_max_epoch only used for Transaction? If so I am not convinced it belongs to the general message trait.

Copy link
Contributor Author

@joyqvq joyqvq Feb 22, 2024

Choose a reason for hiding this comment

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

theres actually no concrete type at a few places where the verify_epoch is invoked, i can only access it via the Message trait:

impl<T> Envelope<T, AuthoritySignInfo>
where
    T: Message + AuthenticatedMessage + Serialize,
{
    pub fn verify_signatures_authenticated(
        &self,
        committee: &Committee,
        verify_params: &VerifyParams,
    ) -> SuiResult {
        self.data.verify_epoch(self.auth_sig().epoch, None)?;

and

impl<T> Envelope<T, AuthoritySignInfo>
where
    T: Message + UnauthenticatedMessage + Serialize,
{
    pub fn verify_authority_signatures(&self, committee: &Committee) -> SuiResult {
        self.data.verify_epoch(self.auth_sig().epoch, None)?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there are 4 concrete types for the message trait, 2 out of them actually just return Ok(()) noop, im guessing its a bit messy to remove the trait?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that just means verify_epoch shouldn't be a trait API for Message. SenderSignedData and SignedCheckpointSummary should have its own function to check this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

verify_max_epoch_for_all_sigs i added this call for SenderSignedData and this is only triggered inside verify_tx. the other other implementations like Checkpoint, TransactionEffects etc should not change its interface

                signed_tx.verify_epoch(self.committee.epoch())?;
                signed_tx.verify_max_epoch_for_all_sigs(
                    self.committee.epoch(),
                    self.zk_login_params.zklogin_max_epoch_upper_bound,
                )?;

however it 2 iterations of the for loop instead of 1. lmk if there is better idea how to refactor this @lxfind @mystenmark

test_cluster.wait_for_authenticator_state_update().await;
test_cluster
.wait_for_epoch_with_timeout(Some(9), Duration::from_secs(190))
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to wait 9 epochs in this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because the zk proof is generated for max epoch = 10.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i probably can regenerate all zkproofs against a smaller epoch to avoid timeouts esp in simtest, i will follow up a PR for that

@@ -12,7 +12,7 @@ use tracing::{info, warn};

/// The minimum and maximum protocol versions supported by this build.
const MIN_PROTOCOL_VERSION: u64 = 1;
const MAX_PROTOCOL_VERSION: u64 = 36;
const MAX_PROTOCOL_VERSION: u64 = 37;
Copy link
Contributor

Choose a reason for hiding this comment

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

fyi @benr-ml is adding 37 in another PR

Copy link
Contributor

@mystenmark mystenmark left a comment

Choose a reason for hiding this comment

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

Couple of nits, looks good otherwise

Copy link
Contributor

@lxfind lxfind left a comment

Choose a reason for hiding this comment

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

Overall LGTM.
Please address the type/name confusion.

@@ -32,6 +32,7 @@ pub struct VerifyParams {
pub zk_login_env: ZkLoginEnv,
pub verify_legacy_zklogin_address: bool,
pub accept_zklogin_in_multisig: bool,
pub zklogin_max_epoch_upper_bound: Option<EpochId>,
Copy link
Contributor

@lxfind lxfind Mar 29, 2024

Choose a reason for hiding this comment

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

Should this be Option<u64>? This is not the actual epoch, but just number of epochs of validity? May also want to consider renaming some of these because it's hard to tell which one is actual epoch ID and which one represents a delta (i.e. max number of valid epochs)

@@ -41,21 +42,27 @@ impl VerifyParams {
zk_login_env: ZkLoginEnv,
verify_legacy_zklogin_address: bool,
accept_zklogin_in_multisig: bool,
zklogin_max_epoch_upper_bound: Option<EpochId>,
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

fn verify_user_authenticator_epoch(
&self,
epoch: EpochId,
upper_bound_max_epoch: Option<EpochId>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Also this one

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.

3 participants