Files
gpu/ecrecover_cgo.go
zeekayandHanzo Dev fff0c95c60 cgo: link substrate via pkg-config: luxgpu (was lux-gpu)
The substrate GPU library's pkg-config package was renamed lux-gpu ->
luxgpu so the hyphenated `lux-gpu` name can belong to the DEX matcher
(liblux_gpu), which has a conflicting lux_gpu_backend_name ABI. Update
the four substrate cgo bindings to the substrate's canonical name.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-22 09:29:55 -07:00

51 lines
1.1 KiB
Go

//go:build cgo
package gpu
/*
#cgo pkg-config: luxgpu
#include <lux/gpu.h>
#include <string.h>
*/
import "C"
import "unsafe"
// BatchEcrecover recovers Ethereum addresses from a batch of signatures
// using GPU-accelerated secp256k1 ecrecover.
func BatchEcrecover(sigs []Signature) ([]EcrecoverResult, error) {
n := len(sigs)
if n == 0 {
return nil, nil
}
gpu := getGPU()
// Pack into C structs
inputs := make([]C.LuxEcrecoverInput, n)
outputs := make([]C.LuxEcrecoverOutput, n)
for i := range sigs {
C.memcpy(unsafe.Pointer(&inputs[i].r[0]), unsafe.Pointer(&sigs[i].R[0]), 32)
C.memcpy(unsafe.Pointer(&inputs[i].s[0]), unsafe.Pointer(&sigs[i].S[0]), 32)
inputs[i].v = C.uint8_t(sigs[i].V)
C.memcpy(unsafe.Pointer(&inputs[i].msg_hash[0]), unsafe.Pointer(&sigs[i].MsgHash[0]), 32)
}
ret := C.lux_gpu_ecrecover_batch(
gpu,
&inputs[0],
&outputs[0],
C.size_t(n),
)
if err := zkError(ret); err != nil {
return nil, err
}
results := make([]EcrecoverResult, n)
for i := range outputs {
copy(results[i].Address[:], C.GoBytes(unsafe.Pointer(&outputs[i].address[0]), 20))
results[i].Valid = outputs[i].valid != 0
}
return results, nil
}