mirror of
https://github.com/luxfi/safe-magnetar.git
synced 2026-10-30 15:18:11 +00:00
2.8 KiB
2.8 KiB
safe-magnetar
Overview
Warning
Code in this repository is not audited and may contain serious security holes. Use at your own risk.
safe-magnetar integrates Magnetar (public-DKG MPC threshold hash-based signature, FIPS 205 byte-equal) with the Safe smart account by
calling the on-chain magnetarVerify precompile at 0x012207. It mirrors the
structure of safe-frost (verifier library + Safe signer/co-signer + ERC-4337
account + interfaces + Foundry tests), but the cryptographic verification is
delegated to a luxd-native precompile rather than implemented in Solidity.
Package Information
- Type: solidity (Foundry) + rust workspace stub
- Repository: github.com/luxfi/safe-magnetar
- Precompile:
0x012207(lux-evm-precompile-magnetar-v1) - Verify wire format:
mode:uint8(1) ‖ pkLen:uint16(2) ‖ pubkey ‖ msgLen:uint16(2)=32 ‖ message(32) ‖ signature - Reference precompile: github.com/luxfi/precompile/magnetar
Directory Structure
.
contracts Magnetar.sol verifier + SafeMagnetarSigner/CoSigner + MagnetarAccount
contracts/interfaces ISafe / ISafeTransactionGuard / IERC1271 / IERC4337 / IERC165
lib/forge-std vendored forge-std for `forge test`
tests Magnetar.t.sol (KAT + framing) + e2e.t.sol (signer/cosigner/account)
tests/kat.json real known-answer-test vector (proven vs the Go precompile)
Key Files
contracts/Magnetar.sol— the decomplected verifier library (frame + strict staticcall).tests/Magnetar.t.sol—test_CalldataFramingMatchesPrecompileABIpins the wire format.foundry.toml— solc 0.8.29, via-IR,fs_permissionsfortests/kat.json.
Design notes (Hickey-simple, decomplected)
- One concern per place. Magnetar.sol does ONLY calldata-framing + strict
staticcall. Key↔owner binding lives in the Safe wrappers; threshold/ownership
policy lives in the Safe itself. The
verifysignature never changes when a new scheme is added — each scheme is its own orthogonal slot. - Fail-closed. A valid result is ONLY: staticcall success AND
returndatasize == 32AND the returned word== 1. Revert, wrong-size return, zero word, or a missing precompile are allfalse. Mirrorsluxfi/safe/contracts/pq/PQVerifier.sol::_callStrict. - Raw wire, no selector. The precompile parses a raw packed layout; the Solidity must NOT prepend an ABI function selector.
Build & Test
forge build
forge test
Regenerating the KAT fixture
cd ../precompile
SDKROOT=$(xcrun --show-sdk-path) CGO_ENABLED=1 go run ./cmd/safekatdump > /tmp/safe_kats.json
SDKROOT=$(xcrun --show-sdk-path) CGO_ENABLED=1 go run ./cmd/safekatverify < /tmp/safe_kats.json # asserts each KAT verifies on the real precompile
Auto-generated for AI assistants. Mirrors the safe-frost template.