Commit Graph

11149 Commits

Author SHA1 Message Date
Claude cd573a583c fix: WebRTC call bugs and add Call Settings screen
Bug fixes:
- Fix invitePeer() bypassing CallManager state tracking, causing
  invited peers to not appear in pendingPeerPubKeys
- Remove 10-minute proximity wake lock timeout so it lasts the
  full call duration (released on cleanup)
- Send hangup to peers on caller timeout so callees stop ringing
  immediately instead of waiting for their own 60s timeout
- Remove duplicate cleanup() call on Ended→Idle transition

New feature:
- Add Call Settings screen (TURN servers + video quality)
- Users can configure custom TURN servers for restrictive networks
- Default STUN/TURN servers are always active and displayed
- Video resolution options: 480p, 720p (default), 1080p
- Configurable max video bitrate: 750kbps, 1.5Mbps, 3Mbps
- Settings wired into IceServerConfig and CallMediaManager

https://claude.ai/code/session_01F5RF2yzngiMr1v2gr7f1GP
2026-04-10 17:18:25 +00:00
Vitor Pamplona 8813907bd3 Merge pull request #2204 from vitorpamplona/claude/optimize-secp256k1-performance-DPixr
Replace LongArray with Fe4 struct for secp256k1 field elements
2026-04-10 10:30:45 -04:00
Vitor Pamplona aa00cb74bb Merge pull request #2203 from vitorpamplona/claude/review-webrtc-calls-a7ZCq
Improve WebRTC call reliability and notification handling
2026-04-10 08:51:21 -04:00
Vitor Pamplona c7f08a1c44 Merge pull request #2202 from vitorpamplona/claude/review-marmot-mls-nFJQr
RFC 9420 compliance: encryption, commit ordering, and thread safety
2026-04-10 08:50:22 -04:00
Vitor Pamplona 4d7eba2a21 Merge pull request #2201 from mstrofnone/fix/largecache-concurrent-modification
fix(quartz): snapshot LargeCache entries in forEach to prevent ConcurrentModificationException
2026-04-10 08:10:44 -04:00
M ed11d2cd45 fix(quartz): snapshot LargeCache entries in forEach to prevent ConcurrentModificationException
On Apple (iOS/macOS) and Linux targets, LargeCache.forEach() iterates
the underlying map directly. When another coroutine modifies the map
during iteration (e.g., NostrClient.syncFilters running while
subscriptions are added), a ConcurrentModificationException is thrown.

On JVM/Android this is not an issue because ConcurrentSkipListMap
handles concurrent iteration safely. On Kotlin/Native (iOS), this
exception is fatal — K/N calls abort() for unhandled exceptions,
crashing the app immediately after account creation when relays
connect and subscriptions start syncing.

Fix: call .entries.toList() before iterating to create a snapshot,
matching the JVM behavior where concurrent modifications during
iteration are tolerated.
2026-04-10 20:53:19 +10:00
davotoula 3294835b77 minor sonar fixes 2026-04-10 12:28:26 +02:00
David Kaspar caaf85bc07 Merge pull request #2200 from vitorpamplona/l10n_crowdin_translations
New Crowdin Translations
2026-04-10 12:06:17 +02:00
Crowdin Bot b8a3ff13f1 New Crowdin translations by GitHub Action 2026-04-10 09:54:43 +00:00
davotoula 6a3e0b0cb6 update video compressor library 2026-04-10 11:50:53 +02:00
Claude 2bb72ac43d docs: document C interop benchmarks and K/N MUL limitation
Benchmarked two approaches for hardware 128-bit multiply on K/N:

1. Full mulWide via C interop (memScoped + allocArray + fe4_mul_reduce):
   FieldP.mul: 44ns → 116ns (2.6x SLOWER — copy/marshal overhead)

2. Per-call umulh via C interop (fe4_umulh, 20 calls per field mul):
   FieldP.mul: 44ns → 331ns (7.5x SLOWER — ~15ns bridge per call)

Conclusion: K/N cinterop bridge adds ~15ns per call, making fine-grained
C interop unviable for the multiply-high hot path (20+ calls per field op).
The pure-Kotlin fused approach (4 IMUL per 128-bit product) remains optimal
at 44ns/op until K/N supports hardware MUL natively.

Updated FieldMulPlatform.native.kt docs with benchmarked rationale.
Fixed remaining LongArray references in native benchmark test.

