core

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: May 29, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FIELD_MODULUS, _ = new(big.Int).SetString("30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47", 16)
	GROUP_MODULUS, _ = new(big.Int).SetString("30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001", 16)

	B_MAX uint = 4294967295
)
View Source
var (
	BASEPOS = 64
)

Functions

func Burn added in v0.0.2

func Burn(y string, bTransfer uint64, u string, proof string) string

func BytePadding

func BytePadding(data []byte, length int) []byte

func BytesCombine

func BytesCombine(pBytes ...[]byte) []byte

func Fund added in v0.0.2

func Fund(y string, b uint64) string

func Hash

func Hash(str string) *ebigint.NBigInt

func PaddingString

func PaddingString(in string, padding int) string

func ProveBurn

func ProveBurn(statement BurnStatement, witness BurnWitness) string

func ProveTransfer

func ProveTransfer(statement TransferStatement, witness TransferWitness) string

func ReadBalance

func ReadBalance(CL, CR types.Point, x *ebigint.NBigInt) int

func Register added in v0.0.2

func Register(y string, c string, s string) string

func Reverse

func Reverse(s []string) []string

func Sign

func Sign(address []byte, keypair Account) (*ebigint.NBigInt, *ebigint.NBigInt, error)

func SignWithRandom

func SignWithRandom(address []byte, keypair Account, k *ebigint.NBigInt) (*ebigint.NBigInt, *ebigint.NBigInt, error)

just for test with special k.

func SimulateAccounts added in v0.0.5

func SimulateAccounts(y string, epoch uint64) string

func Transfer added in v0.0.2

func Transfer(c string, d string, y string, u string, proof string) string

Types

type ABI_Bytes32

type ABI_Bytes32 [32]byte

type ABI_Bytes32_2

type ABI_Bytes32_2 [2][32]byte

type ABI_Bytes32_2S

type ABI_Bytes32_2S [][2][32]byte

type Account

type Account struct {
	X *ebigint.NBigInt `json:"x"`
	Y types.Point      `json:"y"`
}

func CreateAccount

func CreateAccount() Account

func CreateAccountWithX

func CreateAccountWithX(x *ebigint.NBigInt) Account

func (Account) MarshalJSON

func (a Account) MarshalJSON() ([]byte, error)

func (Account) String

func (a Account) String() string

func (*Account) UnmarshalJSON

func (a *Account) UnmarshalJSON(input []byte) error

type BN128

type BN128 struct {
	G1 *bn256.G1
	// contains filtered or unexported fields
}

func NewBN128

func NewBN128() *BN128

func (*BN128) B_MAX

func (b *BN128) B_MAX() uint

func (*BN128) Bytes

func (b *BN128) Bytes(i *big.Int) string

func (*BN128) CurveG

func (b *BN128) CurveG() Point

func (*BN128) CurveRed

func (b *BN128) CurveRed() *ebigint.Red

func (*BN128) Fq

func (b *BN128) Fq() bn256.Fq

func (*BN128) P

func (b *BN128) P() *ebigint.Red

func (*BN128) Q

func (b *BN128) Q() *ebigint.Red

func (*BN128) RandomScalar

func (b *BN128) RandomScalar() *ebigint.NBigInt

func (*BN128) Representation

func (b *BN128) Representation(p Point) string

func (*BN128) Serialize

func (b *BN128) Serialize(p Point) types.Point

func (*BN128) SetSpecialRandom added in v0.0.2

func (b *BN128) SetSpecialRandom(r *ebigint.NBigInt)

for test.

func (*BN128) UnSerialize

func (b *BN128) UnSerialize(pubkey types.Point) Point

func (*BN128) Zero

func (b *BN128) Zero() Point

type BurnProof

type BurnProof struct {
	BA Point
	BS Point
	// contains filtered or unexported fields
}

func (BurnProof) Serialize

func (z BurnProof) Serialize() string

type BurnProver

type BurnProver struct {
	// contains filtered or unexported fields
}

func NewBurnProver

func NewBurnProver() BurnProver

func (BurnProver) GenerateProof

func (burn BurnProver) GenerateProof(istatement BurnStatement, iwitness BurnWitness) *BurnProof

type BurnStatement

type BurnStatement struct {
	CLn    types.Point
	CRn    types.Point
	Y      types.Point
	Epoch  int
	Sender string
}

type BurnWitness

type BurnWitness struct {
	SK    string // keypair['x'], bigInt hex string
	BDiff int
}

type Convolver

type Convolver struct {
	// contains filtered or unexported fields
}

func NewConvolver

func NewConvolver() *Convolver

func (*Convolver) Convolution_Point

func (c *Convolver) Convolution_Point(exponent *FieldVector, base *GeneratorVector) *GeneratorVector

func (*Convolver) Convolution_Scalar

func (c *Convolver) Convolution_Scalar(exponent *FieldVector, base *FieldVector) *FieldVector

func (*Convolver) FFT_Point

func (c *Convolver) FFT_Point(input *GeneratorVector, inverse bool) *GeneratorVector

func (*Convolver) FFT_Scalar

