-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJustfile
More file actions
794 lines (663 loc) · 27.5 KB
/
Justfile
File metadata and controls
794 lines (663 loc) · 27.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
# Chalice - UltraHonk Verifier & ZCash Indexer for NEAR Protocol
#
# This project includes:
# - UltraHonk proof verification using alt_bn128 precompiles
# - ZCash/Bitcoin transaction indexing with merkle proof verification
# Default recipe
default:
@just --list
# ============== Development ==============
# Run all Rust tests
test:
cargo test
# Run ultrahonk-verifier unit tests
test-verifier:
cargo test --package near-ultrahonk-verifier
# Run zcash-indexer unit tests
test-indexer:
cargo test --package zcash-indexer-contract --lib
# Run verifier contract integration tests (deploys to NEAR sandbox)
test-integration:
cargo test --package verifier-contract --test integration -- --nocapture
# Run zcash-indexer integration tests (deploys to NEAR sandbox)
test-indexer-integration:
cargo test --package zcash-indexer-contract --test integration -- --nocapture
# Test Noir inclusion circuit with real Solana entry data
test-noir-simple:
@echo "Testing Noir inclusion proof with Solana entries..."
cd devenv && npm install && npx tsx scripts/ts/test-noir-simple.ts
# Check all crates compile
check:
cargo check --workspace
# Clean build artifacts
clean:
cargo clean
rm -rf target/near
# ============== NEAR Contracts ==============
# Build the NEAR verifier contract (WASM)
near-build:
cd crates/verifier-contract && cargo +1.86 near build non-reproducible-wasm --no-abi
# Build the NEAR zcash indexer contract (WASM)
zcash-build:
cd crates/zcash-indexer-contract && cargo +1.86 near build non-reproducible-wasm --no-abi
# Build the NEAR slot receiver contract (WASM)
slot-receiver-build:
cd crates/slot-receiver-contract && cargo +1.86 near build non-reproducible-wasm --no-abi
# Build all NEAR contracts
near-build-all: near-build zcash-build slot-receiver-build
# Build and show WASM sizes
near-build-size: near-build-all
@echo "Contract sizes:"
@ls -lh target/near/verifier_contract/verifier_contract.wasm
@ls -lh target/near/zcash_indexer_contract/zcash_indexer_contract.wasm
# ============== Noir Circuits ==============
# Run Noir circuit tests
noir-test:
cd noir-circuits/inclusion-nr && nargo test
# Execute Noir circuit (generates witness)
noir-execute:
cd noir-circuits/inclusion-nr && nargo execute
# Generate UltraHonk proof with Keccak transcript (required for NEAR/EVM)
noir-prove: noir-execute
cd noir-circuits/inclusion-nr && mkdir -p target/keccak_proof target/keccak_vk_fields && \
bb prove -b ./target/inclusion.json -w ./target/inclusion.gz -o ./target/keccak_proof --oracle_hash keccak
# Generate verification key with Keccak transcript
noir-vk:
cd noir-circuits/inclusion-nr && mkdir -p target/keccak_vk_fields && rm -rf target/keccak_vk_fields/vk && \
bb write_vk -b ./target/inclusion.json -o ./target/keccak_vk_fields --oracle_hash keccak && \
mv target/keccak_vk_fields/vk target/keccak_vk_fields/vk.bin && \
bb write_vk -b ./target/inclusion.json -o ./target/keccak_vk_fields --oracle_hash keccak --output_format fields && \
mv target/keccak_vk_fields/vk_fields.json target/keccak_vk_fields/vk_fields.json 2>/dev/null || mv target/keccak_vk_fields/vk target/keccak_vk_fields/vk_fields.json
# Export proof as fields JSON (for contract input)
noir-proof-fields: noir-prove noir-vk
cd noir-circuits/inclusion-nr && \
bb proof_as_fields -p ./target/keccak_proof/proof -k ./target/keccak_vk_fields/vk -o ./target/keccak_proof/proof_fields.json
# Full Noir prove flow: execute, prove, generate VK, export fields
noir-full: noir-execute noir-prove noir-vk noir-proof-fields
@echo "Proof generated! Files:"
@echo " - noir-circuits/inclusion-nr/target/keccak_proof/proof_fields.json"
@echo " - noir-circuits/inclusion-nr/target/keccak_vk_fields/vk_fields.json"
# Verify proof locally with Barretenberg
noir-verify: noir-vk
cd noir-circuits/inclusion-nr && bb verify -k ./target/keccak_vk_fields/vk -p ./target/keccak_proof/proof
# ============== Simple Test Circuit ==============
# Execute simple test circuit
simple-execute:
cd noir-circuits/test-circuits/simple && nargo execute
# Generate proof for simple circuit
simple-prove: simple-execute
cd noir-circuits/test-circuits/simple && mkdir -p target/keccak_proof target/keccak_vk && \
bb prove -b ./target/simple.json -w ./target/simple.gz -o ./target/keccak_proof --oracle_hash keccak
# Generate VK for simple circuit
simple-vk:
cd noir-circuits/test-circuits/simple && mkdir -p target/keccak_vk && \
bb write_vk -b ./target/simple.json -o ./target/keccak_vk --oracle_hash keccak --output_format fields_json
# Export simple circuit proof as fields
simple-proof-fields: simple-prove simple-vk
cd noir-circuits/test-circuits/simple && \
bb proof_as_fields -p ./target/keccak_proof/proof -k ./target/keccak_vk/vk -o ./target/keccak_proof/proof_fields.json
# Full simple circuit flow
simple-full: simple-execute simple-prove simple-vk simple-proof-fields
@echo "Simple circuit proof generated!"
# ============== Dual Inclusion Circuit ==============
# Run dual inclusion circuit tests
dual-test:
cd noir-circuits/dual-inclusion-nr && nargo test
# Execute dual inclusion circuit (generates witness)
dual-execute:
cd noir-circuits/dual-inclusion-nr && nargo execute
# Generate proof for dual inclusion circuit
dual-prove: dual-execute
cd noir-circuits/dual-inclusion-nr && mkdir -p target/dual_proof && \
bb prove -b ./target/dual_inclusion.json -w ./target/dual_inclusion.gz -o ./target/dual_proof
# Generate VK for dual inclusion circuit
dual-vk:
cd noir-circuits/dual-inclusion-nr && mkdir -p target/dual_proof && \
bb write_vk -b ./target/dual_inclusion.json -o ./target/dual_proof
# Verify dual inclusion proof
dual-verify: dual-vk
cd noir-circuits/dual-inclusion-nr && bb verify -k ./target/dual_proof/vk -p ./target/dual_proof/proof
# Full dual inclusion circuit flow
dual-full: dual-execute dual-prove dual-vk dual-verify
@echo "Dual inclusion proof generated and verified!"
@echo " Circuit size: ~532k gates"
@echo " Proves: ZCash tx + Solana tx inclusion"
# ============== End-to-End ==============
# Full end-to-end test: build contract, generate proof, run integration test
e2e: near-build noir-full test-integration
@echo "End-to-end test complete!"
# Quick e2e with simple circuit (faster iteration)
e2e-simple: near-build simple-full test-integration
@echo "Simple circuit e2e test complete!"
# ZCash indexer e2e: build contract and run integration tests
e2e-zcash: zcash-build test-indexer-integration
@echo "ZCash indexer e2e test complete!"
# ============== Solidity (Reference) ==============
# Build Solidity contracts (for reference/comparison)
solidity-build:
cd crates/solidity-contracts && ~/.foundry/bin/forge build
# Run Solidity tests
solidity-test:
cd crates/solidity-contracts && ~/.foundry/bin/forge test
# Generate Solidity verifier from VK (for comparison)
noir-solidity: noir-vk
mkdir -p crates/solidity-contracts/src
cd noir-circuits/inclusion-nr && bb write_solidity_verifier -s ultra_honk -k ./target/keccak_vk_fields/vk -o ../../crates/solidity-contracts/src/UltraHonkVerifier.sol
@echo "Solidity verifier generated at crates/solidity-contracts/src/UltraHonkVerifier.sol"
# ============== Development Environment ==============
# Start complete dev environment (Zcash, Solana, NEAR)
devenv-start:
cd devenv && ./start-dev-env.sh
# Run TypeScript + NEAR + Noir integration test
devenv-test:
cd devenv && npm install && npm run test-integration
# Start Geyser entry sync daemon
devenv-geyser-sync:
cd devenv && npm run geyser-sync
# Start Wormhole blockhash sync daemon (mock)
devenv-wormhole-sync:
cd devenv && npm run wormhole-sync
# Build the sandbox tool
sandbox-build:
cargo build --release --package devenv-sandbox
# ============== Solana Development ==============
# Start Solana test validator
solana-start:
#!/usr/bin/env bash
cd "{{justfile_directory()}}/devenv"
echo "=== Starting Solana Test Validator ==="
pkill -f solana-test-validator 2>/dev/null || true
sleep 1
solana-test-validator --reset &
sleep 5
echo "Solana validator started"
solana config set --url http://localhost:8899
solana balance
# Stop Solana validator
solana-stop:
#!/usr/bin/env bash
echo "=== Stopping Solana Test Validator ==="
pkill -f solana-test-validator 2>/dev/null && echo "Stopped" || echo "Not running"
# Initialize Solana devenv (start validator)
solana-init: solana-start
@echo ""
@echo "=== Solana Development Environment Ready ==="
@echo "Validator: http://localhost:8899"
@echo ""
@echo "Solana validator is ready for Wormhole Queries"
@echo "See: just wormhole-flow"
# Solana status check
solana-status:
#!/usr/bin/env bash
echo "=== Solana Status ==="
echo ""
# Check validator
echo "Validator:"
if pgrep -f solana-test-validator >/dev/null 2>&1; then
echo " Status: Running"
SLOT=$(solana slot 2>/dev/null || echo "unknown")
echo " Slot: $SLOT"
echo " RPC: http://localhost:8899"
else
echo " Status: NOT RUNNING"
echo " Start with: just solana-start"
fi
echo ""
echo ""
echo "Note: Solana programs deprecated, using Wormhole Queries instead"
echo "See: just wormhole-status"
# Clean Solana artifacts
solana-clean:
#!/usr/bin/env bash
echo "=== Cleaning Solana Artifacts ==="
just solana-stop
rm -rf devenv/test-ledger
echo "Cleaned"
# ============== Wormhole Queries (Solana → NEAR) ==============
# Test Wormhole Query with mock guardian (reads SlotHashes from Solana)
wormhole-test-query:
#!/usr/bin/env bash
cd "{{justfile_directory()}}/devenv"
echo "=== Testing Wormhole Query for SlotHashes ==="
echo "This tests QueryProxyMock with Solana SlotHashes sysvar"
echo ""
npm run test-wormhole-query
# Generate Wormhole Query response for NEAR contract testing
wormhole-generate-response:
#!/usr/bin/env bash
cd "{{justfile_directory()}}/devenv"
echo "=== Generating Wormhole Query Response ==="
echo "This creates a signed query response from Solana SlotHashes"
echo ""
npm run generate-query-response
echo ""
echo "Response saved to: devenv/query-response.hex"
echo "Ready to submit to NEAR contract!"
# Test NEAR contract with Wormhole Query response (automated sandbox test)
wormhole-test-near:
#!/usr/bin/env bash
cd "{{justfile_directory()}}/devenv"
echo "=== Testing NEAR Contract with Wormhole Query ==="
echo "This runs a full integration test:"
echo " 1. Generate query response from Solana"
echo " 2. Deploy NEAR contract to sandbox"
echo " 3. Submit query response"
echo " 4. Verify slot hashes stored"
echo ""
npm run test-near-contract
# Manual NEAR contract test (step-by-step with near-cli)
wormhole-test-near-manual:
#!/usr/bin/env bash
cd "{{justfile_directory()}}/devenv"
echo "=== Manual NEAR Contract Test ==="
echo "This runs a step-by-step test with near-cli"
echo ""
./scripts/test-near-manual.sh
# Full Wormhole Queries flow (Solana → Query → NEAR)
wormhole-flow:
#!/usr/bin/env bash
echo "=== Wormhole Queries Full Flow ==="
echo ""
echo "This demonstrates the complete flow:"
echo " Solana validator → Wormhole Query → NEAR contract"
echo ""
echo "Terminal 1 (this terminal):"
echo " - Starting Solana validator..."
just solana-start
echo ""
echo " - Building NEAR contract..."
just slot-receiver-build
echo ""
echo " - Generating query response..."
just wormhole-generate-response
echo ""
echo "=== Ready for testing! ==="
echo ""
echo "Now run in this terminal:"
echo " just wormhole-test-near # Automated test (recommended)"
echo ""
echo "Or for manual testing:"
echo " just wormhole-test-near-manual"
# Wormhole Queries status
wormhole-status:
#!/usr/bin/env bash
echo "=== Wormhole Queries Status ==="
echo ""
# Check Solana validator
echo "Solana Validator:"
if pgrep -f solana-test-validator >/dev/null 2>&1; then
echo " Status: Running ✅"
SLOT=$(solana slot 2>/dev/null || echo "unknown")
echo " Slot: $SLOT"
else
echo " Status: NOT RUNNING ❌"
echo " Start with: just solana-start"
fi
echo ""
# Check query response
echo "Query Response:"
if [ -f "{{justfile_directory()}}/devenv/query-response.hex" ]; then
SIZE=$(wc -c < "{{justfile_directory()}}/devenv/query-response.hex" | tr -d ' ')
echo " Status: Generated ✅"
echo " File: devenv/query-response.hex"
echo " Size: $SIZE bytes"
else
echo " Status: Not generated"
echo " Generate with: just wormhole-generate-response"
fi
echo ""
# Check NEAR contract
echo "NEAR Contract:"
WASM_PATH="{{justfile_directory()}}/target/near/slot_receiver_contract/slot_receiver_contract.wasm"
if [ -f "$WASM_PATH" ]; then
SIZE=$(wc -c < "$WASM_PATH" | tr -d ' ')
echo " Status: Built ✅"
echo " File: target/near/slot_receiver_contract/slot_receiver_contract.wasm"
echo " Size: $SIZE bytes"
else
echo " Status: Not built"
echo " Build with: just slot-receiver-build"
fi
echo ""
# Check last deployed contract
if [ -f "{{justfile_directory()}}/devenv/.last-deployed-contract" ]; then
CONTRACT_ID=$(cat "{{justfile_directory()}}/devenv/.last-deployed-contract")
echo "Last Deployed Contract:"
echo " Contract ID: $CONTRACT_ID"
echo " Query with: near view $CONTRACT_ID get_latest_slot '{}'"
fi
# Clean Wormhole Queries artifacts
wormhole-clean:
#!/usr/bin/env bash
echo "=== Cleaning Wormhole Queries Artifacts ==="
rm -f "{{justfile_directory()}}/devenv/query-response.hex"
rm -f "{{justfile_directory()}}/devenv/.last-deployed-contract"
rm -rf "{{justfile_directory()}}/target/near/slot_receiver_contract"
echo "Cleaned"
# Start NEAR sandbox (persistent, stays running)
sandbox-start: sandbox-build
./target/release/sandbox start
# Start NEAR sandbox and deploy contracts
sandbox-start-deploy: sandbox-build zcash-build slot-receiver-build
./target/release/sandbox start --deploy
# Start ZCash regtest node
devenv-zcash-up:
cd devenv/docker && docker compose up -d zcash
# Stop ZCash regtest node
devenv-zcash-down:
cd devenv/docker && docker compose down zcash
# Nuke ZCash regtest (stop container + delete all data)
devenv-zcash-nuke:
#!/usr/bin/env bash
echo "=== Nuking ZCash Regtest ==="
cd devenv/docker && docker compose down zcash 2>/dev/null || true
docker volume rm chalice-devenv_zcash-regtest-data 2>/dev/null && echo "Deleted ZCash volume" || echo "Volume already gone"
rm -f ../zcash-addresses.json
echo "Done. Run 'just devenv-zcash-up' to start fresh."
# View ZCash logs
devenv-zcash-logs:
cd devenv/docker && docker compose logs -f zcash
# Setup ZCash (create addresses, mine initial blocks)
devenv-zcash-setup:
chmod +x devenv/scripts/*.sh && devenv/scripts/setup-zcash.sh
# ZCash CLI shortcut
zcash-cli *ARGS:
chmod +x devenv/scripts/zcash-cli.sh && devenv/scripts/zcash-cli.sh {{ARGS}}
# Mine blocks on ZCash regtest
devenv-mine BLOCKS="1":
chmod +x devenv/scripts/zcash-cli.sh && devenv/scripts/zcash-cli.sh generate {{BLOCKS}}
# Get ZCash block data
devenv-get-block HEIGHT:
chmod +x devenv/scripts/get-block-data.sh && devenv/scripts/get-block-data.sh {{HEIGHT}}
# Send test transaction (manual address)
devenv-send-tx TO AMOUNT:
chmod +x devenv/scripts/send-test-tx.sh && devenv/scripts/send-test-tx.sh {{TO}} {{AMOUNT}}
# Send test transaction to MPC address (uses saved addresses)
devenv-test-tx AMOUNT="1.0":
#!/usr/bin/env bash
set -e
MPC_ADDR=$(jq -r '.mpc_address' devenv/zcash-addresses.json)
chmod +x devenv/scripts/send-test-tx.sh
devenv/scripts/send-test-tx.sh "$MPC_ADDR" {{AMOUNT}}
# Show saved ZCash addresses
devenv-addresses:
@cat devenv/zcash-addresses.json 2>/dev/null || echo "No addresses yet. Run: just devenv-zcash-setup"
# Install devenv dependencies
devenv-install:
cd devenv && npm install
# Build the ZCash relayer (for syncing blocks to NEAR)
relayer-build:
cd btc-light-client-contract/relayer && cargo build --release --no-default-features --features "zcash"
# Build the ZCash regtest relayer (for local development)
relayer-build-regtest:
cd btc-light-client-contract/relayer && cargo build --release --no-default-features --features "zcash,regtest"
@echo "Relayer built at: btc-light-client-contract/relayer/target/release/btc-relayer"
@echo "Config template at: devenv/relayer-config.toml"
# Show ZCash info
devenv-info:
cd devenv && npm run light-client -- info
# Sync blocks from ZCash to Indexer (via light client)
devenv-sync:
cd devenv && npm run light-client -- sync && npm run sync-indexer
# Get current block height
devenv-height:
@devenv/scripts/zcash-cli.sh getblockcount
# ============== Devenv Orchestration ==============
# Initialize development environment (alias for devenv-start)
devenv-init:
@echo "Note: devenv-init is now an alias for devenv-start"
@echo ""
just devenv-start
# Run the ZCash relayer pointing to the sandbox
# Requires: just devenv-init (to initialize the light client first)
relayer-devnet:
#!/usr/bin/env bash
set -e
cd "{{justfile_directory()}}"
# Read sandbox state
if [ ! -f devenv/devenv-state.json ]; then
echo "ERROR: Sandbox not running."
echo ""
echo "Run these commands first:"
echo " Terminal 1: just sandbox-start-deploy"
echo " Terminal 2: just devenv-init"
exit 1
fi
RPC_URL=$(jq -r '.rpc_url' devenv/devenv-state.json)
LC_ACCOUNT=$(jq -r '.light_client_account_id' devenv/devenv-state.json)
ROOT_ACCOUNT=$(jq -r '.root_account_id' devenv/devenv-state.json)
# Check sandbox is actually running
if ! curl -s "$RPC_URL/status" >/dev/null 2>&1; then
echo "ERROR: Sandbox not responding at $RPC_URL"
echo ""
echo "Run 'just sandbox-start-deploy' in another terminal first."
exit 1
fi
echo "=== ZCash Relayer (Devnet) ==="
echo "NEAR RPC: $RPC_URL"
echo "Light Client: $LC_ACCOUNT"
echo ""
echo "NOTE: Light client must be initialized first with 'just devenv-init'"
echo ""
# Export credentials for relayer
# Read the sandbox-generated secret key
SECRET_KEY=$(jq -r '.root_secret_key' devenv/devenv-state.json)
export RELAYER__NEAR__ENDPOINT="$RPC_URL"
export RELAYER__NEAR__ACCOUNT_ID="$ROOT_ACCOUNT"
export RELAYER__NEAR__PRIVATE_KEY="$SECRET_KEY"
export RELAYER__NEAR__BTC_LIGHT_CLIENT_ACCOUNT_ID="$LC_ACCOUNT"
# Set default RUST_LOG level to 'info' if not already set
export RUST_LOG="${RUST_LOG:-info}"
btc-light-client-contract/relayer/target/release/btc-relayer -c devenv/relayer-config.toml
# Full test flow with persistent sandbox: send tx -> mine -> index -> verify
devenv-test-flow AMOUNT="1.0":
#!/usr/bin/env bash
set -e
cd "{{justfile_directory()}}"
# Helper function for zcash-cli
zcash_cli() {
docker exec chalice-zcash zcash-cli -regtest -rpcuser=zcash -rpcpassword=zcash "$@"
}
echo "=== Running Full Test Flow ==="
echo ""
# Check sandbox
if [ ! -f devenv/devenv-state.json ]; then
echo "ERROR: Sandbox not running. Run 'just sandbox-start-deploy' first."
exit 1
fi
# Get MPC address
if [ ! -f devenv/zcash-addresses.json ]; then
echo "ERROR: ZCash not setup. Run 'just devenv-init' first."
exit 1
fi
MPC_ADDR=$(jq -r '.mpc_address' devenv/zcash-addresses.json)
echo "MPC Address: $MPC_ADDR"
# Get current block height
BEFORE_HEIGHT=$(zcash_cli getblockcount)
echo "Current ZCash height: $BEFORE_HEIGHT"
echo ""
# 1. Send test transaction
echo "1. Sending {{AMOUNT}} ZEC to MPC address..."
TXID=$(zcash_cli sendtoaddress "$MPC_ADDR" {{AMOUNT}})
echo " TX: $TXID"
echo ""
# 2. Mine blocks
echo "2. Mining 1 block..."
zcash_cli generate 1
NEW_HEIGHT=$(zcash_cli getblockcount)
echo " New height: $NEW_HEIGHT"
echo ""
# 3. Sync everything
echo "3. Syncing blocks..."
cd devenv && npm run light-client -- sync && npm run sync-indexer
# 4. Prove Inclusion
echo ""
echo "4. Proving Inclusion..."
cd devenv && npm run prove-inclusion -- $TXID
echo ""
echo "=== Test Complete ==="
echo "Proof verified on-chain!"
# Kill all sandbox processes and clean up state
devenv-kill:
#!/usr/bin/env bash
echo "=== Killing devenv processes ==="
pkill -f near-sandbox 2>/dev/null && echo "Killed near-sandbox processes" || echo "No near-sandbox processes"
pkill -f "sandbox start" 2>/dev/null && echo "Killed sandbox tool" || true
pkill -f solana-test-validator 2>/dev/null && echo "Killed solana-test-validator" || echo "No solana processes"
echo ""
echo "Removing state files..."
rm -f devenv/devenv-state.json
rm -f devenv/vaa-output.txt
rm -f devenv/query-response.hex
rm -f devenv/.last-deployed-contract
echo "Done."
# Full reset: kill everything, stop containers, clean state
devenv-reset:
#!/usr/bin/env bash
echo "=== Full Environment Reset ==="
echo ""
# Kill all processes
echo "1. Killing processes..."
pkill -f near-sandbox 2>/dev/null || true
pkill -f "sandbox start" 2>/dev/null || true
pkill -f solana-test-validator 2>/dev/null || true
# Stop containers
echo "2. Stopping containers..."
cd devenv/docker && docker compose down 2>/dev/null || true
# Clean state files
echo "3. Cleaning state files..."
rm -f devenv/devenv-state.json
rm -f devenv/zcash-addresses.json
rm -f devenv/vaa-output.txt
rm -f devenv/query-response.hex
rm -f devenv/.last-deployed-contract
# Clean temp directories
echo "4. Cleaning temp directories..."
rm -rf /tmp/sandbox-* 2>/dev/null || true
rm -rf devenv/test-ledger 2>/dev/null || true
echo ""
echo "=== Reset Complete ==="
echo ""
echo "To start fresh:"
echo " Terminal 1: just sandbox-start-deploy # NEAR sandbox"
echo " Terminal 2: just solana-init # Solana validator"
echo " Terminal 3: just devenv-init # ZCash setup"
echo ""
echo "For Wormhole Queries:"
echo " just wormhole-flow # Complete workflow"
# Quick devenv status check
devenv-status:
#!/usr/bin/env bash
cd "{{justfile_directory()}}"
echo "=== Devenv Status ==="
echo ""
# Solana
echo "Solana:"
if pgrep -f solana-test-validator >/dev/null 2>&1; then
SLOT=$(solana slot 2>/dev/null || echo "unknown")
echo " Status: Running"
echo " Slot: $SLOT"
echo " RPC: http://localhost:8899"
else
echo " Status: NOT RUNNING"
echo " Start with: just solana-init"
fi
echo ""
# ZCash
echo "ZCash:"
if docker exec chalice-zcash zcash-cli -regtest -rpcuser=zcash -rpcpassword=zcash getblockcount >/dev/null 2>&1; then
HEIGHT=$(docker exec chalice-zcash zcash-cli -regtest -rpcuser=zcash -rpcpassword=zcash getblockcount)
echo " Status: Running"
echo " Height: $HEIGHT"
else
echo " Status: NOT RUNNING"
echo " Start with: just devenv-zcash-up"
fi
echo ""
# Sandbox
echo "NEAR Sandbox:"
if [ -f devenv/devenv-state.json ]; then
RPC_URL=$(jq -r '.rpc_url' devenv/devenv-state.json)
if curl -s "$RPC_URL/status" >/dev/null 2>&1; then
echo " Status: Running"
echo " RPC: $RPC_URL"
echo " Light Client: $(jq -r '.light_client_account_id' devenv/devenv-state.json)"
echo " Indexer: $(jq -r '.indexer_account_id' devenv/devenv-state.json)"
echo " Slot Receiver: $(jq -r '.slot_receiver_account_id' devenv/devenv-state.json 2>/dev/null || echo 'not deployed')"
else
echo " Status: NOT RUNNING (stale state file)"
echo " Start with: just sandbox-start-deploy"
fi
else
echo " Status: NOT RUNNING"
echo " Start with: just sandbox-start-deploy"
fi
echo ""
# Wormhole Queries
echo "Wormhole Queries:"
QUERY_RESPONSE="devenv/query-response.hex"
SLOT_WASM="target/near/slot_receiver_contract/slot_receiver_contract.wasm"
LAST_CONTRACT="devenv/.last-deployed-contract"
if [ -f "$QUERY_RESPONSE" ]; then
SIZE=$(wc -c < "$QUERY_RESPONSE" | tr -d ' ')
echo " Query Response: Generated ($SIZE bytes)"
else
echo " Query Response: Not generated"
echo " Generate with: just wormhole-generate-response"
fi
if [ -f "$SLOT_WASM" ]; then
SIZE=$(wc -c < "$SLOT_WASM" | tr -d ' ')
echo " Contract WASM: Built ($SIZE bytes)"
else
echo " Contract WASM: Not built"
echo " Build with: just slot-receiver-build"
fi
if [ -f "$LAST_CONTRACT" ]; then
CONTRACT_ID=$(cat "$LAST_CONTRACT")
echo " Last Deployed: $CONTRACT_ID"
fi
# Orphan processes
echo ""
echo "Orphan processes:"
SANDBOX_ORPHANS=$(pgrep -fl near-sandbox 2>/dev/null | wc -l | tr -d ' ')
SOLANA_ORPHANS=$(pgrep -fl solana-test-validator 2>/dev/null | wc -l | tr -d ' ')
if [ "$SANDBOX_ORPHANS" -gt 0 ] || [ "$SOLANA_ORPHANS" -gt 0 ]; then
[ "$SANDBOX_ORPHANS" -gt 0 ] && echo " WARNING: $SANDBOX_ORPHANS sandbox process(es)"
[ "$SOLANA_ORPHANS" -gt 0 ] && echo " WARNING: $SOLANA_ORPHANS solana process(es)"
echo " Run 'just devenv-kill' to clean up"
else
echo " None"
fi
# ============== Documentation ==============
# Show project structure
tree:
@echo "Project Structure:"
@echo ""
@echo "crates/"
@echo "├── near-bigint/ # U256 + BN254 field arithmetic"
@echo "├── near-bn254-pairing/ # NEAR alt_bn128 precompile wrappers"
@echo "├── near-ultrahonk-verifier/ # Core verifier (Rust port of Solidity)"
@echo "├── verifier-contract/ # NEAR UltraHonk proof verifier contract"
@echo "├── zcash-indexer-contract/ # NEAR ZCash/Bitcoin transaction indexer"
@echo "├── slot-receiver-contract/ # NEAR Solana slot hash receiver (Wormhole VAA)"
@echo "├── solana-entry-indexer/ # Geyser plugin for Solana PoH entries"
@echo "└── solidity-contracts/ # Reference Solidity verifier"
@echo ""
@echo "solana-programs/"
@echo "├── slot-hash-poster/ # Reads SlotHashes sysvar and posts to Wormhole"
@echo "└── blockhash-reader/ # Demo: reads RecentBlockhashes sysvar"
@echo ""
@echo "noir-circuits/"
@echo "├── inclusion-nr/ # Bitcoin Merkle inclusion proof circuit"
@echo "├── dual-inclusion-nr/ # ZCash + Solana dual inclusion circuit"
@echo "└── test-circuits/simple/ # Simple test circuit (x + y == 42)"
@echo ""
@echo "devenv/"
@echo "├── docker/ # Docker compose for ZCash regtest"
@echo "├── scripts/ # Setup and testing scripts"
@echo "│ ├── ts/mock-guardian.ts # Mock Wormhole guardian (Solana→NEAR)"
@echo "│ └── ts/light-client.ts # ZCash light client sync"
@echo "└── vaa-output.txt # Generated Wormhole VAAs"
@echo ""
@echo "docs/"
@echo "└── ULTRAHONK_VERIFIER_PORT.md # Porting journey documentation"