https://claude.ai/code/session_01Sxi6Gpxbstuj3Y8TBY7XrU
2026-04-10 08:33:58 +00:00
Claude eee8b66b53 fix: round 2 MLS security fixes — resolve critical key schedule and validation gaps
Critical fixes:
- Fix PSK/ExternalInit proposals by Reference dropped from key schedule:
  processCommit now collects ALL resolved proposals (inline + by-reference)
  into resolvedProposals list used for PSK and ExternalInit computation
- Fix decrypt() missing blank-leaf membership check: validate sender leaf
  is non-null (occupied) before proceeding with decryption

High fixes:
- Fix MlsGroupManager.decrypt() now mutex-protected to prevent concurrent
  SecretTree ratchet corruption and potential nonce reuse

Medium fixes:
- Fix externalJoin: verify GroupInfo signature before trusting tree/keys
- Fix parentHash verification: COMMIT leaf nodes must have non-empty
  parentHash (no longer silently skipped)
- Fix proposal application order: Updates/Removes applied before Adds
  per RFC 9420 §12.4.2 (frees blank slots before reuse)
- Add encryption key uniqueness check in RatchetTree.addLeaf() per §7.3
- Add LeafNode capabilities validation: verify version and ciphersuite
  support in applyProposalAdd per §12.1.1
- Remove redundant confirmation tag recomputation in processCommit

https://claude.ai/code/session_017SjKXS4Vpu4xRg9zHTgpmC
2026-04-10 07:25:34 +00:00
Claude b036880947 fix: marshal WebRTC callbacks to main thread in CallController
Move foregroundServiceStarted flag check and onPeerDisconnected()
inside scope.launch to avoid accessing main-thread-only state from
WebRTC's internal observer thread.

https://claude.ai/code/session_01DE9BUAuLJSwT3jq7S53NJ6
2026-04-10 07:22:40 +00:00
Claude 28b76f4320 fix: update native benchmark to use Fe4 field access
Fix a[0]/b[0] array indexing to a.l0/b.l0 in the unsignedMultiplyHigh
and uLt micro-benchmarks on Kotlin/Native linuxX64.

Native benchmark results (Kotlin/Native LLVM AOT, linuxX64):
  verifySchnorr:     85,402 ns/op  (11,709 ops/s)
  verifySchnorrFast: 77,231 ns/op  (12,948 ops/s)
  signSchnorr:       74,702 ns/op  (13,386 ops/s)
  sign (cached pk):  41,273 ns/op  (24,228 ops/s)
  pubKeyCreate:      32,305 ns/op  (30,954 ops/s)
  ecdhXOnly:        100,152 ns/op   (9,984 ops/s)

  Field micro-benchmarks:
  FieldP.mul:  44 ns/op    FieldP.add: 5 ns/op
  FieldP.sqr:  37 ns/op    FieldP.sub: 6 ns/op

  Batch verify: 3.1x (4 events) to 7.0x (32 events) faster

https://claude.ai/code/session_01Sxi6Gpxbstuj3Y8TBY7XrU
2026-04-10 07:22:35 +00:00
davotoula 6aa949a4f4 l10n: add cs, pt-BR, sv, de translations for AI writing, wallet, GIF→MP4
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 08:21:13 +02:00
David Kaspar c52fc6b37f Merge pull request #2193 from vitorpamplona/l10n_crowdin_translations
New Crowdin Translations
2026-04-10 08:14:53 +02:00
Claude a2ba64baba feat: migrate secp256k1 from LongArray to Fe4/Wide8 structs
Full migration of the secp256k1 library from LongArray(4)/LongArray(8)
to Fe4/Wide8 struct types with @JvmField named Long fields. This
eliminates all array bounds checks from the hot path.

Files migrated (13 source + 7 test + 2 benchmark):
  - U256.kt, FieldP.kt, ScalarN.kt, Glv.kt, ECPoint.kt
  - FieldMulPlatform.kt (expect + 3 actuals), FieldMulFused.kt
  - PointTypes.kt (MutablePoint, AffinePoint, PointScratch)
  - KeyCodec.kt, Secp256k1.kt
  - All test files and benchmarks

Bytecode impact:
  Before: 464 laload/lastore (bounds-checked) in core arithmetic
  After:  0 laload/lastore, all getfield/putfield (no checks)

The public API (Secp256k1 object) is unchanged - it still accepts
and returns ByteArray. Fe4 conversion happens at the API boundary
via U256.fromBytes()/U256.toBytes().

