Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dd0edc4
feat(mpc-nodes): Add XRP Ledger (mainnet & devnet) support
hanzo-dev May 8, 2025
3ed1566
feat(api): Add XRP Ledger to network listings (mainnet & testnet)
hanzo-dev May 8, 2025
5f0efb0
fix(ui): Correct XRP enum to 'XRP' and update references
hanzo-dev May 8, 2025
d43e014
chore(mpc-nodes): configure XRPL vault addresses for mainnet & devnet
hanzo-dev May 8, 2025
8e712b1
fix(mpc-nodes): include XRP_DEVNET in generate_mpc_sig branch
hanzo-dev May 8, 2025
3e71a5e
feat(mpc-nodes): add XRP Testnet & Devnet entries with correct nodes …
hanzo-dev May 8, 2025
b957d0e
feat(contracts): add LXRP and ZXRP wrapped-XRP ERC20 contracts
hanzo-dev May 8, 2025
b2ee917
Fix token references
hanzo-dev May 8, 2025
adf1af3
Add initial XRP wallet support
hanzo-dev May 8, 2025
11cf64a
Add better wallet support, initial mock tests
hanzo-dev May 8, 2025
b3c4c79
Use XRPL to refer to XRP Ledger
hanzo-dev May 8, 2025
62fbd2f
Fix typecheck
hanzo-dev May 8, 2025
74258e2
Update method name to be consistent
hanzo-dev May 9, 2025
cbad33e
Add XRP withdrawals, some other missing updates
hanzo-dev May 9, 2025
12a0f05
Final updates
hanzo-dev May 9, 2025
399a68c
Add better address handling for XRPL
hanzo-dev May 9, 2025
5d7377e
Update LLM.md with more detailed docs
hanzo-dev May 9, 2025
3fc0100
Add better docs
hanzo-dev May 9, 2025
1274127
Track withdrawal times
hanzo-dev May 10, 2025
98cd12f
Add more docs
hanzo-dev May 12, 2025
5c4d547
Add DKLs23 notes
hanzo-dev May 12, 2025
d393957
Update LLM.md with up to date notes / guide
hanzo-dev May 12, 2025
37dd701
Add scaling docs
hanzo-dev May 12, 2025
0e98759
Add TSSHOCK notes and security analysis
hanzo-dev May 12, 2025
52193ab
Add notes on CGGMP21
hanzo-dev May 12, 2025
b0a0185
Add initial implementation of cggmp21
hanzo-dev May 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions LLM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# LLM.md - Lux.Network Bridge CGGMP21 Implementation

## Project Overview

This document provides information about the implementation of the CGGMP21 protocol for the Lux.Network bridge. The CGGMP21 protocol is an advanced threshold ECDSA implementation that provides enhanced security features like non-interactive signing, proactive security, and identifiable abort.

## Key Components

### 1. Protocol Management

The implementation is designed to support multiple MPC protocols through a plugin-style architecture:

- `protocol.ts`: Core module that defines protocol interfaces and implementations
- Protocol enum: `GG18`, `CGGMP20`, and `CGGMP21`
- Factory pattern: `createProtocol()` to instantiate the appropriate protocol handler

### 2. CGGMP21 Protocol Features

The CGGMP21 protocol implementation includes:

- **Presigning**: Generate signing data without knowing the message to be signed
- **Key Refresh**: Periodic key refreshing for enhanced security
- **Non-Interactive Signing**: Single round of communication after presigning

### 3. API Endpoints

New endpoints added to support CGGMP21:

- `/api/v1/refresh_keys`: Refresh key shares for enhanced security
- `/api/v1/generate_presign`: Generate presign data manually
- `/api/v1/protocol_status`: Get current protocol status and statistics

### 4. Configuration

Environment variables for configuring the protocol:

```
# Protocol selection
mpc_protocol=cggmp21 # Options: cggmp20, cggmp21

# Party configuration
party_id=0
threshold=2
total_parties=3
key_store_path=./keyshares

# Presigning configuration
presign_count=10 # Number of presign data to generate at startup
```

## Design Decisions

1. **Backward Compatibility**: The implementation maintains backward compatibility with the existing CGGMP20 protocol.

