Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: a tool to craft provider registration signatures #533

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
module: [ bridge/standard, external/geth, oracle, p2p, tools/bidder-cli ]
module: [ bridge/standard, external/geth, oracle, p2p, tools/bidder-cli, tools/bls-signer ]

steps:
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
Expand Down
64 changes: 64 additions & 0 deletions tools/bls-signer/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
version: 1

project_name: bls-signer
dist: /tmp/dist/bls-signer

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
- arm64
dir: ./tools/bls-signature-creator
binary: "{{ .ProjectName }}"
flags:
- -v
- -trimpath

archives:
- format: tar.gz
name_template: >-
{{- .Binary }}_
{{- with index .Env "RELEASE_VERSION" -}}
{{ . }}
{{- else -}}
{{- if .IsSnapshot }}{{ .ShortCommit }}
{{- else }}{{ .Version }}
{{- end }}
{{- end -}}
{{- with index .Env "DIRTY_SUFFIX" -}}
{{ . }}
{{- end -}}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}
{{- end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
format_overrides:
- goos: windows
format: zip

checksum:
name_template: >-
{{ .ProjectName }}_
{{- with index .Env "RELEASE_VERSION" -}}
{{ . }}
{{- else -}}
{{- if .IsSnapshot }}{{ .ShortCommit }}
{{- else }}{{ .Version }}
{{- end }}
{{- end -}}
{{- with index .Env "DIRTY_SUFFIX" -}}
{{ . }}
{{- end -}}
_checksums.txt
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
26 changes: 26 additions & 0 deletions tools/bls-signer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# BLS Signer

Tool for signing payloads using BLS keys. It takes a BLS private key and payload as input and generates a BLS signature that can be used for provider registration and other signing operations.

## Installation

Download the latest release binary for your platform from the [releases page](../../releases).

The binary is named `bls-signer` and is available for Linux x86_64 and arm64 architectures.

## Usage
The tool requires:
- A BLS private key (provided as a hex encoded string with optional 0x prefix) via the `--private-key` flag
- A payload (provided as a hex string with optional 0x prefix) via the `--payload` flag

The tool will log:
- The payload that was provided
- The hex-encoded BLS public key derived from your private key
- The hex-encoded BLS signature

The logged public key and signature should be used when making a staking request to register as a provider.

Example usage:
```
bls-signer --private-key 0x30B67395EDA0B03F5E400498690FB8D7CF7BAC53132F89CCED0D65559DB065C9 --payload 0xdeadbeef
```
90 changes: 90 additions & 0 deletions tools/bls-signer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package main

import (
"encoding/hex"
"fmt"
"os"
"strings"

"github.com/cloudflare/circl/sign/bls"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"

"github.com/urfave/cli/v2"
)

var (
optionPrivateKey = &cli.StringFlag{
Name: "private-key",
Usage: "BLS private key as hex encoded string (with optional 0x prefix). Must be a valid hex string representing a BLS private key.",
Required: true,
}

optionPayload = &cli.StringFlag{
Name: "payload",
Usage: "Payload as hex string (with optional 0x prefix)",
Required: true,
}
)

func main() {
app := &cli.App{
Name: "bls-signer",
Usage: "Create BLS signatures",
Flags: []cli.Flag{
optionPrivateKey,
optionPayload,
},
Action: run,
}

if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

func run(c *cli.Context) error {
blsPrivKeyHex := c.String("private-key")
payload := c.String("payload")

// Strip 0x prefix if present
blsPrivKeyHex = strings.TrimPrefix(blsPrivKeyHex, "0x")

// Validate hex string
privKeyBytes, err := hexutil.Decode("0x" + blsPrivKeyHex)
if err != nil {
return fmt.Errorf("invalid private key hex string: %v", err)
}

// Create BLS signature
hashedMessage := crypto.Keccak256(common.HexToAddress(payload).Bytes())
privateKey := new(bls.PrivateKey[bls.G1])
if err := privateKey.UnmarshalBinary(privKeyBytes); err != nil {
fmt.Fprintf(c.App.Writer, "Failed to unmarshal private key: %v\n", err)
return err
}

publicKey := privateKey.PublicKey()
signature := bls.Sign(privateKey, hashedMessage)

// Verify the signature
if !bls.Verify(publicKey, hashedMessage, signature) {
fmt.Fprintln(c.App.Writer, "Failed to verify generated BLS signature")
return fmt.Errorf("failed to verify generated BLS signature")
}

pubkeyb, err := publicKey.MarshalBinary()
if err != nil {
fmt.Fprintf(c.App.Writer, "Failed to marshal public key: %v\n", err)
return err
}

fmt.Fprintf(c.App.Writer, "Generated BLS signature:\n")
fmt.Fprintf(c.App.Writer, "Payload: %s\n", payload)
fmt.Fprintf(c.App.Writer, "Public key: %s\n", hex.EncodeToString(pubkeyb))
fmt.Fprintf(c.App.Writer, "Signature: %s\n", hex.EncodeToString(signature))

return nil
}
1 change: 1 addition & 0 deletions tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23
toolchain go1.23.0

require (
github.com/cloudflare/circl v1.5.0
github.com/ethereum/go-ethereum v1.14.11
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/primev/mev-commit/contracts-abi v0.0.1
Expand Down
2 changes: 2 additions & 0 deletions tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk=
github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cloudflare/circl v1.5.0 h1:hxIWksrX6XN5a1L2TI/h53AGPhNHoUBo+TD1ms9+pys=
github.com/cloudflare/circl v1.5.0/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
github.com/cockroachdb/errors v1.11.3 h1:5bA+k2Y6r+oz/6Z/RFlNeVCesGARKuC6YymtcDrbC/I=
github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8=
github.com/cockroachdb/fifo v0.0.0-20240616162244-4768e80dfb9a h1:f52TdbU4D5nozMAhO9TvTJ2ZMCXtN4VIAmfrrZ0JXQ4=
Expand Down
Loading