Documentation ¶
Index ¶
- Constants
- Variables
- func AccAndProve(set []string, encodeType EncodeType, setup *Setup) (*big.Int, []*big.Int)
- func AccAndProveIter(set []string, encodeType EncodeType, setup *Setup) (*big.Int, []*big.Int)
- func AccAndProveIterParallel(set []string, encodeType EncodeType, setup *Setup) (*big.Int, []*big.Int)
- func AccAndProveParallel(set []string, encodeType EncodeType, setup *Setup) (*big.Int, []*big.Int)
- func AccumulateNew(g, power, N *big.Int) *big.Int
- func CommonBits(a, b big.Word) big.Word
- func DIHashPoseidon(input ...*fr.Element) *big.Int
- func ElementFromBigInt(v *big.Int) *fr.Element
- func ElementFromString(v string) *fr.Element
- func ElementFromUint32(v uint32) *fr.Element
- func GCB(a, b *big.Int) *big.Int
- func GenBenchSet(num int) []string
- func GenRandomizer() *big.Int
- func GenRepresentatives(set []string, encodeType EncodeType) []*big.Int
- func GenerateG()
- func HashToPrime(input []byte) *big.Int
- func ManualBench(testSetSize int)
- func ManualBenchIter(testSetSize int)
- func ManualBenchIterParallel(testSetSize int)
- func ManualBenchParallel(testSetSize int)
- func ManualBenchZKAcc(testSetSize int)
- func PoseidonAndDIHash(input ...*fr.Element) (*fr.Element, *big.Int)
- func PoseidonWith2Inputs(inputs []*big.Int) *big.Int
- func ProveMembership(base, N *big.Int, set []*big.Int) []*big.Int
- func ProveMembershipIter(base big.Int, N *big.Int, set []*big.Int) []*big.Int
- func ProveMembershipIterParallel(base big.Int, N *big.Int, set []*big.Int) []*big.Int
- func ProveMembershipParallel(base, N *big.Int, set []*big.Int, limit int) []*big.Int
- func ProveMembershipParallelWithTable(base, N *big.Int, set []*big.Int, limit int, table *multiexp.PreTable) []*big.Int
- func ProveMembershipParallelWithTableWithRandomizer(base, randomizer, N *big.Int, set []*big.Int, limit int, ...) []*big.Int
- func ProveMembershipParallelWithTableWithRandomizerWithChan(base, randomizer, N *big.Int, set []*big.Int, limit int, ...)
- func ProveMembershipSingleThreadWithRandomizer(base, randomizer, N *big.Int, set []*big.Int, table *multiexp.PreTable) []*big.Int
- func RandomSetupForUniversalHash()
- func SHA256ToInt(input []byte) *big.Int
- func SetProduct(inputSet []big.Int) *big.Int
- func SetProduct2(inputSet []*big.Int) *big.Int
- func SetProductParallel(inputSet []*big.Int, limit int) *big.Int
- func SetProductRecursive(inputSet []*big.Int) *big.Int
- func SetProductRecursiveFast(inputSet []*big.Int) *big.Int
- func SimpleExp(g, x, n *big.Int) *big.Int
- func TrustedSetupForQRN()
- func UniversalHashToInt(input *big.Int) *big.Int
- func ZKAccumulate(set []string, encodeType EncodeType, setup *Setup) (*big.Int, []*big.Int)
- type Element
- type EncodeType
- type Setup
Constants ¶
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 ¶
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 ¶
AccAndProve generates the accumulator with all the memberships precomputed
func AccAndProveIter ¶
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 ¶
AccAndProveParallel recursively generates the accumulator with all the memberships precomputed in parallel
func AccumulateNew ¶
AccumulateNew calculates g^{power} mod N
func CommonBits ¶
CommonBits calculates the greatest common binaries of a and b when they are uint.
func DIHashPoseidon ¶
DIHashPoseidon generates DI hash with Poseidon hash
func ElementFromBigInt ¶
ElementFromBigInt returns an element in BN256 generated from BigInt
func ElementFromString ¶
ElementFromString returns an element in BN256 generated from string of decimal integers
func ElementFromUint32 ¶
ElementFromUint32 returns an element in BN256 generated from uint32
func GCB ¶
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 ¶
GenBenchSet generate one set where every element is different
func GenRandomizer ¶
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 HashToPrime ¶
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 ¶
PoseidonAndDIHash returns the Poseidon Hash result together with DI hash result
func PoseidonWith2Inputs ¶
PoseidonWith2Inputs inputs 2 big.Int and generate a Poseidon hash result.
func ProveMembership ¶
ProveMembership uses divide-and-conquer method to pre-compute the all membership proofs in time O(nlog(n))
func ProveMembershipIter ¶
ProveMembershipIter uses divide-and-conquer method to pre-compute the all membership proofs iteratively
func ProveMembershipIterParallel ¶
ProveMembershipIterParallel uses divide-and-conquer method to pre-compute the all membership proofs iteratively and concurrently
func ProveMembershipParallel ¶
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 ¶
SHA256ToInt calculates the input with Sha256 and change it to big.Int
func SetProduct ¶
SetProduct calculates the products of the input set
func SetProduct2 ¶
SetProduct2 calculates the products of the input set
func SetProductParallel ¶
SetProductParallel uses divide-and-conquer method to calculate the product of the input It uses at most O(2^limit) Goroutines
func SetProductRecursive ¶
SetProductRecursive calculates the products of the input divide-and-conquer recursively
func SetProductRecursiveFast ¶
SetProductRecursiveFast calculates the products of the input divide-and-conquer recursively
func SimpleExp ¶
SimpleExp should calculate g^x mod n. It is implemented here to campare with golang's official Exp and MultiExp
func UniversalHashToInt ¶
UniversalHashToInt calculates output = input * A + B mod P
func ZKAccumulate ¶
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 ¶
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