Conversation
Summary of ChangesHello @nflaig, 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 brings the codebase up-to-date with the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request updates the codebase to align with the v1.7.0-alpha.2 consensus spec. The changes are extensive, touching configuration, state transition logic, caching, and type definitions. The refactoring of the Payload Timeliness Committee (PTC) handling to a lazy computation model is a notable performance improvement.
I've reviewed the changes and found a couple of potential issues. One is related to an incorrect optimization in the onboardBuildersFromPendingDeposits function that could lead to incorrect state during the Gloas fork upgrade. Another is a potential integer overflow bug in an optimized hashing function in seed.ts that could affect consensus in edge cases. My detailed comments are below.
| // Pre-compute builder pubkeys set for O(1) lookup instead of O(n) per deposit | ||
| const builderPubkeys = new Set<string>(); | ||
| for (let i = 0; i < state.builders.length; i++) { | ||
| builderPubkeys.add(toHex(state.builders.getReadonly(i).pubkey)); | ||
| } |
There was a problem hiding this comment.
The pre-computation of builderPubkeys is an optimization that doesn't align with the spec and could lead to incorrect behavior. The spec for onboard_builders_from_pending_deposits states that the list of builder pubkeys should be recomputed in each iteration of the loop over pending deposits. This is because applyDepositForBuilder can mutate state.builders by reusing a slot for an exited builder, which would replace an old builder (and its pubkey) with a new one. Your current implementation only adds new pubkeys to the Set but doesn't handle the removal of old pubkeys when a slot is reused. This can lead to isExistingBuilder being incorrectly true for a pubkey that should no longer be considered a builder.
To fix this, you should re-create the builderPubkeys set inside the loop over state.pendingDeposits to ensure it's always in sync with state.builders.
Example:
function onboardBuildersFromPendingDeposits(state: CachedBeaconStateGloas): void {
const trackedValidatorPubkeys = new Set<string>();
const remainingPendingDeposits = state.pendingDeposits.sliceFrom(state.pendingDeposits.length);
for (let i = 0; i < state.pendingDeposits.length; i++) {
// Re-compute builder pubkeys set inside the loop
const builderPubkeys = new Set<string>();
for (let j = 0; j < state.builders.length; j++) {
builderPubkeys.add(toHex(state.builders.getReadonly(j).pubkey));
}
const deposit = state.pendingDeposits.getReadonly(i);
// ... rest of the logic
}
state.pendingDeposits = remainingPendingDeposits;
}| hashInput.writeUInt32LE(block, seed.length); | ||
| // Zero the upper 4 bytes for correct 8-byte little-endian encoding | ||
| hashInput.writeUInt32LE(0, seed.length + 4); |
There was a problem hiding this comment.
This optimization to write a 64-bit little-endian integer using writeUInt32LE is unsafe and can lead to incorrect behavior. The block variable, calculated as Math.floor(i / 16), can grow larger than 2**32 - 1 if the while loop runs for many iterations (e.g., in scenarios with very low effective balances). writeUInt32LE will truncate values larger than 32 bits, leading to an incorrect hash input and a potential consensus split.
You should use a method that safely handles 64-bit integers, such as Buffer.writeBigUInt64LE() or by using a DataView.
| hashInput.writeUInt32LE(block, seed.length); | |
| // Zero the upper 4 bytes for correct 8-byte little-endian encoding | |
| hashInput.writeUInt32LE(0, seed.length + 4); | |
| hashInput.writeBigUInt64LE(BigInt(block), seed.length); |
|
@codex review |
Performance Report✔️ no performance regression detected Full benchmark results
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 28cf5d59e3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Track newly added builder pubkeys for subsequent deposits | ||
| builderPubkeys.add(pubkeyHex); |
There was a problem hiding this comment.
Only mark builder pubkey after successful onboarding
builderPubkeys is updated unconditionally after applyDepositForBuilder(...). If that call rejects the deposit (e.g., invalid signature), the pubkey is still treated as an existing builder in subsequent iterations. That can route later deposits for the same pubkey through the builder path even when the withdrawal credentials are not builder credentials, potentially creating a builder with validator-style credentials or dropping validator deposits that should stay pending. The spec recomputes builder pubkeys from state each iteration specifically to avoid this; you should only add to builderPubkeys when applyDepositForBuilder actually adds a builder.
Useful? React with 👍 / 👎.
v1.7.0-alpha.2