Skip to content

feat(sdk-lib-mpc): add VrfDkg wrapper for MPS VRF keygen - #9672

Merged
danielpeng1 merged 1 commit into
masterfrom
WCN-2583/safes-mps-vrf-dkg-wrapper
Sep 8, 2026
Merged

feat(sdk-lib-mpc): add VrfDkg wrapper for MPS VRF keygen#9672
danielpeng1 merged 1 commit into
masterfrom
WCN-2583/safes-mps-vrf-dkg-wrapper

Conversation

@danielpeng1

Copy link
Copy Markdown
Contributor

Add MpsVrf.VrfDkg in sdk-lib-mpc wrapping wasm-mps EdDSA VRF DKG.

  • Same initDkg / handleIncomingMessages / getKeyShare / restoreSession shape as DklsVrf
  • Msg2 is per-recipient p2p from the wasm party-id map; VrfShare has no pk/keyId/chaincode getters
  • Session restore validates with io-ts; state bytes are treated as secret key material
  • Local 2-of-3 helper generateVrfDKGKeyShares

Tests

  • Unit tests for happy path, hard-derive agreement, MPS sign/verify comms, serialize round-trip, restore at both rounds, and rejections
  • Measured VRF keyshare size: 229 bytes

@danielpeng1 danielpeng1 self-assigned this Sep 8, 2026
@linear-code

linear-code Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

WCN-2583

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

⚠️ Unit tests are failing on Node 26.x (Current release line, non-blocking). This is not an LTS version yet, so it does not block merge, but it signals an incompatibility to fix before Node 26.x becomes LTS.

View run

@danielpeng1

Copy link
Copy Markdown
Contributor Author

@claude review

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Claude finished @danielpeng1's task —— View job


Code Review for VrfDkg MPS Implementation

Tasks:

  • Read and analyze all changed files
  • Review main implementation (dkg.ts)
  • Review types and interfaces (types.ts)
  • Review utility functions (util.ts)
  • Review test coverage and quality
  • Check for security considerations
  • Verify adherence to repo conventions
  • Provide comprehensive review feedback

Overall Assessment ✅

This is a well-implemented VRF DKG wrapper that follows the existing patterns in the codebase. The implementation mirrors the DklsVrf structure while adapting to MPS-specific requirements. The code is clean, well-documented, and includes comprehensive test coverage.

Strengths

Architecture & Design:

  • ✅ Clean separation of concerns with dedicated files for types, utils, and main implementation
  • ✅ Consistent API with existing DklsVrf implementation (initDkg, handleIncomingMessages, getKeyShare, restoreSession)
  • ✅ Proper state machine design with clear transitions through VrfDkgState enum
  • ✅ Good encapsulation of WASM complexity behind a clean interface

Security:

  • ✅ Proper handling of secret key material with clear documentation warnings
  • ✅ State bytes are treated as secret and cleared when no longer needed (line 169 in dkg.ts)
  • ✅ Input validation for parameters, seeds, and session data
  • ✅ Use of io-ts for runtime type validation in session restoration

Testing:

  • ✅ Comprehensive test suite covering happy path, edge cases, and error conditions
  • ✅ Tests for MPS sign/verify communication compatibility
  • ✅ Session serialization/deserialization round-trip tests
  • ✅ Hard derivation agreement tests proving key consistency
  • ✅ Proper error condition testing with specific error message validation

Code Quality Issues

Minor Issues:

  1. Inconsistent WASM Loading Pattern (dkg.ts:43-61):
    The electron detection logic could be simplified and made more robust:

    // Current
    !window.process && !window.process?.['type']
    
    // Could be cleaner
    typeof window?.process?.type === 'undefined'
  2. Magic Numbers (test/unit/tss/eddsa-mps-vrf/dkg.ts:8):
    The VRF_KEYSHARE_SIZE_BYTES = 229 is hardcoded. Consider adding this as a constant in the main module or documenting the version dependency more explicitly.

  3. Error Message Consistency:
    Some error messages use "VRF DKG" while others use different formats. Consider standardizing on a consistent format.

TypeScript & Best Practices:

  1. Type Safety in WASM Interface (dkg.ts:7-9):
    The union type for WasmMps is good, but consider using branded types or more specific interfaces to prevent runtime type confusion.

  2. Buffer vs Uint8Array Consistency (types.ts:25,27):
    The interface mixes Uint8Array and Buffer types. While functionally correct, consider standardizing on one approach for consistency.

Architecture Comparison

The implementation correctly follows the established patterns from DklsVrf:

  • ✅ Similar class structure and method signatures
  • ✅ Consistent state management approach
  • ✅ Proper WASM lifecycle handling
  • ✅ Compatible message routing patterns

Key Differences (appropriately adapted):

  • Uses MPS-specific message routing (p2p messages in round 2 vs broadcast in DKLS)
  • Simplified keyshare interface (no pk/keyId/chaincode getters as documented)
  • Different session serialization approach (explicit state tracking vs WASM round tags)

Security Review

  • ✅ Proper secrets handling with explicit warnings
  • ✅ Input validation prevents common attack vectors
  • ✅ State machine prevents invalid transitions
  • ✅ No logging of sensitive material
  • ✅ Appropriate use of crypto.randomBytes for entropy

Test Coverage Analysis

The test suite is thorough and covers:

  • ✅ Happy path scenarios (basic 2-of-3 DKG)
  • ✅ Integration with existing MPS communication layer
  • ✅ Serialization compatibility with DKLS message format
  • ✅ Session persistence and restoration at multiple points
  • ✅ Error conditions and input validation
  • ✅ Cross-party consistency verification

Recommendations

  1. Consider adding JSDoc comments for the main class methods to improve IDE experience
  2. Add constant exports for magic numbers like keyshare size
  3. Consider adding benchmark tests for performance regression detection
  4. Document version compatibility with @bitgo/wasm-mps more explicitly

Node 26.x Compatibility Note

The failing Node 26.x tests appear to be a known issue (non-blocking for LTS). This should be addressed before Node 26.x becomes LTS, but doesn't block this PR.


Final Verdict:Approve - This is a solid implementation that maintains consistency with existing patterns while properly adapting to MPS-specific requirements. The minor issues noted are not blockers and can be addressed in follow-up improvements.


Job Run: https://github.com/BitGo/BitGoJS/actions/runs/34187848716

@danielpeng1
danielpeng1 marked this pull request as ready for review September 8, 2026 05:27
@danielpeng1
danielpeng1 requested review from a team as code owners September 8, 2026 05:27
Comment thread modules/sdk-lib-mpc/src/tss/eddsa-mps-vrf/dkg.ts Outdated
@danielpeng1
danielpeng1 force-pushed the WCN-2583/safes-mps-vrf-dkg-wrapper branch from 344e2be to 37ab5d0 Compare September 8, 2026 13:29
@danielpeng1
danielpeng1 requested a review from vibhavgo September 8, 2026 14:00
@danielpeng1
danielpeng1 merged commit 8e04e14 into master Sep 8, 2026
27 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.

3 participants