Skip to content

feat: integrate real GMX wallet trade data via Arbitrum RPC - #60

Merged
raymond1203 merged 6 commits into
mainfrom
feat/gmx-real-data
Feb 21, 2026
Merged

raymond1203 merged 6 commits into
mainfrom
feat/gmx-real-data

Conversation

@raymond1203

Copy link
Copy Markdown
Contributor

Summary

Closes #53

  • Rust prover: New gmx_fetcher module fetches GMX v2 PositionDecrease events from Arbitrum mainnet via eth_getLogs JSON-RPC. Uses alloy-sol-types 0.8 for ABI decoding of the complex nested EventLogData struct. CLI gets --wallet, --rpc-url, --from-block, --to-block flags.
  • Frontend: lib/gmx-fetcher.ts fetches trades via thirdweb's RPC client. lib/wasm-prover.ts gets generateSharpeProofFromReturns() wrapper. New WalletProver component with wallet input, trade summary, and 6-step proof pipeline visualization.
  • Dashboard: New "Live Wallet" tab in AgentDashboard for end-to-end flow: enter wallet → fetch GMX trades → generate STARK proof → verify on-chain.

Files Changed

File Change
prover/src/gmx_fetcher.rs New: GMX v2 RPC fetcher with ABI decoding (7 unit tests)
prover/Cargo.toml Add reqwest, tokio, serde, alloy-sol-types under cli feature
prover/src/lib.rs Add gmx_fetcher module declaration
prover/src/main.rs Add --wallet mode with async main
lib/gmx-fetcher.ts New: Frontend GMX trade fetcher via thirdweb RPC
lib/wasm-prover.ts Add generateSharpeProofFromReturns()
lib/chains.ts Add Arbitrum One chain definition
lib/bot-data.ts Add fetching-trades phase, wallet pipeline steps, string botId
components/WalletProver.tsx New: Live wallet UI with trade fetch + proof + verify
components/AgentDashboard.tsx Add Live Wallet tab

Test plan

  • cargo test --features cli — 39 tests pass (7 new gmx_fetcher tests)
  • pnpm build — production build succeeds
  • pnpm lint — no new errors
  • Manual: cargo run --features cli --release -- --wallet 0x<known-gmx-trader> --num-queries 4
  • Manual: pnpm dev → Live Wallet tab → enter wallet → Fetch → Prove → Verify

raymond1203 and others added 3 commits February 21, 2026 17:53
- Add pipeline types and derivePipelineSteps() to lib/bot-data.ts
- Create ProofPipeline component with bot selector, vertical timeline,
  verify button, and tx result card
- Wrap AgentDashboard in shadcn Tabs (Agent Dashboard / Proof Pipeline)
- Fix ConnectWallet hydration mismatch via dynamic import with ssr:false
Pipeline fixes:
- Add errorAtStep tracking so failed step shows red in timeline
- Fix proving phase flicker when progress is null (default to step 2)
- derivePipelineSteps now accepts errorAtStep param for persistent error display

