Skip to content

feat: Add NoosphereVRF shared singleton for verifiable randomness#38

Merged
nolnol3 merged 4 commits intodevelopfrom
vrf
Feb 8, 2026
Merged

feat: Add NoosphereVRF shared singleton for verifiable randomness#38
nolnol3 merged 4 commits intodevelopfrom
vrf

Conversation

@nolnol3
Copy link
Copy Markdown
Member

@nolnol3 nolnol3 commented Feb 8, 2026

Add VRF module (src/v1_0_0/vrf/) providing epoch-based Merkle tree random values shared across all consumer dApps on a chain.

  • INoosphereVRF.sol: Public interface
  • NoosphereVRF.sol: Singleton with epoch management, Merkle proof verification, global request ID counter, and replay prevention
  • NoosphereVRFConsumer.sol: Abstract for dApps to inherit, integrates with Noosphere compute pipeline and exposes virtual hooks

Add VRF module (src/v1_0_0/vrf/) providing epoch-based Merkle tree
random values shared across all consumer dApps on a chain.

- INoosphereVRF.sol: Public interface
- NoosphereVRF.sol: Singleton with epoch management, Merkle proof
  verification, global request ID counter, and replay prevention
- NoosphereVRFConsumer.sol: Abstract for dApps to inherit, integrates
  with Noosphere compute pipeline and exposes virtual hooks
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @nolnol3, 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 integrates a robust Verifiable Random Function (VRF) system into the Noosphere platform. It establishes a shared, epoch-based mechanism for generating and verifying random numbers, ensuring fairness and unpredictability for all connected dApps. The system leverages Merkle trees for pre-commitment and verification, combined with L2 block hashes for additional entropy, and includes built-in replay prevention. This enhancement provides a foundational service for dApps requiring secure and transparent randomness.

Highlights

  • New VRF Module Introduction: This pull request introduces a new Verifiable Random Function (VRF) module within the src/v1_0_0/vrf/ directory, designed to provide epoch-based Merkle tree random values shared across all consumer dApps on a chain.
  • INoosphereVRF Interface: A new public interface, INoosphereVRF.sol, has been added. It defines the contract for epoch management, request lifecycle (requesting and fulfilling random values), view functions for request status, configuration constants, and consumer management.
  • NoosphereVRF Singleton Implementation: The core logic is implemented in NoosphereVRF.sol, a singleton contract. It handles epoch registration, global request ID assignment, Merkle proof verification, and replay prevention. It also incorporates a highly optimized assembly function for decoding base64 data URI outputs from the VRNG container.
  • NoosphereVRFConsumer Abstract Contract: An abstract contract, NoosphereVRFConsumer.sol, is provided for dApps to inherit. This contract simplifies integration with the Noosphere compute pipeline and the NoosphereVRF singleton, exposing virtual hooks for handling received or expired random values and managing subscriptions.
Changelog
  • src/v1_0_0/vrf/INoosphereVRF.sol
    • Added new interface for the Noosphere VRF singleton.
    • Defined events for epoch registration, low epoch slots, random value verification, expiration, and consumer management.
    • Included functions for epoch management (registerEpoch, getEpochRoot, getEpochRemaining, getCurrentEpoch).
    • Specified request lifecycle functions (requestRandomValue, fulfillRandomValue) for assigning and verifying random values.
    • Added view functions for nextRequestId, isRequestExpired, and getRequestBlock.
    • Defined configuration constants EPOCH_SIZE and BLOCKHASH_TIMEOUT.
    • Included functions for adding, removing, and checking authorized consumers.
  • src/v1_0_0/vrf/NoosphereVRF.sol
    • Added new contract implementing the INoosphereVRF interface.
    • Integrated MerkleProof from OpenZeppelin and ArbSys for L2 block data.
    • Implemented storage for owner, next request ID, epoch roots, request block numbers, and authorized consumers.
    • Defined custom errors for access control and VRF-specific conditions.
    • Implemented onlyOwner and onlyConsumer modifiers.
    • Provided constructor to set the contract owner.
    • Implemented registerEpoch for owner-only epoch root registration.
    • Implemented requestRandomValue to assign global request IDs, record block numbers, and warn when epochs are running low.
    • Implemented fulfillRandomValue to resolve request IDs, decode output, verify Merkle proofs, and retrieve L2 block hashes for 2-party entropy.
    • Added consumer management functions (addConsumer, removeConsumer, isAuthorizedConsumer).
    • Implemented view functions for nextRequestId, isRequestExpired, getRequestBlock, getEpochRoot, getEpochRemaining, and getCurrentEpoch.
    • Included transferOwnership and typeAndVersion functions.
    • Developed an optimized _decodeRevealOutput assembly function for double base64 decoding of data URIs.
  • src/v1_0_0/vrf/NoosphereVRFConsumer.sol
    • Added new abstract contract for dApps consuming Noosphere VRF.
    • Inherits from TransientComputeClient and Delegator.
    • Stored an immutable reference to the INoosphereVRF singleton.
    • Managed subscription ownership and user subscriptions.
    • Defined NotOwner and NotSubscriptionOwner errors.
    • Provided functions for createSubscription and cancelSubscription.
    • Implemented _requestRandomValue to interact with the VRF singleton and the compute pipeline.
    • Overrode _receiveCompute to delegate VRF verification to the NoosphereVRF singleton and call appropriate virtual hooks.
    • Defined virtual hooks _onRandomValueReceived and _onRandomValueExpired for dApp-specific logic.
    • Included view functions for getUserSubscriptions, getSubscriptionOwner, updateSigner, and getRouterAddress.
    • Added a _uint2str helper function for converting uint256 to string.
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
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08b4cf2af1

ℹ️ 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".

Copy link
Copy Markdown

@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 introduces a well-structured and documented NoosphereVRF module, providing verifiable randomness through an epoch-based Merkle tree system. The use of a singleton for NoosphereVRF and an abstract NoosphereVRFConsumer is a solid design choice. My review focuses on improving correctness, scalability, and gas efficiency. I've identified a high-severity issue in cancelSubscription that leads to inconsistent state, a medium-severity scalability concern in getUserSubscriptions, and opportunities for gas optimization and clearer error handling within the complex data decoding logic in NoosphereVRF.

…rrors, pagination

- Fix requestId race condition: split requestRandomValue into reserveRequestId + bindRequest
- Fix cancelSubscription: add swap-and-pop array cleanup + delete subscriptionOwner mapping
- Optimize _decodeRevealOutput: replace byte-by-byte copy with direct mload/mstore
- Replace revert(0,0) with custom error InvalidOutputData
- Add pagination to getUserSubscriptions(user, offset, limit) + getUserSubscriptionCount
- Add comprehensive test suite (54 tests) covering all fixes and core functionality
- Add DeployVRF.sol script for NoosphereVRF singleton deployment
- Move RegisterEpoch.sol from starter-app (epoch registration belongs in evm)
- Add deploy-vrf, deploy-vrf-hpp-sepolia, register-epoch Makefile targets
@nolnol3 nolnol3 merged commit 6645ed4 into develop Feb 8, 2026
2 checks passed
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.

1 participant