All secp256k1 unit tests pass on JVM.

https://claude.ai/code/session_01Sxi6Gpxbstuj3Y8TBY7XrU
2026-04-10 03:30:53 +00:00
Claude ed5515a7c5 fix: critical MLS security fixes for Marmot protocol (RFC 9420 compliance)
Phase 1 - Critical/High cryptographic fixes:
- Fix sender data nonce reuse: derive key/nonce from ciphertext sample per §6.3.1
- Add PrivateContentAAD binding (group_id, epoch, content_type) per §6.3.2
- Add SenderDataAAD binding per §6.3.1
- Fix KDFLabel encoding: use TLS fixed-width (putOpaque1/putOpaque4) not QUIC VarInt
- Add reuse_guard (4-byte random XOR into nonce) per §6.3.1
- Fix parent hash verification: capture sibling hashes before UpdatePath applied
- Fix Welcome confirmation tag: use HMAC instead of ExpandWithLabel
- Make confirmation tag mandatory in processCommit (was nullable)
- Fix off-by-one in path secret derivation during processCommit
- Fix TokenEncryption: extract 32-byte x-only pubkey from 33-byte compressed key
- Fix SELF_REMOVE proposal type: move from 0x0008 to 0xF001 (private-use range)

Phase 2 - Protocol compliance and thread safety:
- Validate KeyPackage ciphersuite is supported (0x0001 only)
- Synchronize KeyPackageRotationManager read operations with mutex
- Synchronize EpochCommitTracker with lock object
- Synchronize processedEventIds with lock in MarmotInboundProcessor
- Synchronize MlsGroupManager encrypt/decrypt with mutex
- Synchronize MarmotSubscriptionManager read methods
- Require unresolved proposal references to error per §12.4.2

Phase 3 - Hardening:
- Add path traversal validation in AndroidMlsGroupStateStore (hex-only groupId)
- Bind nostrGroupId as AAD in outer ChaCha20-Poly1305 encryption
- Track failed events in dedup set to prevent CPU exhaustion
- Validate nostrGroupId in processWelcome against Welcome event's own h tag
- Validate sender leaf index bounds during decryption

Phase 4 - Low priority fixes:
- Fix externalJoin: compute confirmedTranscriptHash and interimTranscriptHash
- Add snapshot methods for non-suspend filter access

https://claude.ai/code/session_017SjKXS4Vpu4xRg9zHTgpmC
2026-04-10 03:23:15 +00:00
Claude e4c8efb046 fix: address WebRTC call implementation bugs and hardening
- Fix enableVideo() not restarting camera after disable/re-enable
- Add hangup action to foreground service notification with tap-to-open
- Register BluetoothSco receiver with RECEIVER_NOT_EXPORTED flag
- Replace GlobalScope with lifecycleScope+NonCancellable in CallActivity
- Replace GlobalScope with goAsync()+MainScope in CallNotificationReceiver
- Reduce proximity WakeLock timeout from 1 hour to 10 minutes
- Add try-catch to CallMediaManager.initialize() to prevent EglBase leak
- Add ICE restart attempt before giving up on FAILED state
- Add VideoRenderer update block to handle track reference changes

https://claude.ai/code/session_01DE9BUAuLJSwT3jq7S53NJ6
2026-04-10 03:07:10 +00:00
Claude ea8b693785 feat: add Fe4 struct-based field elements to eliminate array bounds checks
Prototype Fe4/Wide8 classes that replace LongArray(4)/LongArray(8) with
named @JvmField Long fields. Every LongArray access compiles to
laload/lastore (3 bytecode insns + implicit bounds check); Fe4 field
access compiles to getfield/putfield (2 insns, zero checks).

Bytecode impact (core arithmetic files):
  LongArray: 464 bounds-checked array ops (U256: 150, FieldP: 119, Fused: 195)
  Fe4:         0 bounds-checked ops, 203 direct field accesses

JVM benchmark results (HotSpot C2, best of 3 rounds, alternating order):
  FieldP.mul:  40 ns → 41 ns  (~equal, C2 fully optimizes hot mul)
  FieldP.sqr:  48 ns → 30 ns  (+60% faster)
  FieldP.add:   9 ns →  6 ns  (+34% faster)
  FieldP.sub:  10 ns →  6 ns  (+55% faster)
  U256.sqrWide: 37 ns → 17 ns (+114% faster)

