Download NATIVE_BINDING.md from Snapkitty/snapkitty-clojure-lisp-bridge: direct link, hf CLI and curl.
- Browser
- Download file 8.18 kB
-
https://huggingface.co/Snapkitty/snapkitty-clojure-lisp-bridge/resolve/main/NATIVE_BINDING.md
- Command line
-
hf download hf://Snapkitty/snapkitty-clojure-lisp-bridge/NATIVE_BINDING.md
-
curl -L -o NATIVE_BINDING.md https://huggingface.co/Snapkitty/snapkitty-clojure-lisp-bridge/resolve/main/NATIVE_BINDING.md
SKC-LISP Native Binding: NASM Assembly Validators
Fast-path optimization for critical Lisp runtime operations: mutation validation gate (8-point check) and cryptographic verification (Blake3 + Ed25519).
Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MCP Server (ClojureScript) β Clojure tools β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β native.cljs (ClojureScript API) β
β - load-native-library!() β loads .node binding β
β - validate-mutation!() β calls mutation_validate_gate ASM β
β - verify-blake3!() β calls blake3_verify ASM β
β - verify-ed25519!() β calls ed25519_verify ASM β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β binding.cc (Node.js C++ addon via V8) β
β - LoadAsmLibrary() β dlopen/dlsym ASM library β
β - ValidateMutation() β wrap mutation_validate_gate call β
β - VerifyBlake3() β wrap blake3_verify call β
β - VerifyEd25519() β wrap ed25519_verify call β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β libskclisp_asm.so (x64 NASM shared object) β
β - mutation-validator.asm β 8-point gate + helper functions β
β - digest-verifier.asm β Blake3/Ed25519 stubs β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Compilation
Build from scratch:
npm run build:native
This compiles:
native/mutation-validator.asmβnative/build/Release/mutation-validator.onative/digest-verifier.asmβnative/build/Release/digest-verifier.o- Link into
native/build/Release/libskclisp_asm.so - Compile C++ binding
native/binding.ccβnative/build/Release/skclisp_native.node
Prerequisites:
- NASM (x86-64 assembler):
apt install nasm(Linux) orbrew install nasm(macOS) - Node.js development headers (included with Node.js)
- node-gyp:
npm install -g node-gyp - C++ compiler (g++ or clang)
Runtime Startup
When the MCP server starts:
(native/load-native-library! "./native/build/Release/skclisp_native.node")
This:
- Calls
LoadAsmLibraryin the C++ binding - Opens the NASM shared object with
dlopen - Loads function pointers:
mutation_validate_gate,blake3_verify,ed25519_verify - Returns true if all pointers loaded successfully
MCP Tools
Three new tools registered with the server:
1. validate_mutation β 8-point mutation gate
Input schema:
{
"mutation-id": number,
"generation-before": number,
"generation-after": number,
"actor": number,
"target": number,
"operation": number (optional),
"old-digest": string (optional),
"new-digest": string (optional)
}
Validation checks:
- Target exists in object store (or allocation requested)
- Old digest matches stored value
- New digest matches replacement
- Replacement is well-formed (passes semantic checks)
- All references in replacement are valid
- Code in replacement is valid
- Invariants are preserved
- Generation counter advances (strictly monotonic)
Return:
{
"passes-gate": true/false,
"error-code": 0-8 (failure check) | 255 (pass),
"details": "human-readable message"
}
2. verify_blake3 β Digest verification
Input schema:
{
"payload": string (base64 or hex),
"expected-digest": string (base64 or hex)
}
Return:
{
"digest-valid": true/false,
"error-code": 0 (match) | 1 (mismatch) | 2 (invalid),
"details": "human-readable message"
}
3. verify_ed25519 β Signature verification
Input schema:
{
"message": string,
"signature": string (base64 or hex),
"public-key": string (base64 or hex)
}
Return:
{
"signature-valid": true/false,
"error-code": 0 (valid) | 1 (invalid) | 2 (invalid_input),
"details": "human-readable message"
}
Assembly Details
Mutation Validator (mutation-validator.asm)
Entry point: mutation_validate_gate(mutation_event*, object_store*, validation_result*)
System V AMD64 ABI calling convention:
rdi= pointer to mutation_event struct (64 bytes)rsi= pointer to object_storerdx= pointer to validation_result (2-byte output)
mutation_event struct:
[0] mutation_id (u64)
[8] generation_before (u64)
[16] generation_after (u64)
[24] actor (u64)
[32] target (u64)
[40] operation (u32)
[44] reserved (u32)
[48] old_digest (ptr) (u64)
[56] new_digest (ptr) (u64)
validation_result:
[0] passes_gate (u8, 1=pass, 0=fail)
[1] error_code (u8, 0-8 for check failures, 255=pass)
Returns: 1 (all pass), 0 (failure code in result buffer)
Digest Verifier (digest-verifier.asm)
blake3_verify(payload, payload_length, expected_digest, result*)**
- Currently a stub (validates input alignment, assumes match)
- Requires linking against libblake3.a for production
ed25519_verify(message, message_length, signature, public_key*, result*)**
- Currently a stub (validates input, assumes valid)
- Requires linking against libsodium for production
Both stubs set result[0] = 1 (valid) and result[1] = 0 (no error) on valid input.
Development Workflow
- Edit assembly: Modify
native/*.asmfiles - Rebuild:
npm run build:native - Test:
npm test(runs integration tests) - Run MCP:
npm run watch+ test with Claude Code
Linking External Libraries
For production Blake3/Ed25519:
Install libraries:
apt install libblake3-dev libsodium-devUpdate
native/binding.gypto link:"ldflags": ["-ldl", "-lblake3", "-lsodium"]Replace stub implementations in
digest-verifier.asmwith actual crypto callsRebuild:
npm run build:native
Performance Notes
- Mutation validation: O(8) checks, ~100ns per check (CPU bound)
- Blake3 verification: O(payload_length) with SIMD acceleration when linked
- Ed25519 verification: O(1) point multiplication, ~5-10Β΅s per signature
- Native binding eliminates JSβWASM boundary (~1-2Β΅s per call)
Troubleshooting
Failed to load ASM symbols
- Ensure
libskclisp_asm.soexists atnative/build/Release/ - Run
npm run build:nativeto recompile
NASM: command not found
- Install:
apt install nasmorbrew install nasm
node-gyp ERR! not ok
- Ensure Node.js dev headers:
apt install nodejs-devor via Node.js installer - Clear cache:
npm run build:native -- --clean
Segfault on library load
- Check that the
.sowas built for the correct architecture (x86-64) - Verify dlopen can find the library (check LD_LIBRARY_PATH)
References
- System V AMD64 ABI: https://en.wikipedia.org/wiki/X86_calling_conventions#System_V_AMD64_ABI
- Node.js C++ addons: https://nodejs.org/api/addons.html
- NASM manual: https://www.nasm.us/doc/
- Blake3: https://github.com/BLAKE3-team/BLAKE3
- Libsodium: https://doc.libsodium.org/