accumulator

package
v0.0.0-...-e663500 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// RSABitLength denotes the test bit length of RSA
	RSABitLength = 2048

	// N2048String stores the modulus N for RSA accumulator, can only be used for testing purposes. DO NOT use in production.
	N2048String = "" /* 617-byte string literal not displayed */
	// G2048String stores the generator g for RSA accumulator, can only be used for testing purposes. DO NOT use in production.
	G2048String = "" /* 616-byte string literal not displayed */
	// H2048String stores the generator h for RSA accumulator, can only be used for testing purposes. DO NOT use in production.
	H2048String = "" /* 616-byte string literal not displayed */

	// HashToPrimeFromSha256 is a prime number generated from Sha256
	HashToPrimeFromSha256 = iota
	// DIHashFromPoseidon is a division intractable Hash output
	DIHashFromPoseidon
	// PString stores P, generated by RandomSetupForUniversalHash
	PString = "90906479945022450706608444255860322124872501190254782434061962615363326054763"
	// AString stores P, generated by RandomSetupForUniversalHash
	AString = "88002637055063747320581957665708636390837016772007025523219521174143026565170"
	// BString stores P, generated by RandomSetupForUniversalHash
	BString = "13294476384846260317153427213550716038030529474006293344879303435820149470959"
)

Variables

View Source
var (

	// Min1024 is set to a 1024 bits number with most significant bit 1 and other bits 0
	// This can speed up the calculation
	// Min1024 is set to 2^1023
	Min1024 = big.NewInt(0)
	// Min2048 is set to 2^2047
	Min2048 = big.NewInt(0)
	// P is generated by RandomSetupForUniversalHash for UniversalHash
	P = big.NewInt(0)
	// A is generated by RandomSetupForUniversalHash for UniversalHash
	A = big.NewInt(0)
	// B is generated by RandomSetupForUniversalHash for UniversalHash
	B = big.NewInt(0)
)

Functions

func AccAndProve

func AccAndProve(set []string, encodeType EncodeType, setup *Setup) (*big.Int, []*big.Int)

AccAndProve generates the accumulator with all the memberships precomputed

func AccAndProveIter

func AccAndProveIter(set []string, encodeType EncodeType, setup *Setup) (*big.Int, []*big.Int)

AccAndProveIter iteratively generates the accumulator with all the memberships precomputed

func AccAndProveIterParallel

func AccAndProveIterParallel(set []string, encodeType EncodeType,
	setup *Setup) (*big.Int, []*big.Int)

AccAndProveIterParallel iteratively and concurrently generates the accumulator with all the memberships precomputed

func AccAndProveParallel

func AccAndProveParallel(set []string, encodeType EncodeType, setup *Setup) (*big.Int, []*big.Int)

AccAndProveParallel recursively generates the accumulator with all the memberships precomputed in parallel

func AccumulateNew

func AccumulateNew(g, power, N *big.Int) *big.Int

AccumulateNew calculates g^{power} mod N

func CommonBits

func CommonBits(a, b big.Word) big.Word

CommonBits calculates the greatest common binaries of a and b when they are uint.

func DIHashPoseidon

func DIHashPoseidon(input ...*fr.Element) *big.Int

DIHashPoseidon generates DI hash with Poseidon hash

func ElementFromBigInt

func ElementFromBigInt(v *big.Int) *fr.Element

ElementFromBigInt returns an element in BN256 generated from BigInt

func ElementFromString

func ElementFromString(v string) *fr.Element

ElementFromString returns an element in BN256 generated from string of decimal integers

func ElementFromUint32

func ElementFromUint32(v uint32) *fr.Element

ElementFromUint32 returns an element in BN256 generated from uint32

func GCB

func GCB(a, b *big.Int) *big.Int

GCB calculates the greatest common binaries of a and b. For example, if a = 1011 (binary) and b = 1100, the return will be of 1000(binary)

func GenBenchSet

func GenBenchSet(num int) []string

GenBenchSet generate one set where every element is different

func GenRandomizer

func GenRandomizer() *big.Int

GenRandomizer outputs random number uniformly between 0 to 2^2047

func GenRepresentatives

func GenRepresentatives(set []string, encodeType EncodeType) []*big.Int

GenRepresentatives generates different representatives that can be inputted into RSA accumulator

func GenerateG

func GenerateG()

GenerateG generates a generator for a hidden order group randomly

func HashToPrime

func HashToPrime(input []byte) *big.Int

HashToPrime takes the input into Sha256 and take the hash output to input repeatedly until we hit a prime number

func ManualBench

func ManualBench(testSetSize int)

ManualBench is used for manual benchmark. Because the running time can be long, the golang benchmark may not work

func ManualBenchIter

func ManualBenchIter(testSetSize int)

ManualBenchIter is used for manual benchmark. Because the running time can be long, the golang benchmark may not work

func ManualBenchIterParallel

func ManualBenchIterParallel(testSetSize int)

ManualBenchIterParallel is used for manual benchmark. Because the running time can be long, the golang benchmark may not work

func ManualBenchParallel

func ManualBenchParallel(testSetSize int)

ManualBenchParallel is used for manual benchmark. Because the running time can be long, the golang benchmark may not work

func ManualBenchZKAcc

func ManualBenchZKAcc(testSetSize int)

ManualBenchZKAcc is used for manual benchmark. Because the running time can be long, the golang benchmark may not work

func PoseidonAndDIHash

