mirror of
https://github.com/luxfi/precompile.git
synced 2026-09-24 00:26:21 +00:00
Across the curve and hash precompiles: decode refuses a point that is not on its curve or not canonically encoded, rather than handing an off-curve point to an arithmetic routine; pasta's inversion no longer treats a multiple of p as invertible, where ModInverse returns nil and leaves the divisor untouched; compute refuses a quoted price wider than 256 bits instead of returning it modulo, and enforces readOnly; poseidon's sponge fee grows with its input; hqc reports an unwired backend as itself rather than as a verification failure; and sr25519 pins that the cgo and non-cgo verifiers name the same backend and agree, which is a consensus split when they do not. Every path deducts gas before it works, so no call is free. KAT vectors accompany each.
35 lines
1.1 KiB
Go
35 lines
1.1 KiB
Go
// Copyright (C) 2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
//go:build cgo
|
|
|
|
package sr25519
|
|
|
|
/*
|
|
#cgo CFLAGS: -I${SRCDIR}/donna -I${SRCDIR}/donna/ed25519-donna -DED25519_CUSTOMRANDOM -DED25519_CUSTOMHASH -DED25519_NO_INLINE_ASM -O3 -w
|
|
#include "sr25519.h"
|
|
*/
|
|
import "C"
|
|
import "unsafe"
|
|
|
|
// backend names the verifier this build linked. The two builds must return the
|
|
// same verdict for every input; see the parity corpus in the tests.
|
|
const backend = "sr25519-donna (cgo)"
|
|
|
|
// verifySR25519 verifies an sr25519 Schnorrkel signature using the
|
|
// sr25519-donna C library. Signing context is hardcoded to "substrate".
|
|
func verifySR25519(publicKey, signature, message []byte) bool {
|
|
if len(publicKey) != PublicKeySize || len(signature) != SignatureSize || len(message) == 0 {
|
|
return false
|
|
}
|
|
|
|
// sr25519_verify(signature, message, message_length, public_key) → bool
|
|
result := C.sr25519_verify(
|
|
(*C.uint8_t)(unsafe.Pointer(&signature[0])),
|
|
(*C.uint8_t)(unsafe.Pointer(&message[0])),
|
|
C.ulong(len(message)),
|
|
(*C.uint8_t)(unsafe.Pointer(&publicKey[0])),
|
|
)
|
|
return bool(result)
|
|
}
|