The gains are largest for sqr/add/sub which have high ratios of
array read-modify-write patterns. Expected to be even larger on
Android ART (limited inlining) and Kotlin/Native LLVM (AOT, no
profile-guided bounds check elimination).

https://claude.ai/code/session_01Sxi6Gpxbstuj3Y8TBY7XrU
2026-04-10 02:31:55 +00:00
Crowdin Bot f191389782 New Crowdin translations by GitHub Action 2026-04-09 23:27:49 +00:00
Vitor Pamplona a9e59d817f Improves benchmark names, options and formatting 2026-04-09 19:25:47 -04:00
Vitor Pamplona 0823a86923 Merge pull request #2197 from vitorpamplona/claude/fix-libsecp256k1-macos-qXyE4
Add cross-platform support and simplify benchmark output
2026-04-09 19:01:53 -04:00
Claude 3c95229c52 fix: remove comparison table from benchmark script, keep raw results
Each platform section now prints its results directly instead of
collecting them for a final aggregated table.

https://claude.ai/code/session_01JZbyrS9xZEtJ9Y4yfsmnz1
2026-04-09 22:54:22 +00:00
Claude 141997b75d fix: support macOS in quartz benchmark run_all.sh
The script was hardcoded for Linux (searching for .so files and
linux-x86_64 paths). Add platform detection via uname so it finds
the correct native library on macOS (darwin .dylib) and Linux
(aarch64 and x86_64). Skip K/Native benchmark on non-Linux since
only linuxX64 target exists.

https://claude.ai/code/session_01JZbyrS9xZEtJ9Y4yfsmnz1
2026-04-09 22:37:52 +00:00
Vitor Pamplona 4d8340a9d7 Merge pull request #2195 from vitorpamplona/claude/optimize-secp256k1-pfzWD
Optimize secp256k1 field arithmetic with fused multiply and inline comparisons
2026-04-09 18:11:40 -04:00
Claude c33e3bd54f feat: add cross-platform benchmark comparison script
run_all.sh runs all secp256k1 benchmarks and produces a formatted
comparison table. Runs C native, Kotlin/Native, JVM (always), and
Android (only if device/emulator connected via adb).

Output includes:
- ops/sec with comma-separated numbers
- libsecp256k1 vs Quartz column headers
- verifySchnorrFast and signSchnorr (cached pk) as Quartz-only rows
- Ratio table: C vs K/Native, JNI vs JVM Kotlin (apples-to-apples)
- Android column and ratios when device is connected

Run from repo root: ./quartz/benchmarks/run_all.sh

https://claude.ai/code/session_015CtM5k88rF7WFgX8o2AGNR
2026-04-09 22:10:19 +00:00
Claude e2725718c2 docs: add standalone C benchmark for libsecp256k1
Standalone C program that links against the ACINQ secp256k1-kmp-jni
.so to benchmark raw C libsecp256k1 performance without any JVM, JNI,
or ART overhead. Uses the same test vectors as the Kotlin benchmarks.

Useful as a baseline when comparing Kotlin/Native or Android results
against the C library on the same hardware.

https://claude.ai/code/session_015CtM5k88rF7WFgX8o2AGNR
2026-04-09 21:39:23 +00:00
Claude 9aa3e211b9 perf: pass PointScratch through mul and mulG, eliminate ThreadLocal
Add optional PointScratch parameter to ECPoint.mul and ECPoint.mulG
(default to scratch.get() for backward compat). All callers in
Secp256k1.kt now pass their already-fetched scratch through.

From the ECDH trace: ECPoint.mul was calling scratch.get() (ThreadLocal)
redundantly — the caller already had the scratch. On ART, each
ThreadLocal.get costs ~6µs (hash table probe), and ECDH had 10 calls
totaling 64µs.

With this change, all hot-path EC operations (verify, sign, ECDH,
pubkey create, tweak mul) fetch the scratch once at the entry point
and pass it through the entire call chain.

https://claude.ai/code/session_015CtM5k88rF7WFgX8o2AGNR
2026-04-09 21:33:38 +00:00
Claude e148ff1ed7 perf: replace all uLt with uLtInline, inline isInfinity body
Replace every non-inline uLt() call with uLtInline() across FieldP.kt,
U256.kt, and ScalarN.kt. The expect/actual uLt() can't be inline
(KMP limitation), costing ~84ns per call on ART as a real function
dispatch. From the trace: 12,394 uLt calls × 84ns = 1.035ms per
verify (1.2% of total).

