Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 36 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
GO_MODULES := . driver/gurvy/compat

.PHONY: all
all: checks unit-tests unit-tests-race

Expand All @@ -9,11 +11,19 @@ checks: check-deps

.PHONY: unit-tests
unit-tests:
@go test -timeout 480s -cover $(shell go list ./...)
@echo "Unit-testing Go modules..."
@for dir in $(GO_MODULES); do \
echo " Unit-testing module: $$dir"; \
(cd $$dir && go test -cover ./...); \
done

.PHONY: unit-tests-race
unit-tests-race:
@export GORACE=history_size=7; go test -timeout 960s -race -cover $(shell go list ./...)
@echo "Unit-testing with race Go modules..."
@for dir in $(GO_MODULES); do \
echo " Unit-testing with race module: $$dir"; \
(export GORACE=history_size=7 && cd $$dir && go test -race -cover ./...); \
done

.PHONY: perf
perf:
Expand All @@ -27,22 +37,40 @@ check-deps:
.PHONY: lint
# run various linters
lint:
@echo "Running Go Linters..."
golangci-lint run --color=always --timeout=4m
@echo "Running Go linters..."
@for dir in $(GO_MODULES); do \
echo " Running Go linters on module: $$dir"; \
(cd $$dir && golangci-lint run --color=always --timeout=4m); \
done

.PHONY: lint-auto-fix
# run linters with auto-fix
lint-auto-fix:
@echo "Running Go Linters with auto-fix..."
golangci-lint run --color=always --timeout=4m --fix
@echo "Running Go linters with auto-fix..."
@for dir in $(GO_MODULES); do \
echo " Running Go linters with auto-fix on module: $$dir"; \
(cd $$dir && golangci-lint run --color=always --timeout=4m --fix); \
done

.PHONY: install-linter-tool
# install golangci-lint
install-linter-tool:
@echo "Installing golangci Linter"
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(HOME)/go/bin v2.10.1
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(HOME)/go/bin v2.12.2

.PHONY: fmt
fmt: ## Run gofmt on the entire project
@echo "Running gofmt..."
@gofmt -l -s -w .
@for dir in $(GO_MODULES); do \
echo " Formatting module: $$dir"; \
(cd $$dir && find . -path './.git' -prune -o -name '*.go' -print | xargs gofmt -l -s -w); \
done

.PHONY: tidy
# tidy up go modules
tidy:
@echo "Tidying Go modules..."
@for dir in $(GO_MODULES); do \
echo " Tidying module: $$dir"; \
(cd $$dir && go mod tidy); \
done
52 changes: 39 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The library abstracts the complexity of pairing operations while providing flexi
## Features

- **Multiple Curve Support**: FP256BN, BN254, BLS12-381, BLS12-377, and BBS+ variants
- **Pluggable Backends**: Support for AMCL, Gurvy, and Kilic implementations
- **Pluggable Backends**: Support for AMCL and Gurvy implementations
- **Type-Safe API**: Strongly-typed group elements (G1, G2, Gt, Zr)
- **Efficient Operations**: Optimized pairing computations and multi-scalar multiplications
- **Serialization**: Support for both compressed and uncompressed point representations
Expand Down Expand Up @@ -76,10 +76,10 @@ func main() {
| `FP256BN_AMCL` | 256-bit Barreto-Naehrig curve | AMCL | General-purpose pairing operations |
| `FP256BN_AMCL_MIRACL` | 256-bit BN curve (MIRACL variant) | AMCL | Legacy compatibility |
| `BN254` | 254-bit Barreto-Naehrig curve | Gurvy | High-performance applications |
| `BLS12_381` | BLS12-381 curve | Kilic | Modern protocols, BLS signatures |
| `BLS12_381` | BLS12-381 curve (deprecated) | None | Legacy slot |
| `BLS12_381_GURVY` | BLS12-381 curve | Gurvy | Performance-optimized BLS12-381 |
| `BLS12_377_GURVY` | BLS12-377 curve | Gurvy | Recursive proof systems |
| `BLS12_381_BBS` | BLS12-381 for BBS+ signatures | Kilic | Anonymous credentials |
| `BLS12_381_BBS` | BLS12-381 for BBS+ signatures | Gurvy | Anonymous credentials |
| `BLS12_381_BBS_GURVY` | BLS12-381 for BBS+ signatures | Gurvy | High-performance BBS+ |

### Choosing a Curve
Expand Down Expand Up @@ -204,7 +204,7 @@ fmt.Printf("Signature: %x\n", signature.Compressed())
### Example 4: Multi-Scalar Multiplication

```go
curve := math.Curves[math.BLS12_381]
curve := math.Curves[math.BLS12_381_GURVY]

// Create multiple points and scalars
points := []*math.G1{
Expand Down Expand Up @@ -243,11 +243,11 @@ fmt.Printf("Multi-scalar multiplication result: %s\n", result.String())
│ Curve, G1, G2, Gt, Zr interfaces │
└─────────────────┬───────────────────┘
┌──────────────────┐
┌──────┐ ┌──────┐ ┌──────┐
│ AMCL │ │Gurvy │ │Kilic
└──────┘ └──────┘ └──────┘
┌──────────────────┐
┌──────┐ ┌──────┐
│ AMCL │ │Gurvy
└──────┘ └──────┘
```

This design allows:
Expand All @@ -258,8 +258,35 @@ This design allows:
### Backend Implementations

- **AMCL (Apache Milagro Crypto Library)**: Mature, well-tested implementation
- **Gurvy**: High-performance Go-native implementation with assembly optimizations
- **Kilic**: Optimized BLS12-381 implementation with focus on BLS signatures
- **Gurvy**: High-performance Go-native implementation using [gnark-crypto](https://github.com/ConsenSys/gnark-crypto)

### Gurvy BLS12-381 hash-to-curve

The `driver/gurvy` package contains a self-contained BLS12-381 hash-to-curve
pipeline (`Hash`, `SwuMapG1BE`, `HashToG1GenericBESwu`) that is byte-for-byte
compatible with the algorithm originally implemented in `kilic/bls12-381`.

**Dependencies**: the main module has no runtime dependency on
`kilic/bls12-381`. The kilic library was removed from `go.mod` once the
reimplementation was validated.

**Test vectors**: `driver/gurvy/compat_test.go` uses self-contained
known-answer vectors and property tests (gnark-crypto as the sole oracle).
Vectors can be regenerated by temporarily removing the `//go:build ignore`
constraint from `driver/gurvy/gen_vectors_test.go` and running:

```bash
cd driver/gurvy && go test -run TestGenVectors -v
```

**Oracle tests**: `driver/gurvy/compat/` is a standalone Go module
(`github.com/IBM/mathlib/driver/gurvy/compat`) that retains the original
kilic-vs-gurvy oracle tests. These are deliberately isolated so that the kilic
dependency does not appear in the main module graph. Run them with:

```bash
cd driver/gurvy/compat && go test ./...
```

## Performance Considerations

Expand Down Expand Up @@ -324,5 +351,4 @@ This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENS

This library builds upon the excellent work of:
- Apache Milagro Crypto Library (AMCL)
- ConsenSys Gurvy library
- Kilic BLS12-381 implementation
- ConsenSys Gurvy library
Loading
Loading