2. **Protocol Abstraction**: An abstract `MPCProtocol` class defines a common interface for all protocol implementations, allowing easy switching between protocols.

3. **Presigning Management**: CGGMP21 includes a system for managing presign data that is generated in advance for better performance and security.

4. **Key Refresh**: CGGMP21 supports periodic key refreshing without changing the public key, enhancing security.

## Implementation Details

### CGGMP21 Protocol Class

The `CGGMP21Protocol` class implements the `MPCProtocol` interface and adds specific methods for CGGMP21:

```typescript
export class CGGMP21Protocol extends MPCProtocol {
// Core signing method (implements MPCProtocol interface)
async sign(options: SignOptions): Promise<{ r: string; s: string; v: string; signature: string }>

// CGGMP21-specific methods
async generatePresignData(): Promise<{ id: string, path: string }>
async refreshKeyShares(epoch: number): Promise<string>
async getOrCreatePresignData(): Promise<{ id: string, path: string }>
}
```

### PresignStore

A dedicated store for managing presign data:

```typescript
export class PresignStore {
async savePresignData(presignData: PresignData): Promise<void>
async getUnusedPresignData(): Promise<PresignData | null>
async getUnusedCount(): Promise<number>
async markPresignDataAsUsed(id: string): Promise<void>
async markAllAsUsed(): Promise<void>
}
```

### Integration with Existing Signing System

The existing signing system in `utils.ts` was modified to use the protocol handler:

```typescript
// Use protocol handler for signing
const { signature, r, s, v } = await protocolHandler.sign({ messageHash: netSigningMsg });
```

## Usage Flow

1. **Configuration**: Set `mpc_protocol=cggmp21` in environment variables
2. **Initialization**: At startup, the system generates presign data (configured by `presign_count`)
3. **Signing**: When a transaction needs to be signed, the system:
- Gets or creates presign data
- Signs the message using the presign data
- Marks the presign data as used
4. **Maintenance**: Periodically refresh keys using the `/api/v1/refresh_keys` endpoint

## Future Improvements

1. **Automated Key Refreshing**: Implement a scheduled job for regular key refreshing
2. **Better Error Handling**: Improve error handling for protocol operations
3. **Performance Optimization**: Implement batched presigning operations
4. **Monitoring**: Add metrics and monitoring for presign data usage and protocol operations
11 changes: 10 additions & 1 deletion app/bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
"storybook": "storybook dev -p 6006",
"build:storybook": "storybook build",
"analyze": "cross-env ANALYZE=true next build",
"lint": "next lint"
"lint": "next lint",
"test": "vitest --config vitest.config.ts"
},
"dependencies": {
"@eth-optimism/contracts-ts": "^0.15.0",
"@hanzo/auth": "catalog:",
"@hanzo/ui": "4.2.0",
"@headlessui/react": "^1.7.3",
"@imtbl/imx-sdk": "2.1.1",
"@ledgerhq/hw-app-xrp": "^6.31.0",
"@ledgerhq/hw-transport-webhid": "^6.30.0",
"@loopring-web/loopring-sdk": "3.3.5",
"@loopring-web/web3-provider": "1.4.13",
"@luxfi/ui": "5.4.1",
Expand Down Expand Up @@ -83,6 +86,8 @@
"viem": "^2.9.9",
"wagmi": "^2.5.19",
"web3": "^4.11.1",
"xrpl": "^4.2.5",
"xumm": "^1.8.0",
"zksync": "^0.13.1",
"zustand": "^4.4.1"
},
Expand All @@ -99,6 +104,9 @@
"@storybook/nextjs": "^7.4.5",
"@storybook/react": "^7.4.5",
"@storybook/testing-library": "^0.2.1",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.3.0",
"@testing-library/react-hooks": "^8.0.1",
"@types/bn.js": "^5.1.0",
"@types/crypto-js": "^4.1.1",
"@types/lodash.merge": "^4.6.9",
Expand All @@ -122,6 +130,7 @@
"storybook-react-context": "^0.6.0",
"tailwindcss": "catalog:",
"typescript": "catalog:",
"vitest": "^3.1.3",
"webpack-watch-files-plugin": "^1.2.1"
}
}
1 change: 1 addition & 0 deletions app/bridge/src/Models/CryptoNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum NetworkType {
TON = "ton",
Bitocoin = "btc",
Cardano = "cardano",
XRPL = "xrpl",
}

