|
|
@ -12,9 +12,11 @@ import ( |
|
|
|
) |
|
|
|
|
|
|
|
type TestChallengerCircuit struct { |
|
|
|
PublicInputs [3]frontend.Variable |
|
|
|
CircuitDigest [4]frontend.Variable |
|
|
|
WiresCap [16][4]frontend.Variable |
|
|
|
PublicInputs [3]frontend.Variable |
|
|
|
CircuitDigest [4]frontend.Variable |
|
|
|
WiresCap [16][4]frontend.Variable |
|
|
|
PlonkZsPartialProductsCap [16][4]frontend.Variable |
|
|
|
QuotientPolysCap [16][4]frontend.Variable |
|
|
|
} |
|
|
|
|
|
|
|
func (circuit *TestChallengerCircuit) Define(api frontend.API) error { |
|
|
@ -39,6 +41,20 @@ func (circuit *TestChallengerCircuit) Define(api frontend.API) error { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var plonkZsPartialProductsCap [16][4]F |
|
|
|
for i := 0; i < len(plonkZsPartialProductsCap); i++ { |
|
|
|
for j := 0; j < len(plonkZsPartialProductsCap[0]); j++ { |
|
|
|
plonkZsPartialProductsCap[i][j] = field.FromBinary(api.ToBinary(circuit.PlonkZsPartialProductsCap[i][j], 64)).(F) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var quotientPolysCap [16][4]F |
|
|
|
for i := 0; i < len(quotientPolysCap); i++ { |
|
|
|
for j := 0; j < len(quotientPolysCap[0]); j++ { |
|
|
|
quotientPolysCap[i][j] = field.FromBinary(api.ToBinary(circuit.QuotientPolysCap[i][j], 64)).(F) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
publicInputHash := poseidonChip.HashNoPad(publicInputs[:]) |
|
|
|
challengerChip.ObserveHash(circuitDigest) |
|
|
|
challengerChip.ObserveHash(publicInputHash) |
|
|
@ -74,15 +90,57 @@ func (circuit *TestChallengerCircuit) Define(api frontend.API) error { |
|
|
|
field.AssertIsEqual(plonkGammas[i], expectedPlonkGammas[i]) |
|
|
|
} |
|
|
|
|
|
|
|
challengerChip.ObserveCap(plonkZsPartialProductsCap[:]) |
|
|
|
plonkAlphas := challengerChip.GetNChallenges(numChallenges) |
|
|
|
|
|
|
|
expectedPlonkAlphas := [2]F{ |
|
|
|
NewFieldElementFromString("14505919539124304197"), |
|
|
|
NewFieldElementFromString("1695455639263736117"), |
|
|
|
} |
|
|
|
|
|
|
|
for i := 0; i < 2; i++ { |
|
|
|
field.AssertIsEqual(plonkAlphas[i], expectedPlonkAlphas[i]) |
|
|
|
} |
|
|
|
|
|
|
|
challengerChip.ObserveCap(quotientPolysCap[:]) |
|
|
|
plonkZeta := challengerChip.GetExtensionChallenge() |
|
|
|
|
|
|
|
expectedPlonkZeta := QuadraticExtension{ |
|
|
|
NewFieldElementFromString("14887793628029982930"), |
|
|
|
NewFieldElementFromString("1136137158284059037"), |
|
|
|
} |
|
|
|
|
|
|
|
for i := 0; i < 2; i++ { |
|
|
|
field.AssertIsEqual(plonkZeta[i], expectedPlonkZeta[i]) |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func TestChallengerWitness(t *testing.T) { |
|
|
|
assert := test.NewAssert(t) |
|
|
|
|
|
|
|
testCase := func(publicInputs [3]frontend.Variable, circuitDigest [4]frontend.Variable, wiresCap [16][4]frontend.Variable) { |
|
|
|
circuit := TestChallengerCircuit{PublicInputs: publicInputs, CircuitDigest: circuitDigest, WiresCap: wiresCap} |
|
|
|
witness := TestChallengerCircuit{PublicInputs: publicInputs, CircuitDigest: circuitDigest, WiresCap: wiresCap} |
|
|
|
testCase := func( |
|
|
|
publicInputs [3]frontend.Variable, |
|
|
|
circuitDigest [4]frontend.Variable, |
|
|
|
wiresCap [16][4]frontend.Variable, |
|
|
|
plonkZsPartialProductsCap [16][4]frontend.Variable, |
|
|
|
quotientPolysCap [16][4]frontend.Variable, |
|
|
|
) { |
|
|
|
circuit := TestChallengerCircuit{ |
|
|
|
PublicInputs: publicInputs, |
|
|
|
CircuitDigest: circuitDigest, |
|
|
|
WiresCap: wiresCap, |
|
|
|
PlonkZsPartialProductsCap: plonkZsPartialProductsCap, |
|
|
|
QuotientPolysCap: quotientPolysCap, |
|
|
|
} |
|
|
|
witness := TestChallengerCircuit{ |
|
|
|
PublicInputs: publicInputs, |
|
|
|
CircuitDigest: circuitDigest, |
|
|
|
WiresCap: wiresCap, |
|
|
|
PlonkZsPartialProductsCap: plonkZsPartialProductsCap, |
|
|
|
QuotientPolysCap: quotientPolysCap, |
|
|
|
} |
|
|
|
err := test.IsSolved(&circuit, &witness, TEST_CURVE.ScalarField()) |
|
|
|
assert.NoError(err) |
|
|
|
} |
|
|
@ -107,16 +165,60 @@ func TestChallengerWitness(t *testing.T) { |
|
|
|
{"10758265002546797581", "1374136260999724547", "7200401521491969338", "219493657547391496"}, |
|
|
|
{"5995963332181008902", "4442996285152250372", "2005936434281221193", "6869325719052666642"}, |
|
|
|
} |
|
|
|
plonkZsPartialProductsCapStr := [][]string{ |
|
|
|
{"1209867952068639569", "4958824272276746373", "8278739766347565702", "1966940898171663504"}, |
|
|
|
{"12599305286358028697", "8932511136775685440", "5376267558248004641", "6313904687311555884"}, |
|
|
|
{"11190791343943249124", "4016631697385248176", "10356629842603047568", "10968099068686195317"}, |
|
|
|
{"1963983823153667719", "6333891613271539690", "12318891063769180636", "10443318253972130654"}, |
|
|
|
{"7799898099378084347", "2751829638242157622", "8351904444410446701", "5284662773710644867"}, |
|
|
|
{"1588568181448440843", "10836321455257423751", "5543952383542989142", "12946954522116753258"}, |
|
|
|
{"15710202198621978057", "13746115173212319217", "6103259182317700987", "17589471289629134988"}, |
|
|
|
{"12877950969971815168", "4963889190939310439", "8868772654550990048", "11774978531783219015"}, |
|
|
|
{"16832740767463005599", "15040340114131672027", "7469306538360789573", "3154855824233652432"}, |
|
|
|
{"9383568437827143152", "1741060064145647394", "17668587021570420286", "5241789470902809114"}, |
|
|
|
{"2087729156816989530", "8248918881937854542", "8673194597758568216", "10710697836634846115"}, |
|
|
|
{"11253371860840267365", "16818881664594712299", "11933553751682199585", "1936353232880935379"}, |
|
|
|
{"12163553231829171860", "17244267969759347515", "2003902333564157189", "6934019871173840760"}, |
|
|
|
{"2082141893879862527", "18267460725569427782", "1129651898415533808", "14011240934155569890"}, |
|
|
|
{"2526273401266876282", "6955959191669943337", "5926536548217021446", "17949337312612691782"}, |
|
|
|
{"8858882459906353593", "5813258279939597857", "6320047506247573502", "15969724232572328561"}, |
|
|
|
} |
|
|
|
quotientPolysCapStr := [][]string{ |
|
|
|
{"9435614145733021495", "1742717829476348934", "11178548223985487003", "14531951007568589725"}, |
|
|
|
{"11747844681527676730", "3089691012847802165", "5887135310661642077", "13943570416123664971"}, |
|
|
|
{"11150071448774479229", "4486829025930200476", "9369448886033958276", "15757606153229850783"}, |
|
|
|
{"14603194410536469617", "11776185929725558373", "3122936423686490326", "10128277488128872810"}, |
|
|
|
{"4990578700975083076", "4997575606014863069", "14499603187047727337", "14028694557236527137"}, |
|
|
|
{"2279147899956815983", "16034899207717647338", "14763350037932939672", "10075834812570828076"}, |
|
|
|
{"1102006741007271956", "15242779529961262072", "6900547375301951311", "8631780317175902419"}, |
|
|
|
{"6299112770394539219", "6297397453582105768", "14148031335065995704", "3794733067587629405"}, |
|
|
|
{"7891039548997763820", "4260484126440019022", "6493066317319943586", "14775252570136307979"}, |
|
|
|
{"10790514248728420789", "14444029601980227412", "17514190309172155536", "12973059492411164965"}, |
|
|
|
{"8940755416742726696", "8469566845539112244", "7642612722784522739", "15276772682665052607"}, |
|
|
|
{"18306931819862706026", "14374659904694625207", "8609543532143656606", "17350044275494282679"}, |
|
|
|
{"9062024023737444614", "13780128979028684176", "6115495431779737008", "7170446003855284754"}, |
|
|
|
{"6191400598853400595", "7806485717076924017", "3225145303141729264", "3644550749005104128"}, |
|
|
|
{"15759718266801608721", "2406060174022670585", "15679263832775538866", "18066847192985300443"}, |
|
|
|
{"9184823221361582966", "4767786405185004644", "9827047623720647370", "993615002460432327"}, |
|
|
|
} |
|
|
|
|
|
|
|
var publicInputs [3]frontend.Variable |
|
|
|
var circuitDigest [4]frontend.Variable |
|
|
|
var wiresCap [16][4]frontend.Variable |
|
|
|
var plonkZsPartialProductsCap [16][4]frontend.Variable |
|
|
|
var quotientPolysCap [16][4]frontend.Variable |
|
|
|
|
|
|
|
copy(publicInputs[:], utils.StrArrayToFrontendVariableArray(publicInputsStr)) |
|
|
|
copy(circuitDigest[:], utils.StrArrayToFrontendVariableArray(circuitDigestStr)) |
|
|
|
for i := 0; i < len(wiresCapStr); i++ { |
|
|
|
copy(wiresCap[i][:], utils.StrArrayToFrontendVariableArray(wiresCapStr[i])) |
|
|
|
} |
|
|
|
for i := 0; i < len(plonkZsPartialProductsCapStr); i++ { |
|
|
|
copy(plonkZsPartialProductsCap[i][:], utils.StrArrayToFrontendVariableArray(plonkZsPartialProductsCapStr[i])) |
|
|
|
} |
|
|
|
for i := 0; i < len(quotientPolysCapStr); i++ { |
|
|
|
copy(quotientPolysCap[i][:], utils.StrArrayToFrontendVariableArray(quotientPolysCapStr[i])) |
|
|
|
} |
|
|
|
|
|
|
|
testCase(publicInputs, circuitDigest, wiresCap) |
|
|
|
testCase(publicInputs, circuitDigest, wiresCap, plonkZsPartialProductsCap, quotientPolysCap) |
|
|
|
} |