Skip to content

Conversation

@nlordell
Copy link
Collaborator

@nlordell nlordell commented Dec 8, 2025

This PR changes the strategy for doing genesis to wait for the KeyGen event to be manually triggered. With this change, we no longer need to start indexing from block 0 and can just start with latest.

Now, the genesis process looks a bit different:

  1. Each validator starts with their parameters
  2. Someone manually triggers a keyGen call on the coordinator contract in order to kick off the process
  3. Profit $$$

This simplifies the startup significantly and no longer requires nodes to support querying events from huge block ranges, or taking along time to get to the current block (with the downside of a more manual genesis process).

This PR changes the strategy for doing genesis to wait for the
`KeyGen` event to be manually triggered. With this change, we no
longer need to start indexing from block 0 and can just start with
`latest`.

Now, the genesis process looks a bit different:
1. Each validator starts with their parameters
2. Someone manually triggers a `keyGen` call on the coordinator
   contract in order to kick off the process
3. Profit $$$

This simplifies the startup significantly and no longer requires nodes
to support querying events from huge block ranges, or taking along
time to get to the current block (with the downside of a more manual
genesis process).
@nlordell nlordell requested a review from a team as a code owner December 8, 2025 11:19
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @nlordell, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant change to the genesis process, shifting from an automatic key generation to one that is manually triggered by a KeyGen event on the coordinator contract. This strategic modification aims to streamline the startup of validator nodes by allowing them to commence indexing from the latest block, thereby reducing initial synchronization times and overall operational overhead. The changes involve refactoring core genesis logic, enhancing contract interaction patterns, and introducing new utilities for group parameter calculations.

Highlights

  • Manual Genesis KeyGen Trigger: The genesis process now requires a manual keyGen call on the coordinator contract, moving away from an automatic trigger.
  • Simplified Node Startup: This change eliminates the need for nodes to start indexing from block 0, allowing them to begin from the latest block, significantly speeding up startup.
  • Refactored Genesis Logic: The checkGenesis function has been renamed to handleGenesisKeyGen and now specifically reacts to a KeyGen event, ensuring the manual trigger is processed correctly.
  • Contract Interaction Improvements: Contract addresses and ABIs are now encapsulated in structured objects, improving code readability and maintainability for contract interactions in tests.
  • New Group Calculation Utilities: New utility functions calcGroupParameters and calcGenesisGroupId have been introduced to centralize the logic for calculating group-related parameters.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the genesis process to be manually triggered via a KeyGen event, which simplifies the node's startup by allowing it to sync from the latest block instead of from genesis. The changes are well-structured and include beneficial refactorings, such as improving contract interaction logic in tests for better clarity and centralizing the calculation of group parameters. My review includes a couple of suggestions to further enhance maintainability and robustness.

Comment on lines +183 to +187
await initiatorClient.writeContract({
...coordinator,
functionName: "keyGen",
args: [calculateParticipantsRoot(participants), 3n, 2n, zeroHash],
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve maintainability and avoid magic numbers, it's better to derive the count and threshold values from the participants array dynamically rather than hardcoding them. This will make the test more robust if the number of participants changes in the future.

const count = BigInt(participants.length);
		const threshold = count / 2n + 1n;
		await initiatorClient.writeContract({
			...coordinator,
			functionName: "keyGen",
			args: [calculateParticipantsRoot(participants), count, threshold, zeroHash],
		});

Comment on lines 13 to 20
export const calcGroupParameters = (participantCount: number, consensus: Address, epoch: bigint): GroupParameters => {
const count = BigInt(participantCount);
const threshold = count / 2n + 1n;
const context = encodePacked(["uint32", "address", "uint64"], [0, consensus, epoch]);

// TODO: Handle cases where the group size is too small.
return { count, threshold, context };
};
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The TODO comment on line 18 correctly points out that cases with small group sizes are not handled. To make this function more robust and self-contained, it would be beneficial to add a validation check at the beginning to ensure participantCount is sufficient (e.g., at least 2). This aligns with the requirements of the FROSTCoordinator contract and centralizes the validation logic, preventing potential issues in different call sites.

export const calcGroupParameters = (participantCount: number, consensus: Address, epoch: bigint): GroupParameters => {
	if (participantCount < 2) {
		// TODO: Use a more specific error type
		throw new Error("Group size must be at least 2");
	}
	const count = BigInt(participantCount);
	const threshold = count / 2n + 1n;
	const context = encodePacked(["uint32", "address", "uint64"], [0, consensus, epoch]);

	return { count, threshold, context };
};

case "event_transaction_attested": {
return await handleTransactionAttested(machineStates, transition);
}
case "event_key_gen":
Copy link
Contributor

Choose a reason for hiding this comment

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

Yay no unhandled events

@nlordell nlordell merged commit 8db49f0 into main Dec 9, 2025
3 checks passed
@nlordell nlordell deleted the pr/manual-keygen-for-genesis branch December 9, 2025 09:29
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