export type CryptoNetwork = {
Expand Down
16 changes: 16 additions & 0 deletions app/bridge/src/components/icons/Wallets/XRPL.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import Image, { type ImageProps } from 'next/image'

// XRP Ledger icon for wallet display
// XRP Ledger icon for wallet display
export default function XRPLIcon(props: Omit<ImageProps, 'src' | 'alt'>) {
return (
<Image
src="/assets/img/xrp.svg"
alt="XRP Ledger"
width={24}
height={24}
{...props}
/>
)
}
4 changes: 4 additions & 0 deletions app/bridge/src/components/lux/teleport/constants/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export const SWAP_PAIRS: Record<string, string[]> = {
LDOGS: ['ZDOGS'],
LMRB: ['ZMRB'],
LREDO: ['ZREDO'],
LXRP: ['XRP', 'ZXRP'],
// Zoo tokens
ZOO: ['LZOO'],
ZBTC: ['WBTC', 'LBTC'],
Expand Down Expand Up @@ -197,6 +198,7 @@ export const SWAP_PAIRS: Record<string, string[]> = {
ZDOGS: ['LDOGS'],
ZMRB: ['LMRB'],
ZREDO: ['LREDO'],
ZXRP: ['LXRP', 'XRP'],
// Evm tokens
ETH: ['LETH', 'ZETH'],
WETH: ['LETH', 'ZETH'],
Expand Down Expand Up @@ -239,4 +241,6 @@ export const SWAP_PAIRS: Record<string, string[]> = {
DOGS: ['LDOGS', 'ZDOGS'],
MRB: ['LMRB', 'ZMRB'],
REDO: ['LREDO', 'ZREDO'],
// XRP Ledger tokens
XRP: ['LXRP', 'ZXRP'],
}
5 changes: 4 additions & 1 deletion app/bridge/src/components/lux/teleport/process.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ interface IProps {

const Form: React.FC<IProps> = ({ swapId, className }) => {
const { networks } = useSettings()
const filteredNetworks = networks.filter((n: CryptoNetwork) => n.type === NetworkType.EVM)
const filteredNetworks = networks.filter(
(n: CryptoNetwork) =>
n.type === NetworkType.EVM || n.type === NetworkType.XRPL
)

const [sourceNetwork, setSourceNetwork] = React.useState<CryptoNetwork | undefined>(undefined)
const [sourceAsset, setSourceAsset] = React.useState<NetworkCurrency | undefined>(undefined)
Expand Down
20 changes: 20 additions & 0 deletions app/bridge/src/components/lux/teleport/swap/SwapDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import UserTokenDepositor from './progress/TokenDepositor'
import TeleportProcessor from './progress/TeleportProcessor'
import PayoutProcessor from './progress/PayoutProcessor'
import SwapSuccess from './progress/SwapSuccess'
import XrplPayoutProcessor from './progress/XrplPayoutProcessor'
import { SwapStatus } from '@/Models/SwapStatus'
import type { CryptoNetwork, NetworkCurrency } from '@/Models/CryptoNetwork'
import { NetworkType } from '@/Models/CryptoNetwork'

interface IProps {
className?: string
Expand Down Expand Up @@ -62,6 +64,24 @@ const SwapDetails: React.FC<IProps> = ({
/>
)
} else if (swapStatus === SwapStatus.UserPayoutPending) {
// XRPL payout flow
if (destinationNetwork.type === NetworkType.XRPL) {
return (
<XrplPayoutProcessor
sourceNetwork={{
type: sourceNetwork.type,
chain_id: sourceNetwork.chain_id || undefined // Convert null to undefined
}}
destinationNetwork={{
type: destinationNetwork.type
}}
destinationAddress={destinationAddress}
sourceAmount={sourceAmount}
swapId={swapId}
className={className}
/>
)
}
return (
<PayoutProcessor
sourceNetwork={sourceNetwork}
Expand Down
Loading