back_maxwell_rangeproof

package module
v0.0.0-...-b76f929 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2023 License: MIT Imports: 7 Imported by: 0

README

Back-Maxwell range proof for Pedersen Commitments on Go

Example implementation of Back-Maxwell Rangeproof on Go for creating the Pedersen commitment with corresponding proof that committed value lies in [0..2^n-1] range.
The implementation uses Ethereum bn128 G1 curve to produce commitments and proofs.

Use only for educational reasons.

DO NOT USE IN PRODUCTION.

Signing scheme Signing scheme

Usage

Explore main_test.go TestPedersenCommitment with example of usage.

Note, that there are the following values defined in global space to be changed on your choice:

var G *bn256.G1
var H *bn256.G1

// Hash function that should return the value in Curve.N field
var Hash func(...[]byte) *big.Int = defaultHash

Signature (Proof of ownership)

Explore main_test.go TestSignatureForCommitments with example of signing the Pederssn commitment.

It uses the scheme from Simple Schnorr Signature with Pedersen Commitment as Key article.

Signing scheme

For the decentralized systems hash message expected to be the hash of transaction outputs.

Schnorr Signature

Explore main_test.go TestSchnorrSignatureAggregation with an example of Schnorr signature. It can be useful to sign the resulting C=C1-C2 commitment in transactions.

It uses the scheme from Schnorr Signature article.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Hash func(...[]byte) *big.Int = defaultHash

Hash function that should return the value in Curve.N field

Functions

func Add

func Add(a, b *bn256.G1) *bn256.G1

func PedersenCommitment

func PedersenCommitment(a, r *big.Int) *bn256.G1

PedersenCommitment creates *bn256.G1 with pedersen commitment aH + rG

func ScalarMul

func ScalarMul(p *bn256.G1, k *big.Int) *bn256.G1

func Sub

func Sub(a, b *bn256.G1) *bn256.G1

func Verify

func Verify(signature Signature, C *bn256.G1) error

func VerifyPedersenCommitment

func VerifyPedersenCommitment(C *bn256.G1, proof Proof) error

VerifyPedersenCommitment - verifies proof that C commitment commits the value in [0..2^n-1]

func VerifySchnorr

func VerifySchnorr(sig SchnorrSignature, publicKey *bn256.G1, m *big.Int) error

func X

func X(p *bn256.G1) *big.Int

func Y

func Y(p *bn256.G1) *big.Int

Types

type Proof

type Proof struct {
	E0 *big.Int
	C  []*bn256.G1
	S  []*big.Int
	N  int
}

func CreatePedersenCommitment

func CreatePedersenCommitment(val uint64, n int) (Proof, *bn256.G1, *big.Int, error)

CreatePedersenCommitment - creates Pedersen commitment for given val, and generates proof that given val lies in [0..2^n-1]. Returns Proof, generated commitment and private key in case of success generation.

type SchnorrSignature

type SchnorrSignature struct {
	R *bn256.G1
	S *big.Int
}

func SignSchnorr

func SignSchnorr(prv *big.Int, publicKey *bn256.G1, m *big.Int) (SchnorrSignature, error)

type Signature

type Signature struct {
	R *bn256.G1
	U *big.Int
	V *big.Int
	M *big.Int
}

func Sign

func Sign(r *big.Int, a *big.Int, m *big.Int, C *bn256.G1) (Signature, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL