MCPcopy Create free account
hub / github.com/DOSNetwork/core / RecoverCommit

Function RecoverCommit

share/poly.go:394–428  ·  view source on GitHub ↗

RecoverCommit reconstructs the secret commitment p(0) from a list of public shares using Lagrange interpolation.

(g kyber.Group, shares []*PubShare, t, n int)

Source from the content-addressed store, hash-verified

392// RecoverCommit reconstructs the secret commitment p(0) from a list of public
393// shares using Lagrange interpolation.
394func RecoverCommit(g kyber.Group, shares []*PubShare, t, n int) (kyber.Point, error) {
395 x := make(map[int]kyber.Scalar)
396 for i, s := range shares {
397 if s == nil || s.V == nil || s.I < 0 || n <= s.I {
398 continue
399 }
400 x[i] = g.Scalar().SetInt64(1 + int64(s.I))
401 }
402
403 if len(x) < t {
404 return nil, errors.New("share: not enough good public shares to reconstruct secret commitment")
405 }
406
407 num := g.Scalar()
408 den := g.Scalar()
409 tmp := g.Scalar()
410 Acc := g.Point().Null()
411 Tmp := g.Point()
412
413 for i, xi := range x {
414 num.One()
415 den.One()
416 for j, xj := range x {
417 if i == j {
418 continue
419 }
420 num.Mul(num, xj)
421 den.Mul(den, tmp.Sub(xj, xi))
422 }
423 Tmp.Mul(num.Div(num, den), shares[i].V)
424 Acc.Add(Acc, Tmp)
425 }
426
427 return Acc, nil
428}

Callers 4

TestPublicRecoveryFunction · 0.85
TestPublicRecoveryDeleteFunction · 0.85
TestPublicAddFunction · 0.85

Calls 10

NewMethod · 0.65
SetInt64Method · 0.45
ScalarMethod · 0.45
NullMethod · 0.45
PointMethod · 0.45
OneMethod · 0.45
MulMethod · 0.45
SubMethod · 0.45
DivMethod · 0.45
AddMethod · 0.45

Tested by 4

TestPublicRecoveryFunction · 0.68
TestPublicRecoveryDeleteFunction · 0.68
TestPublicAddFunction · 0.68