func (c *Convolver) FFT_Scalar(input *FieldVector, inverse bool) *FieldVector

type ETH_ADDR

type ETH_ADDR ethcommon.Address

type FieldVector

type FieldVector struct {
	// contains filtered or unexported fields
}

func NewFieldVector

func NewFieldVector(vector []*ebigint.NBigInt) *FieldVector

func (*FieldVector) Add

func (f *FieldVector) Add(other *FieldVector) *FieldVector

func (*FieldVector) Concat

func (f *FieldVector) Concat(other *FieldVector) *FieldVector

func (*FieldVector) Extract

func (f *FieldVector) Extract(parity int) *FieldVector

func (*FieldVector) Flip

func (f *FieldVector) Flip() *FieldVector

func (*FieldVector) GetVector

func (f *FieldVector) GetVector() []*ebigint.NBigInt

func (*FieldVector) Hadamard

func (f *FieldVector) Hadamard(other *FieldVector) *FieldVector

func (*FieldVector) InnerProduct

func (f *FieldVector) InnerProduct(other *FieldVector) *ebigint.NBigInt

func (*FieldVector) Invert

func (f *FieldVector) Invert() *FieldVector

func (*FieldVector) Length

func (f *FieldVector) Length() int

func (*FieldVector) Negate

func (f *FieldVector) Negate() *FieldVector

func (*FieldVector) Plus

func (f *FieldVector) Plus(constant *ebigint.NBigInt) *FieldVector

func (*FieldVector) Slice

func (f *FieldVector) Slice(begin, end int) *FieldVector

func (*FieldVector) String added in v0.0.2

func (f *FieldVector) String() string

func (*FieldVector) Subtract

func (f *FieldVector) Subtract(other *FieldVector) *FieldVector

func (*FieldVector) Sum

func (f *FieldVector) Sum() *ebigint.NBigInt

func (*FieldVector) Times

func (f *FieldVector) Times(constant *ebigint.NBigInt) *FieldVector

type FieldVectorPolynomial

type FieldVectorPolynomial struct {
	// contains filtered or unexported fields
}

func NewFieldVectorPolynomial

func NewFieldVectorPolynomial(coefficients ...*FieldVector) *FieldVectorPolynomial

func (*FieldVectorPolynomial) Evaluate

func (*FieldVectorPolynomial) GetCoefficients

func (f *FieldVectorPolynomial) GetCoefficients() []*FieldVector

func (*FieldVectorPolynomial) InnerProduct

func (f *FieldVectorPolynomial) InnerProduct(other *FieldVectorPolynomial) []*ebigint.NBigInt

type GeneratorParams

type GeneratorParams struct {
	// contains filtered or unexported fields
}

func NewGeneratorParams

func NewGeneratorParams(hi interface{}, gs, hs *GeneratorVector) *GeneratorParams

func (*GeneratorParams) Commit

func (g *GeneratorParams) Commit(blinding *ebigint.NBigInt, gExp, hExp *FieldVector) Point

func (GeneratorParams) GetG

func (g GeneratorParams) GetG() Point

func (GeneratorParams) GetGS

func (g GeneratorParams) GetGS() *GeneratorVector

func (GeneratorParams) GetH

func (g GeneratorParams) GetH() Point

func (GeneratorParams) GetHS

func (g GeneratorParams) GetHS() *GeneratorVector

type GeneratorVector

type GeneratorVector struct {
	// contains filtered or unexported fields
}

func NewGeneratorVector

func NewGeneratorVector(Innards []Point) *GeneratorVector

func (*GeneratorVector) Add

func (*GeneratorVector) Commit

func (g *GeneratorVector) Commit(exponents *FieldVector) Point

func (*GeneratorVector) Concat

func (g *GeneratorVector) Concat(other *GeneratorVector) *GeneratorVector

func (*GeneratorVector) Extract

func (g *GeneratorVector) Extract(parity int) *GeneratorVector

func (*GeneratorVector) GetVector

func (g *GeneratorVector) GetVector() []Point

func (*GeneratorVector) Hadamard

func (g *GeneratorVector) Hadamard(exponents *FieldVector) *GeneratorVector

func (*GeneratorVector) Length

func (g *GeneratorVector) Length() int

func (*GeneratorVector) Negate

func (g *GeneratorVector) Negate() *GeneratorVector

func (*GeneratorVector) Slice

func (g *GeneratorVector) Slice(begin, end int) *GeneratorVector

func (*GeneratorVector) String added in v0.0.2

func (g *GeneratorVector) String() string

func (*GeneratorVector) Sum

func (g *GeneratorVector) Sum() Point

func (*GeneratorVector) Times

func (g *GeneratorVector) Times(constant *ebigint.NBigInt) *GeneratorVector

type InnerProductProof

type InnerProductProof struct {
	L []Point
	R []Point
	A *ebigint.NBigInt
	B *ebigint.NBigInt
}

func (*InnerProductProof) Serialize

func (i *InnerProductProof) Serialize() string

type InnerProductProver

type InnerProductProver struct {
}

func (InnerProductProver) GenerateProof

type InnerProduct_statement

