pedersen

package
v0.0.0-...-ee1bab5 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 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.

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

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

Overview

Package pedersen Copyright 2023 Oleg Fomenko. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Package pedersen Copyright 2023 Oleg Fomenko. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Package pedersen Copyright 2023 Oleg Fomenko. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

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 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)

Jump to

Keyboard shortcuts

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