uLtInline uses the same XOR-with-MIN_VALUE trick but as a package-level
inline function — zero dispatch overhead.

Also inline isInfinity() body directly: was delegating to U256.isZero()
(double dispatch), now computes (z[0] or z[1] or z[2] or z[3]) == 0L
directly. 190 calls × 347ns = 66µs saved.

https://claude.ai/code/session_015CtM5k88rF7WFgX8o2AGNR
2026-04-09 21:19:52 +00:00
Claude 40cb0e270c perf: eliminate redundant ThreadLocal.get and copyInto$default calls
Pass PointScratch through mulDoubleG instead of re-fetching from
ThreadLocal. The verify path was calling ThreadLocal.get() 2x:
once in verifySchnorrFast and again in mulDoubleG. On ART, each
ThreadLocal.get costs ~41µs (hash table probe), totaling ~83µs
per verify (~1% of total).

mulDoubleG now accepts an optional PointScratch parameter
(defaults to scratch.get() for backward compat). The verify
path passes its already-fetched scratch through.

Also fix all remaining LongArray copyInto calls with default params:
- MutablePoint.copyFrom: 3 calls per copy (x, y, z)
- MutablePoint.setAffine: 2 calls (x, y)
- mulDoubleG P-table build: 2 calls per table entry
- mul P-table build: 2 calls per table entry
- batchToAffine: 2 calls
- U256.copyInto: was delegating with defaults

Each copyInto$default adds a bitmask check + 3 branches + arraylength
per call. With ~13 LongArray copies per verify, this eliminates ~52
extra branch instructions from the hot path.

https://claude.ai/code/session_015CtM5k88rF7WFgX8o2AGNR
2026-04-09 21:14:57 +00:00
Claude cb486778db perf: eliminate heap allocations in key operations
Replace U256.fromBytes (allocates LongArray(4)) with
U256.fromBytesInto (writes to pre-allocated scratch) across
all key operations:

- pubkeyCreate: scalar → sc.scalarTmp1 (safe: mulG doesn't use it)
- signSchnorrWithPubKey: d0 → sc.zInv (safe: signSchnorrInternal
  doesn't use it; d0 is read at lines 322-324 and 391 before zInv
  is needed)
- signSchnorrWithXOnlyPubKey: same pattern with sc.zInv
- pubKeyTweakMul: scalar → sc.scalarTmp1 (safe: ECPoint.mul
  doesn't use scalarTmp fields)
- ecdhXOnly: k → sc.scalarTmp1 (same)
- privKeyTweakAdd: already fixed in previous commit

signSchnorr keeps its allocation because d0 must survive through
mulG (which destroys splitK*) AND signSchnorrInternal (which uses
scalarTmp*). The single LongArray(4) alloc is negligible vs mulG
cost (~100μs).

Each eliminated allocation saves ~10-20ns of GC pressure on ART
and ~5ns on K/Native. For signSchnorrWithPubKey (the cached-pk
fast path), this removes the only unnecessary allocation.

https://claude.ai/code/session_015CtM5k88rF7WFgX8o2AGNR
2026-04-09 21:08:35 +00:00
Claude 6b1bc947a9 perf: eliminate heap allocations in privKeyTweakAdd
Use thread-local scratch LongArrays instead of allocating 2
intermediate LongArray(4) via U256.fromBytes. The old path did:
  fromBytes(seckey) → alloc LongArray(4)
  fromBytes(tweak)  → alloc LongArray(4)
  ScalarN.add(a, b) → alloc LongArray(4)
  U256.toBytes(r)   → alloc ByteArray(32)
  = 4 heap allocations

New path uses pre-allocated scratch from PointScratch:
  fromBytesInto(scratch, seckey) → zero alloc
  fromBytesInto(scratch, tweak) → zero alloc
  ScalarN.addTo(scratch, a, b)  → zero alloc
  U256.toBytes(r)               → 1 alloc (unavoidable, return value)

K/Native: 163 → 88 ns (-46%, from 6.3x to 3.4x vs C)
JVM: now faster than native C via JNI (Kotlin 6.5M ops/s vs C 4.8M ops/s)

https://claude.ai/code/session_015CtM5k88rF7WFgX8o2AGNR
2026-04-09 20:59:58 +00:00
Claude 0ca3ff71eb perf: fuse 128-bit multiply for K/Native (saves 16 mul per field op)
Add fieldMulReduceFused and fieldSqrReduceFused that compute both lo
and hi of each 64×64→128 multiply from 4 shared sub-products.

Previous: lo = a * b (1 hardware mul) + hi = umulh(a,b) (4 imul) = 5
Fused: 4 shared sub-products compute both lo and hi = 4 multiplies

The inline lambda consumer pattern avoids allocation:
  mulFull(a, b) { lo, hi -> ... }  // everything inlined at call site

K/Native benchmark improvement (linuxX64):
  verifySchnorrFast: 101,637 → 96,699 ns (-5%)
  signSchnorr(cached): 50,206 → 45,037 ns (-10%)
  compressedPubKeyFor: 40,906 → 37,075 ns (-9%)
  Native instruction count: 95 → 79 multiplies per field mul

Android keeps the unfused path because ART's single-cycle MUL for
a*b is faster than manually constructing lo from sub-products.
The fused approach saves 1 multiply but adds ~5 shift/and/or ops —
net regression on ART (80,756 vs 74,898 ns for verify).

https://claude.ai/code/session_015CtM5k88rF7WFgX8o2AGNR
2026-04-09 20:45:50 +00:00
Claude 0c51dbcf74 docs: document failed UMULH approaches on Android
Remove crypto-intrinsics module and API-tiered dispatch files.
Revert to the pure-Kotlin fallback for Android field multiply.

Three approaches to reach hardware UMULH were tested on Pixel 8
(Android 16, API 36) and all failed:

1. Direct Math.unsignedMultiplyHigh from Kotlin:
   D8 replaces with pure-Java backport when app minSdk=26 < 35.

2. MethodHandle.invokeExact via Java helper module:
   Bytecode correct (invoke-polymorphic JJ→J, zero boxing), but
   ART can't inline invoke-polymorphic. 25ns/call → 2.2x regression.

3. Full fieldMulReduce in Java, module with minSdk=35:
   D8 runs at APP level with app's minSdk=26, not library's minSdk=35.
   Trace confirmed: FieldMulIntrinsic$$ExternalSyntheticBackport0.m
   still generated. Plus Long.compareUnsigned (282ns/call) is slower
   than Kotlin's inlined XOR trick (~0ns).

The Kotlin inline+crossinline pattern remains optimal for ART:
- unsignedMultiplyHighFallback inlined at each call site
- uLtInline uses XOR+compare (no method call)
- Fused function fits ART's inlining budget

UMULH on Android requires raising app minSdk to 35.

https://claude.ai/code/session_015CtM5k88rF7WFgX8o2AGNR
2026-04-09 19:59:40 +00:00
Claude 7f8dba4af8 perf: add API-tiered field multiply dispatch for Android
Add 3-file dispatch structure for fieldMulReduce on Android:
- FieldMulApi35: placeholder for Math.unsignedMultiplyHigh (API 35+)
- FieldMulApi31: placeholder for Math.multiplyHigh (API 31-34)
- Fallback: pure-Kotlin 4-imul (API <31, unchanged)

All three currently use the pure-Kotlin fallback because both paths
to the hardware UMULH intrinsic are blocked:

1. Direct Math.unsignedMultiplyHigh call: D8 replaces with synthetic
   backport (ExternalSyntheticBackport0.m) when minSdk=26 < 35.
   Verified via dexdump: backport is pure-Java 4-imul, never reaches
   hardware UMULH even on API 36 devices.

2. MethodHandle.invokeExact: Kotlin compiles as regular invokevirtual
   with Object[] boxing (3 allocs per call), not type-exact
   invoke-polymorphic (JJ)J. Only Java's javac has @PolymorphicSignature
   support. KMP androidMain doesn't support Java sources.

TO UNLOCK: Add a Java helper class (MulHighInvoker.java) in a separate
Android library module that calls MethodHandle.invokeExact(long, long)
with zero boxing. This produces invoke-polymorphic that D8 cannot
desugar and ART intrinsifies to UMULH on ARM64.

https://claude.ai/code/session_015CtM5k88rF7WFgX8o2AGNR
2026-04-09 19:10:37 +00:00
Vitor Pamplona 816e2738ea Merge pull request #2192 from vitorpamplona/claude/filter-ended-games-feed-sV08Q
Remove LiveChessGameChallengeEvent from home feed filters
2026-04-09 14:26:01 -04:00
Claude 34bef2438e perf: remove lazy delegates from ECPoint precomputed tables
Convert gOddTable, gLamTable, and combTable from `by lazy` to eager
initialization. These tables are accessed on every verify (mulDoubleG)
and sign (mulG) call.

On K/Native, each `by lazy` access goes through
SynchronizedLazyImpl.getValue() — a thread-safe lock check + memory
barrier. The native disassembly showed 2 SynchronizedLazyImpl calls
per mulDoubleG invocation.

On JVM, Kotlin's lazy delegates use double-checked locking via
SynchronizedLazyImpl, adding interface dispatch + volatile read on
every access.

Move the `scratch` (ScratchLocal) field declaration before the table
fields to satisfy initialization order — buildGOddTable() and
buildCombTable() use doublePoint/addPoints which call scratch.get().

https://claude.ai/code/session_015CtM5k88rF7WFgX8o2AGNR
2026-04-09 18:01:15 +00:00
Claude 0403d64c47 fix: filter out chess game challenges from home feed, keep only ended games
LiveChessGameChallengeEvent (kind 30064) represents game offers/challenges
that haven't ended yet. Remove them from both the home feed filter and
the relay subscription so only completed games (kind 64) and game end
events (kind 30067) appear.

https://claude.ai/code/session_01XiWkVxXQBnLPTbeswL3y4c
2026-04-09 17:50:36 +00:00
Claude 39ce3ad260 perf: optimize secp256k1 verify bytecode — fix JIT/branch issues
Three bytecode-level optimizations to the Schnorr verify path:

1. Replace `by lazy` delegates with direct field init for tag hash
   prefixes (CHALLENGE_PREFIX, AUX_PREFIX, NONCE_PREFIX). Eliminates
   Lazy.getValue() interface dispatch + checkcast on every call.

2. Use explicit copyInto parameters everywhere, eliminating the
   copyInto$default bridge method (bitmask + 3 branches + arraylength
   per call). 4 calls per verify × 3 using defaults = 12 extra branches
   removed from the hot path.

3. Extract shared verify computation into verifySchnorrCore(), called
   by both verifySchnorr() and verifySchnorrFast(). Previously, two
   ~400-bytecode near-identical methods competed for JIT optimization.
   Now one hot method gets compiled, and both public methods are thin
   wrappers (34 and 130 bytecodes).

JVM benchmark before: verifySchnorrFast was 5% SLOWER than verifySchnorr
(60,930 vs 57,876 ns) due to JIT warmup ordering bias.

JVM benchmark after: verifySchnorrFast is 11% faster (50,345 vs 56,143 ns),
matching the expected ~14% savings from skipping the field inversion.

https://claude.ai/code/session_015CtM5k88rF7WFgX8o2AGNR
2026-04-09 16:43:20 +00:00
Vitor Pamplona 8710c30261 Merge branch 'main' of https://github.com/vitorpamplona/amethyst 2026-04-09 11:36:05 -04:00
Vitor Pamplona 1361353995 Merge branch 'main' of https://github.com/vitorpamplona/amethyst 2026-04-09 11:25:42 -04:00
Vitor Pamplona 45436aa4b2 Merge pull request #2190 from vitorpamplona/l10n_crowdin_translations
New Crowdin Translations
2026-04-09 11:22:07 -04:00
Crowdin Bot b9fbd77309 New Crowdin translations by GitHub Action 2026-04-09 15:14:37 +00:00
Vitor Pamplona eb32ea7fdc Merge pull request #2188 from vitorpamplona/claude/optimize-secp256k1-TFUD5
Optimize secp256k1 field arithmetic with fused multiply-reduce and platform-specific intrinsics
2026-04-09 11:12:47 -04:00
Claude da64a4a4d3 fix: align all 3 benchmarks to identical operation set
All 3 platform benchmarks (Android, JVM, K/Native) now measure the
same core operations for cross-platform comparability:

  verifySchnorr        — strict BIP-340
  verifySchnorrFast    — Nostr x-check only (no y-parity inversion)
  signSchnorr          — derives pubkey each time
  signSchnorr(cached)  — pre-computed x-only pubkey
  compressedPubKeyFor  — create + compress
  secKeyVerify         — key validation
  privKeyTweakAdd      — BIP-32 key derivation
  ecdhXOnly            — Nostr ECDH (NIP-04/44)
  batch verify (8, 16) — same-pubkey batch

Changes:
- Android: added signSchnorrCachedPkOurs, ecdhXOnly/ecdhXOnlyOurs
  (replaced pubKeyTweakMulCompact naming)
- JVM: removed pubkeyCreate and pubKeyCompress (subsets of
  compressedPubKeyFor, not measured on other platforms)
- K/Native: added verifySchnorrFast

K/Native retains field micro-benchmarks (FieldP.mul/sqr/add/sub/inv,
unsignedMultiplyHigh, uLt) as a K/N-specific diagnostic tool.

https://claude.ai/code/session_01EMY5RnXb9rnsyU2KbXrSaY
2026-04-09 15:02:39 +00:00
Claude b3206b8e48 feat: add batch verify to Android benchmark + expose in Secp256k1InstanceOurs
Add verifySchnorrBatch to Secp256k1InstanceOurs wrapper and add
Android benchmark tests for batch(8) and batch(16).

To get per-event cost: ns/op ÷ batchSize.
JVM benchmark showed 4-7× speedup over individual verify.
Android results TBD.

https://claude.ai/code/session_01EMY5RnXb9rnsyU2KbXrSaY
2026-04-09 14:45:14 +00:00
Claude 245212727a perf: keep uLt (expect/actual) for non-fused code, uLtInline only in fused
The previous commit replaced ALL uLt calls with uLtInline (XOR trick),
which regressed JVM verify from 1.6× to 1.9× vs native C. The XOR trick
is slower than Long.compareUnsigned on HotSpot.

Fix: uLtInline is used ONLY inside the fused FieldMulPlatform.kt inline
functions (which JVM doesn't use — it uses the unfused path). All other
code (U256.addTo/subTo, FieldP.add/sub/half, ScalarN, Glv) keeps the
expect/actual uLt which uses Long.compareUnsigned on JVM.

JVM: verifySchnorrFast 1.3× (restored, improved)
Android: uLt overhead remains for non-fused paths (~11K calls/verify)
but the fused mul/sqr path (the dominant cost) is fully inlined.

https://claude.ai/code/session_01EMY5RnXb9rnsyU2KbXrSaY
2026-04-09 13:55:59 +00:00
Claude e408db0944 perf: inline unsignedMultiplyHighFallback to eliminate 32K function calls
Trace profiling showed unsignedMultiplyHighFallback at 16.9% of verify
time (32,524 calls × 82ns = 2.674ms). Although called from inside an
inline crossinline lambda, the function itself was a regular dispatch.

Adding @Suppress("NOTHING_TO_INLINE") inline makes the Kotlin compiler
embed the 4-multiply arithmetic directly at each call site, eliminating
all function dispatch overhead.

https://claude.ai/code/session_01EMY5RnXb9rnsyU2KbXrSaY
2026-04-09 13:27:25 +00:00
Claude c243e3894c perf: eliminate D8 backport + uLt overhead on Android (38% of verify)
Trace profiling on Pixel 8 revealed two massive overhead sources:

1. ExternalSyntheticBackport0.m — 17.5% of verify (3.45ms)
   D8/R8 desugaring wraps Math.unsignedMultiplyHigh in a synthetic
   backport because minSdk=26 < 35. The backport adds 139ns per call
   × 24,875 calls. The actual UMULH intrinsic is ~1ns, but the
   wrapper adds ~138ns.

   FIX: Use pure-Kotlin unsignedMultiplyHighFallback on Android instead
   of Math.unsignedMultiplyHigh. The fallback (4 Long multiplies +
   shifts, ~10-20ns) is FASTER than the backported intrinsic (139ns).
   Removed all API-level dispatch — a single fallback path for all
   Android versions.

2. uLt function calls — 20.7% of verify (4.08ms)
   The expect/actual uLt (can't be inline) was called 49,924 times
   per verify at 82ns each. Most calls came from the fused
   fieldMulReduceWith/fieldSqrReduceWith inline expansions.

   FIX: Add uLtInline — a private inline function using the XOR trick
   directly. Since it's @Suppress("NOTHING_TO_INLINE") inline, the
   Kotlin compiler inlines it at every call site (not the JIT).
   Replaces all 55 uLt calls in the fused inline functions.
   JVM is unaffected (uses unfused path with Long.compareUnsigned).

Combined: eliminates ~38% of verify overhead on Android.

https://claude.ai/code/session_01EMY5RnXb9rnsyU2KbXrSaY
2026-04-09 13:13:40 +00:00