Shared fixes (same as #57):
- Add WASM build artifacts (prover/pkg/) and build script
- Fix WASM init with promise caching to prevent race condition
- Remove dead code: gas-context, chart.tsx, GasProvider, recharts, unused gas-utils fns
Add full pipeline for fetching real GMX v2 PositionDecrease events from
Arbitrum mainnet, computing return_bps, and generating STARK proofs from
live wallet data.

Rust prover:
- New gmx_fetcher module with alloy-sol-types ABI decoding for GMX v2
  EventEmitter EventLogData (7 nested key-value structs)
- CLI --wallet flag for real wallet proof generation via RPC
- alloy-sol-types, reqwest, tokio, serde deps under cli feature

Frontend:
- GMX trade fetcher using thirdweb eth_getLogs RPC
- generateSharpeProofFromReturns WASM wrapper
- WalletProver component with trade fetching, summary, 6-step pipeline
- Live Wallet tab in AgentDashboard
- Arbitrum One chain definition

@hoddukzoa12 hoddukzoa12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review: Live Wallet 증명 구조에 데이터 출처 검증 누락

현재 Live Wallet 플로우는 bot 데모와 동일한 증명 구조를 사용하고 있습니다.
eth_getLogs로 이벤트를 가져온 뒤 return_bps를 추출하여 Sharpe STARK prover에 그대로 전달하는 방식입니다.

문제점

데이터 출처(data provenance)가 증명되지 않습니다.

현재 구조:

eth_getLogs → ABI decode → return_bps → Sharpe STARK proof

누군가 가짜 return_bps를 넣어도 유효한 proof가 생성됩니다. 즉, "계산이 맞다"는 증명하지만 "이 데이터가 실제 온체인에 존재했다"는 증명하지 않습니다.

필요한 구조

RPC → stateRoot + MPT proof (eth_getProof)
           ↓
STARK circuit 내에서 Keccak 기반 MPT 경로 재계산
           ↓
데이터가 해당 stateRoot에 속함을 binding
           ↓
Sharpe ratio 계산 정확성 증명 (기존)

구체적으로 추가해야 할 것

  1. eth_getProof RPC 호출 — account/storage proof + stateRoot 가져오기
  2. STARK circuit 내 Keccak MPT 검증 로직 — RLP 디코딩 + 트라이 경로 순회
  3. Boundary constraint에서 MPT root → stateRoot 바인딩
  4. Public input에 block hash 또는 stateRoot 포함

영향 범위

  • prover/src/gmx_fetcher.rs — eth_getProof 호출 추가
  • prover/src/ — MPT 검증 circuit 모듈 신규
  • prover/src/lib.rs — proving pipeline에 MPT 검증 통합
  • lib/gmx-fetcher.ts — 프론트엔드에서도 proof 데이터 fetch
  • contracts/stylus/src/ — verifier에 MPT 검증 constraint 추가

Live Wallet이 해커톤에서 차별화 포인트가 되려면, **"온체인 데이터의 출처까지 영지식으로 증명한다"**는 구조가 필수입니다.

- Add wallet address input flow (replaces TX hash input)
- Fetch GMX V2 PositionDecrease events via eth_getLogs from EventEmitter
- Parse basePnlUsd/sizeDeltaUsd from ABI-encoded event data to compute return_bps
- Correct GMX V2 EventLog1 topic structure: [sig, keccak256(eventName), account]
- Activate TC4 constraint for dataset_commitment immutability in STARK circuit
- Add receipt proof module (MPT verification + dataset_commitment computation)
- Add on-chain MPT verification module for Stylus verifier
- Extend WASM prover with generateSharpeProofWithCommitment()
- Fix WASM loading: serve from public/ instead of broken @/ alias URL
- Limit trades to last 200 for browser WASM proof performance
- All tests pass: prover 42/42, verifier 72/72, frontend build OK
@hoddukzoa12

Copy link
Copy Markdown
Contributor

Receipt Proof + Wallet-Based GMX Trade Verification 구현 완료

feat/proof-pipeline-visualization 브랜치에 다음 기능이 구현되었습니다 (commit 55b554e):

주요 변경사항

1. Wallet-Based GMX Trade Fetching (lib/gmx-trades.ts)

  • 지갑 주소 입력 → GMX V2 EventEmitter에서 PositionDecrease 이벤트 자동 fetch
  • eth_getLogs로 topics: [null, keccak256("PositionDecrease"), paddedWallet] 필터링
  • ABI 데이터에서 basePnlUsd, sizeDeltaUsd 파싱하여 return_bps 계산
  • 최근 200개 트레이드 제한 (WASM proof 성능 최적화)

2. Receipt Proof Data Provenance (lib/receipt-proof.ts, prover/src/receipt_proof.rs)

  • dataset_commitment = keccak(blockHash, keccak(receiptsRoot, receiptHash)) mod BN254
  • STARK circuit TC4 constraint 활성화: commitment 불변성 검증
  • On-chain MPT verification 모듈 (contracts/stylus/src/mpt.rs)

3. WASM Prover 확장 (prover/src/wasm.rs)

  • generateSharpeProofWithCommitment(returns_bps, commitment_hex, num_queries, callback)
  • generateSharpeProofFromReturns(returns_bps, num_queries, callback)
  • WASM 파일을 public/에서 서빙하여 로딩 문제 해결

4. WalletProver UI (components/WalletProver.tsx)

  • 지갑 주소 입력 → 7단계 파이프라인 시각화
  • Arbitrum One (GMX V2 지원) / Sepolia 네트워크 선택
  • 트레이드 요약 카드 (트레이드 수, 총 수익, 승률 등)

테스트 결과

  • Prover tests: 42/42 pass
  • Verifier tests: 72/72 pass
  • Frontend build: OK
  • 실제 지갑 테스트 (0xE8d8bB57...): 5,330개 트레이드 fetch, 최근 200개로 proof 생성 가능

아키텍처

Wallet Address → eth_getLogs(GMX EventEmitter) → return_bps[]
                                                        ↓
Receipt Proof (last TX) → dataset_commitment ──→ STARK Proof (WASM)
                                                        ↓
                                               On-Chain Verify (Stylus)

남은 작업

  • Stylus 컨트랙트 재배포 (verify_sharpe_proof_with_receipt)
  • 실제 on-chain verification E2E 테스트
  • feat/gmx-real-data 브랜치와 머지

김진우 and others added 2 commits February 21, 2026 21:22
Combines receipt proof pipeline (7-step wallet flow, dataset commitment
binding, TC4 constraint activation) with real GMX trade fetching
(ABI decoding via alloy-sol-types, wallet-based flow).

Resolved conflicts:
- WalletProver.tsx: use wallet-based + receipt proof pipeline
- bot-data.ts: 7-step pipeline with fetching-receipt-proof phase
- wasm-prover.ts: keep both generateSharpeProofFromReturns and WithCommitment
- gmx_fetcher.rs: combine GMX ABI fetcher + receipt proof fetcher
- main.rs: real trade fetching + optional receipt proof binding
- Cargo.toml: keep alloy-sol-types + serde deps for CLI
eprintln! is unavailable in no_std environment. Remove debug prints
from keccak hash test to fix cargo test compilation.
@raymond1203

Copy link
Copy Markdown
Contributor Author

Receipt Proof 통합 완료

@hoddukzoa12 구현해주신 receipt proof + wallet verification 코드를 머지했습니다.

통합 내용

  • prover/src/receipt_proof.rs: MPT proof 검증 + dataset_commitment 계산
  • contracts/stylus/src/mpt.rs: On-chain MPT 검증 모듈
  • lib/receipt-proof.ts, lib/gmx-trades.ts: 프론트엔드 receipt proof + trade fetcher
  • WASM prover 확장 (generateSharpeProofWithCommitment)

추가 수정

  • contracts/stylus/src/lib.rs: eprintln! → no_std 환경 호환성 수정 (테스트 컴파일 에러 해결)

테스트 결과

  • Prover: 49/49 pass
  • Verifier: 72/72 pass
  • Frontend build: OK

@raymond1203
raymond1203 merged commit 0aff732 into main Feb 21, 2026
4 of 5 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.

feat: 실제 GMX 지갑 트레이드 데이터 연동

2 participants