type InnerProduct_statement struct {
	PrimeBase *GeneratorParams
	P         Point
}

type InnerProduct_witness

type InnerProduct_witness struct {
	L *FieldVector
	R *FieldVector
}

type PList

type PList struct {
	// contains filtered or unexported fields
}

func NewPList

func NewPList() *PList

func (*PList) Append

func (p *PList) Append(d []*ebigint.NBigInt)

func (*PList) Len

func (p *PList) Len() int

type ParseSimulateAccountsResponse added in v0.0.6

type ParseSimulateAccountsResponse struct {
	Accounts [][2]types.Point `json:"accounts"`
}

func ParseSimulateAccounts added in v0.0.6

func ParseSimulateAccounts(data string) (*ParseSimulateAccountsResponse, error)

type PedersenCommitment

type PedersenCommitment struct {
	// contains filtered or unexported fields
}

func NewPedersenCommitment

func NewPedersenCommitment(params GeneratorParams, coefficient *ebigint.NBigInt, b *ebigint.NBigInt) *PedersenCommitment

func (PedersenCommitment) Add

func (PedersenCommitment) Commit

func (pc PedersenCommitment) Commit() Point

func (PedersenCommitment) GetR

func (pc PedersenCommitment) GetR() *ebigint.NBigInt

func (PedersenCommitment) GetX

func (pc PedersenCommitment) GetX() *ebigint.NBigInt

func (PedersenCommitment) Times

type Point

type Point struct {
	// contains filtered or unexported fields
}

func GEpoch

func GEpoch(epoch int) Point

func MapInto

func MapInto(seed string) Point

utils.mapInto = (seed) => { // seed is flattened 0x + hex string

    var seed_red = new BN(seed.slice(2), 16).toRed(bn128.p);
    var p_1_4 = bn128.curve.p.add(new BN(1)).div(new BN(4));
    while (true) {
        var y_squared = seed_red.redPow(new BN(3)).redAdd(new BN(3).toRed(bn128.p));
        var y = y_squared.redPow(p_1_4);
        if (y.redPow(new BN(2)).eq(y_squared)) {
            return bn128.curve.point(seed_red.fromRed(), y.fromRed());
        }
        seed_red.redIAdd(new BN(1).toRed(bn128.p));
    }
};

seed is flattened 0x + hex string

func NewPoint

func NewPoint(d1, d2 *big.Int) Point

func U

func U(epoch int, x *ebigint.NBigInt) Point

func (Point) Add

func (p Point) Add(o Point) Point

func (Point) Equal

func (p Point) Equal(o Point) bool

func (Point) Mul

func (p Point) Mul(o *ebigint.NBigInt) Point

func (Point) Neg

func (p Point) Neg() Point

func (Point) String

func (p Point) String() string

func (Point) XY

func (p Point) XY() (*big.Int, *big.Int)

type PolyCommitment

type PolyCommitment struct {
	// contains filtered or unexported fields
}

func NewPolyCommitment

func NewPolyCommitment(params GeneratorParams, coefficients []*ebigint.NBigInt) *PolyCommitment

func (*PolyCommitment) Evaluate

func (*PolyCommitment) GetCommitments

func (pc *PolyCommitment) GetCommitments() []Point

type Polynomial

type Polynomial struct {
	// contains filtered or unexported fields
}

func NewPolynomial

func NewPolynomial(coefficients []*ebigint.NBigInt) *Polynomial

func (*Polynomial) Mul

func (p *Polynomial) Mul(other *Polynomial) *Polynomial

type TransferStatement

type TransferStatement struct {
	CLn   []types.Point
	CRn   []types.Point
	C     []types.Point
	D     types.Point
	Y     []types.Point
	Epoch int
}

func (*TransferStatement) Content added in v0.0.2

func (t *TransferStatement) Content()

type TransferWitness

type TransferWitness struct {
	BTransfer int
	BDiff     int
	Index     []int
	SK        string // keypair['x'], bigInt hex string
	R         string // random scalar, bigInt hex string
}

func (*TransferWitness) Content added in v0.0.2

func (t *TransferWitness) Content()

type ZetherProof

type ZetherProof struct {
	BA Point
	BS Point
	A  Point
	B  Point

	CLnG []Point
	CRnG []Point
	C_0G []Point
	DG   []Point

	C_XG []Point
	// contains filtered or unexported fields
}

func (ZetherProof) Serialize

func (z ZetherProof) Serialize() string

type ZetherProver

type ZetherProver struct {
	// contains filtered or unexported fields
}

func NewZetherProver

func NewZetherProver() ZetherProver

func (ZetherProver) GenerateProof

func (this ZetherProver) GenerateProof(istatement TransferStatement, iwitness TransferWitness) *ZetherProof

func (ZetherProver) RecursivePolynomials

func (this ZetherProver) RecursivePolynomials(plist *PList, accum *Polynomial,
	a []*ebigint.NBigInt, b []*ebigint.NBigInt)

Directories

Path Synopsis
Package bn256 implements a particular bilinear group at the 128-bit security level.
Package bn256 implements a particular bilinear group at the 128-bit security level.

Jump to

Keyboard shortcuts

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