func PoseidonAndDIHash(input ...*fr.Element) (*fr.Element, *big.Int)

PoseidonAndDIHash returns the Poseidon Hash result together with DI hash result

func PoseidonWith2Inputs

func PoseidonWith2Inputs(inputs []*big.Int) *big.Int

PoseidonWith2Inputs inputs 2 big.Int and generate a Poseidon hash result.

func ProveMembership

func ProveMembership(base, N *big.Int, set []*big.Int) []*big.Int

ProveMembership uses divide-and-conquer method to pre-compute the all membership proofs in time O(nlog(n))

func ProveMembershipIter

func ProveMembershipIter(base big.Int, N *big.Int, set []*big.Int) []*big.Int

ProveMembershipIter uses divide-and-conquer method to pre-compute the all membership proofs iteratively

func ProveMembershipIterParallel

func ProveMembershipIterParallel(base big.Int, N *big.Int, set []*big.Int) []*big.Int

ProveMembershipIterParallel uses divide-and-conquer method to pre-compute the all membership proofs iteratively and concurrently

func ProveMembershipParallel

func ProveMembershipParallel(base, N *big.Int, set []*big.Int, limit int) []*big.Int

ProveMembershipParallel uses divide-and-conquer method to pre-compute the all membership proofs in time O(nlog(n)) It uses at most O(2^limit) Goroutines

func ProveMembershipParallelWithTable

func ProveMembershipParallelWithTable(base, N *big.Int, set []*big.Int, limit int, table *multiexp.PreTable) []*big.Int

ProveMembershipParallelWithTable uses divide-and-conquer method to pre-compute the all membership proofs in time O(nlog(n)) It uses at most O(2^limit) Goroutines

func ProveMembershipParallelWithTableWithRandomizer

func ProveMembershipParallelWithTableWithRandomizer(base, randomizer, N *big.Int, set []*big.Int, limit int, table *multiexp.PreTable) []*big.Int

ProveMembershipParallelWithTableWithRandomizer uses divide-and-conquer method to pre-compute the all membership proofs in time O(nlog(n)) It uses at most O(2^limit) Goroutines It uses the same table with different randomizers

func ProveMembershipParallelWithTableWithRandomizerWithChan

func ProveMembershipParallelWithTableWithRandomizerWithChan(base, randomizer, N *big.Int, set []*big.Int, limit int, table *multiexp.PreTable, c chan []*big.Int)

ProveMembershipParallelWithTableWithRandomizerWithChan uses divide-and-conquer method to pre-compute the all membership proofs in time O(nlog(n)) It uses at most O(2^limit) Goroutines It uses the same table with different randomizers

func ProveMembershipSingleThreadWithRandomizer

func ProveMembershipSingleThreadWithRandomizer(base, randomizer, N *big.Int, set []*big.Int, table *multiexp.PreTable) []*big.Int

ProveMembershipSingleThreadWithRandomizer uses divide-and-conquer method to pre-compute the all membership proofs in time O(nlog(n))

func RandomSetupForUniversalHash

func RandomSetupForUniversalHash()

RandomSetupForUniversalHash generates parameters for a universal hash.

func SHA256ToInt

func SHA256ToInt(input []byte) *big.Int

SHA256ToInt calculates the input with Sha256 and change it to big.Int

func SetProduct

func SetProduct(inputSet []big.Int) *big.Int

SetProduct calculates the products of the input set

func SetProduct2

func SetProduct2(inputSet []*big.Int) *big.Int

SetProduct2 calculates the products of the input set

func SetProductParallel

func SetProductParallel(inputSet []*big.Int, limit int) *big.Int

SetProductParallel uses divide-and-conquer method to calculate the product of the input It uses at most O(2^limit) Goroutines

func SetProductRecursive

func SetProductRecursive(inputSet []*big.Int) *big.Int

SetProductRecursive calculates the products of the input divide-and-conquer recursively

func SetProductRecursiveFast

func SetProductRecursiveFast(inputSet []*big.Int) *big.Int

SetProductRecursiveFast calculates the products of the input divide-and-conquer recursively

func SimpleExp

func SimpleExp(g, x, n *big.Int) *big.Int

SimpleExp should calculate g^x mod n. It is implemented here to campare with golang's official Exp and MultiExp

func TrustedSetupForQRN

func TrustedSetupForQRN()

TrustedSetupForQRN outputs a hidden order group

func UniversalHashToInt

func UniversalHashToInt(input *big.Int) *big.Int

UniversalHashToInt calculates output = input * A + B mod P

func ZKAccumulate

func ZKAccumulate(set []string, encodeType EncodeType, setup *Setup) (*big.Int, []*big.Int)

ZKAccumulate generates one accumulator which is zero-knowledge

Types

type Element

type Element []byte

Element should be able to be accumulated into RSA accumulator

func GetPseudoRandomElement

func GetPseudoRandomElement(input int) *Element

GetPseudoRandomElement returns the pseudo random element from the input integer, for test use only

type EncodeType

type EncodeType int

EncodeType is the type of generating Element, should be consistent all the time

type Setup

type Setup struct {
	N *big.Int
	G *big.Int //default generator in Z*_N
}

Setup is a basic struct for a hidden order group

func TrustedSetup

func TrustedSetup() *Setup

TrustedSetup returns a pointer to AccumulatorSetup with 2048 bits key length

Jump to

Keyboard shortcuts

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