This commit is contained in:
williambannas 2018-05-24 21:36:42 +00:00 committed by GitHub
commit 42937c2404
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 403 additions and 403 deletions

View file

@ -3,7 +3,7 @@
//
// Bilinear groups are the basis of many of the new cryptographic protocols that
// have been proposed over the past decade. They consist of a triplet of groups
// (G₁, G₂ and GT) such that there exists a function e(g₁ˣ,g₂ʸ)=gTˣʸ (where gₓ
// (G₁, G₂ and GT) such that there exists a function g(g₁ˣ,g₂ʸ)=gTˣʸ (where gₓ
// is a generator of the respective group). That function is called a pairing
// function.
//
@ -49,108 +49,108 @@ func (g *G1) String() string {
return "bn256.G1" + g.p.String()
}
// ScalarBaseMult sets e to g*k where g is the generator of the group and then
// returns e.
func (e *G1) ScalarBaseMult(k *big.Int) *G1 {
if e.p == nil {
e.p = &curvePoint{}
// ScalarBaseMult sets g to g*k where g is the generator of the group and then
// returns g.
func (g *G1) ScalarBaseMult(k *big.Int) *G1 {
if g.p == nil {
g.p = &curvePoint{}
}
e.p.Mul(curveGen, k)
return e
g.p.Mul(curveGen, k)
return g
}
// ScalarMult sets e to a*k and then returns e.
func (e *G1) ScalarMult(a *G1, k *big.Int) *G1 {
if e.p == nil {
e.p = &curvePoint{}
// ScalarMult sets g to a*k and then returns g.
func (g *G1) ScalarMult(a *G1, k *big.Int) *G1 {
if g.p == nil {
g.p = &curvePoint{}
}
e.p.Mul(a.p, k)
return e
g.p.Mul(a.p, k)
return g
}
// Add sets e to a+b and then returns e.
func (e *G1) Add(a, b *G1) *G1 {
if e.p == nil {
e.p = &curvePoint{}
// Add sets g to a+b and then returns g.
func (g *G1) Add(a, b *G1) *G1 {
if g.p == nil {
g.p = &curvePoint{}
}
e.p.Add(a.p, b.p)
return e
g.p.Add(a.p, b.p)
return g
}
// Neg sets e to -a and then returns e.
func (e *G1) Neg(a *G1) *G1 {
if e.p == nil {
e.p = &curvePoint{}
// Neg sets g to -a and then returns g.
func (g *G1) Neg(a *G1) *G1 {
if g.p == nil {
g.p = &curvePoint{}
}
e.p.Neg(a.p)
return e
g.p.Neg(a.p)
return g
}
// Set sets e to a and then returns e.
func (e *G1) Set(a *G1) *G1 {
if e.p == nil {
e.p = &curvePoint{}
// Set sets g to a and then returns g.
func (g *G1) Set(a *G1) *G1 {
if g.p == nil {
g.p = &curvePoint{}
}
e.p.Set(a.p)
return e
g.p.Set(a.p)
return g
}
// Marshal converts e to a byte slice.
func (e *G1) Marshal() []byte {
// Marshal converts g to a byte slice.
func (g *G1) Marshal() []byte {
// Each value is a 256-bit number.
const numBytes = 256 / 8
e.p.MakeAffine()
g.p.MakeAffine()
ret := make([]byte, numBytes*2)
if e.p.IsInfinity() {
if g.p.IsInfinity() {
return ret
}
temp := &gfP{}
montDecode(temp, &e.p.x)
montDecode(temp, &g.p.x)
temp.Marshal(ret)
montDecode(temp, &e.p.y)
montDecode(temp, &g.p.y)
temp.Marshal(ret[numBytes:])
return ret
}
// Unmarshal sets e to the result of converting the output of Marshal back into
// a group element and then returns e.
func (e *G1) Unmarshal(m []byte) ([]byte, error) {
// Unmarshal sets g to the result of converting the output of Marshal back into
// a group element and then returns g.
func (g *G1) Unmarshal(m []byte) ([]byte, error) {
// Each value is a 256-bit number.
const numBytes = 256 / 8
if len(m) < 2*numBytes {
return nil, errors.New("bn256: not enough data")
}
// Unmarshal the points and check their caps
if e.p == nil {
e.p = &curvePoint{}
if g.p == nil {
g.p = &curvePoint{}
} else {
e.p.x, e.p.y = gfP{0}, gfP{0}
g.p.x, g.p.y = gfP{0}, gfP{0}
}
var err error
if err = e.p.x.Unmarshal(m); err != nil {
if err = g.p.x.Unmarshal(m); err != nil {
return nil, err
}
if err = e.p.y.Unmarshal(m[numBytes:]); err != nil {
if err = g.p.y.Unmarshal(m[numBytes:]); err != nil {
return nil, err
}
// Encode into Montgomery form and ensure it's on the curve
montEncode(&e.p.x, &e.p.x)
montEncode(&e.p.y, &e.p.y)
montEncode(&g.p.x, &g.p.x)
montEncode(&g.p.y, &g.p.y)
zero := gfP{0}
if e.p.x == zero && e.p.y == zero {
if g.p.x == zero && g.p.y == zero {
// This is the point at infinity.
e.p.y = *newGFp(1)
e.p.z = gfP{0}
e.p.t = gfP{0}
g.p.y = *newGFp(1)
g.p.z = gfP{0}
g.p.t = gfP{0}
} else {
e.p.z = *newGFp(1)
e.p.t = *newGFp(1)
g.p.z = *newGFp(1)
g.p.t = *newGFp(1)
if !e.p.IsOnCurve() {
if !g.p.IsOnCurve() {
return nil, errors.New("bn256: malformed point")
}
}
@ -173,125 +173,125 @@ func RandomG2(r io.Reader) (*big.Int, *G2, error) {
return k, new(G2).ScalarBaseMult(k), nil
}
func (e *G2) String() string {
return "bn256.G2" + e.p.String()
func (g *G2) String() string {
return "bn256.G2" + g.p.String()
}
// ScalarBaseMult sets e to g*k where g is the generator of the group and then
// ScalarBaseMult sets g to g*k where g is the generator of the group and then
// returns out.
func (e *G2) ScalarBaseMult(k *big.Int) *G2 {
if e.p == nil {
e.p = &twistPoint{}
func (g *G2) ScalarBaseMult(k *big.Int) *G2 {
if g.p == nil {
g.p = &twistPoint{}
}
e.p.Mul(twistGen, k)
return e
g.p.Mul(twistGen, k)
return g
}
// ScalarMult sets e to a*k and then returns e.
func (e *G2) ScalarMult(a *G2, k *big.Int) *G2 {
if e.p == nil {
e.p = &twistPoint{}
// ScalarMult sets g to a*k and then returns g.
func (g *G2) ScalarMult(a *G2, k *big.Int) *G2 {
if g.p == nil {
g.p = &twistPoint{}
}
e.p.Mul(a.p, k)
return e
g.p.Mul(a.p, k)
return g
}
// Add sets e to a+b and then returns e.
func (e *G2) Add(a, b *G2) *G2 {
if e.p == nil {
e.p = &twistPoint{}
// Add sets g to a+b and then returns g.
func (g *G2) Add(a, b *G2) *G2 {
if g.p == nil {
g.p = &twistPoint{}
}
e.p.Add(a.p, b.p)
return e
g.p.Add(a.p, b.p)
return g
}
// Neg sets e to -a and then returns e.
func (e *G2) Neg(a *G2) *G2 {
if e.p == nil {
e.p = &twistPoint{}
// Neg sets g to -a and then returns g.
func (g *G2) Neg(a *G2) *G2 {
if g.p == nil {
g.p = &twistPoint{}
}
e.p.Neg(a.p)
return e
g.p.Neg(a.p)
return g
}
// Set sets e to a and then returns e.
func (e *G2) Set(a *G2) *G2 {
if e.p == nil {
e.p = &twistPoint{}
// Set sets g to a and then returns g.
func (g *G2) Set(a *G2) *G2 {
if g.p == nil {
g.p = &twistPoint{}
}
e.p.Set(a.p)
return e
g.p.Set(a.p)
return g
}
// Marshal converts e into a byte slice.
func (e *G2) Marshal() []byte {
// Marshal converts g into a byte slice.
func (g *G2) Marshal() []byte {
// Each value is a 256-bit number.
const numBytes = 256 / 8
if e.p == nil {
e.p = &twistPoint{}
if g.p == nil {
g.p = &twistPoint{}
}
e.p.MakeAffine()
g.p.MakeAffine()
ret := make([]byte, numBytes*4)
if e.p.IsInfinity() {
if g.p.IsInfinity() {
return ret
}
temp := &gfP{}
montDecode(temp, &e.p.x.x)
montDecode(temp, &g.p.x.x)
temp.Marshal(ret)
montDecode(temp, &e.p.x.y)
montDecode(temp, &g.p.x.y)
temp.Marshal(ret[numBytes:])
montDecode(temp, &e.p.y.x)
montDecode(temp, &g.p.y.x)
temp.Marshal(ret[2*numBytes:])
montDecode(temp, &e.p.y.y)
montDecode(temp, &g.p.y.y)
temp.Marshal(ret[3*numBytes:])
return ret
}
// Unmarshal sets e to the result of converting the output of Marshal back into
// a group element and then returns e.
func (e *G2) Unmarshal(m []byte) ([]byte, error) {
// Unmarshal sets g to the result of converting the output of Marshal back into
// a group element and then returns g.
func (g *G2) Unmarshal(m []byte) ([]byte, error) {
// Each value is a 256-bit number.
const numBytes = 256 / 8
if len(m) < 4*numBytes {
return nil, errors.New("bn256: not enough data")
}
// Unmarshal the points and check their caps
if e.p == nil {
e.p = &twistPoint{}
if g.p == nil {
g.p = &twistPoint{}
}
var err error
if err = e.p.x.x.Unmarshal(m); err != nil {
if err = g.p.x.x.Unmarshal(m); err != nil {
return nil, err
}
if err = e.p.x.y.Unmarshal(m[numBytes:]); err != nil {
if err = g.p.x.y.Unmarshal(m[numBytes:]); err != nil {
return nil, err
}
if err = e.p.y.x.Unmarshal(m[2*numBytes:]); err != nil {
if err = g.p.y.x.Unmarshal(m[2*numBytes:]); err != nil {
return nil, err
}
if err = e.p.y.y.Unmarshal(m[3*numBytes:]); err != nil {
if err = g.p.y.y.Unmarshal(m[3*numBytes:]); err != nil {
return nil, err
}
// Encode into Montgomery form and ensure it's on the curve
montEncode(&e.p.x.x, &e.p.x.x)
montEncode(&e.p.x.y, &e.p.x.y)
montEncode(&e.p.y.x, &e.p.y.x)
montEncode(&e.p.y.y, &e.p.y.y)
montEncode(&g.p.x.x, &g.p.x.x)
montEncode(&g.p.x.y, &g.p.x.y)
montEncode(&g.p.y.x, &g.p.y.x)
montEncode(&g.p.y.y, &g.p.y.y)
if e.p.x.IsZero() && e.p.y.IsZero() {
if g.p.x.IsZero() && g.p.y.IsZero() {
// This is the point at infinity.
e.p.y.SetOne()
e.p.z.SetZero()
e.p.t.SetZero()
g.p.y.SetOne()
g.p.z.SetZero()
g.p.t.SetZero()
} else {
e.p.z.SetOne()
e.p.t.SetOne()
g.p.z.SetOne()
g.p.t.SetOne()
if !e.p.IsOnCurve() {
if !g.p.IsOnCurve() {
return nil, errors.New("bn256: malformed point")
}
}
@ -334,88 +334,88 @@ func (g *GT) String() string {
return "bn256.GT" + g.p.String()
}
// ScalarMult sets e to a*k and then returns e.
func (e *GT) ScalarMult(a *GT, k *big.Int) *GT {
if e.p == nil {
e.p = &gfP12{}
// ScalarMult sets g to a*k and then returns g.
func (g *GT) ScalarMult(a *GT, k *big.Int) *GT {
if g.p == nil {
g.p = &gfP12{}
}
e.p.Exp(a.p, k)
return e
g.p.Exp(a.p, k)
return g
}
// Add sets e to a+b and then returns e.
func (e *GT) Add(a, b *GT) *GT {
if e.p == nil {
e.p = &gfP12{}
// Add sets g to a+b and then returns g.
func (g *GT) Add(a, b *GT) *GT {
if g.p == nil {
g.p = &gfP12{}
}
e.p.Mul(a.p, b.p)
return e
g.p.Mul(a.p, b.p)
return g
}
// Neg sets e to -a and then returns e.
func (e *GT) Neg(a *GT) *GT {
if e.p == nil {
e.p = &gfP12{}
// Neg sets g to -a and then returns g.
func (g *GT) Neg(a *GT) *GT {
if g.p == nil {
g.p = &gfP12{}
}
e.p.Conjugate(a.p)
return e
g.p.Conjugate(a.p)
return g
}
// Set sets e to a and then returns e.
func (e *GT) Set(a *GT) *GT {
if e.p == nil {
e.p = &gfP12{}
// Set sets g to a and then returns g.
func (g *GT) Set(a *GT) *GT {
if g.p == nil {
g.p = &gfP12{}
}
e.p.Set(a.p)
return e
g.p.Set(a.p)
return g
}
// Finalize is a linear function from F_p^12 to GT.
func (e *GT) Finalize() *GT {
ret := finalExponentiation(e.p)
e.p.Set(ret)
return e
func (g *GT) Finalize() *GT {
ret := finalExponentiation(g.p)
g.p.Set(ret)
return g
}
// Marshal converts e into a byte slice.
func (e *GT) Marshal() []byte {
// Marshal converts g into a byte slice.
func (g *GT) Marshal() []byte {
// Each value is a 256-bit number.
const numBytes = 256 / 8
ret := make([]byte, numBytes*12)
temp := &gfP{}
montDecode(temp, &e.p.x.x.x)
montDecode(temp, &g.p.x.x.x)
temp.Marshal(ret)
montDecode(temp, &e.p.x.x.y)
montDecode(temp, &g.p.x.x.y)
temp.Marshal(ret[numBytes:])
montDecode(temp, &e.p.x.y.x)
montDecode(temp, &g.p.x.y.x)
temp.Marshal(ret[2*numBytes:])
montDecode(temp, &e.p.x.y.y)
montDecode(temp, &g.p.x.y.y)
temp.Marshal(ret[3*numBytes:])
montDecode(temp, &e.p.x.z.x)
montDecode(temp, &g.p.x.z.x)
temp.Marshal(ret[4*numBytes:])
montDecode(temp, &e.p.x.z.y)
montDecode(temp, &g.p.x.z.y)
temp.Marshal(ret[5*numBytes:])
montDecode(temp, &e.p.y.x.x)
montDecode(temp, &g.p.y.x.x)
temp.Marshal(ret[6*numBytes:])
montDecode(temp, &e.p.y.x.y)
montDecode(temp, &g.p.y.x.y)
temp.Marshal(ret[7*numBytes:])
montDecode(temp, &e.p.y.y.x)
montDecode(temp, &g.p.y.y.x)
temp.Marshal(ret[8*numBytes:])
montDecode(temp, &e.p.y.y.y)
montDecode(temp, &g.p.y.y.y)
temp.Marshal(ret[9*numBytes:])
montDecode(temp, &e.p.y.z.x)
montDecode(temp, &g.p.y.z.x)
temp.Marshal(ret[10*numBytes:])
montDecode(temp, &e.p.y.z.y)
montDecode(temp, &g.p.y.z.y)
temp.Marshal(ret[11*numBytes:])
return ret
}
// Unmarshal sets e to the result of converting the output of Marshal back into
// a group element and then returns e.
func (e *GT) Unmarshal(m []byte) ([]byte, error) {
// Unmarshal sets g to the result of converting the output of Marshal back into
// a group element and then returns g.
func (g *GT) Unmarshal(m []byte) ([]byte, error) {
// Each value is a 256-bit number.
const numBytes = 256 / 8
@ -423,59 +423,59 @@ func (e *GT) Unmarshal(m []byte) ([]byte, error) {
return nil, errors.New("bn256: not enough data")
}
if e.p == nil {
e.p = &gfP12{}
if g.p == nil {
g.p = &gfP12{}
}
var err error
if err = e.p.x.x.x.Unmarshal(m); err != nil {
if err = g.p.x.x.x.Unmarshal(m); err != nil {
return nil, err
}
if err = e.p.x.x.y.Unmarshal(m[numBytes:]); err != nil {
if err = g.p.x.x.y.Unmarshal(m[numBytes:]); err != nil {
return nil, err
}
if err = e.p.x.y.x.Unmarshal(m[2*numBytes:]); err != nil {
if err = g.p.x.y.x.Unmarshal(m[2*numBytes:]); err != nil {
return nil, err
}
if err = e.p.x.y.y.Unmarshal(m[3*numBytes:]); err != nil {
if err = g.p.x.y.y.Unmarshal(m[3*numBytes:]); err != nil {
return nil, err
}
if err = e.p.x.z.x.Unmarshal(m[4*numBytes:]); err != nil {
if err = g.p.x.z.x.Unmarshal(m[4*numBytes:]); err != nil {
return nil, err
}
if err = e.p.x.z.y.Unmarshal(m[5*numBytes:]); err != nil {
if err = g.p.x.z.y.Unmarshal(m[5*numBytes:]); err != nil {
return nil, err
}
if err = e.p.y.x.x.Unmarshal(m[6*numBytes:]); err != nil {
if err = g.p.y.x.x.Unmarshal(m[6*numBytes:]); err != nil {
return nil, err
}
if err = e.p.y.x.y.Unmarshal(m[7*numBytes:]); err != nil {
if err = g.p.y.x.y.Unmarshal(m[7*numBytes:]); err != nil {
return nil, err
}
if err = e.p.y.y.x.Unmarshal(m[8*numBytes:]); err != nil {
if err = g.p.y.y.x.Unmarshal(m[8*numBytes:]); err != nil {
return nil, err
}
if err = e.p.y.y.y.Unmarshal(m[9*numBytes:]); err != nil {
if err = g.p.y.y.y.Unmarshal(m[9*numBytes:]); err != nil {
return nil, err
}
if err = e.p.y.z.x.Unmarshal(m[10*numBytes:]); err != nil {
if err = g.p.y.z.x.Unmarshal(m[10*numBytes:]); err != nil {
return nil, err
}
if err = e.p.y.z.y.Unmarshal(m[11*numBytes:]); err != nil {
if err = g.p.y.z.y.Unmarshal(m[11*numBytes:]); err != nil {
return nil, err
}
montEncode(&e.p.x.x.x, &e.p.x.x.x)
montEncode(&e.p.x.x.y, &e.p.x.x.y)
montEncode(&e.p.x.y.x, &e.p.x.y.x)
montEncode(&e.p.x.y.y, &e.p.x.y.y)
montEncode(&e.p.x.z.x, &e.p.x.z.x)
montEncode(&e.p.x.z.y, &e.p.x.z.y)
montEncode(&e.p.y.x.x, &e.p.y.x.x)
montEncode(&e.p.y.x.y, &e.p.y.x.y)
montEncode(&e.p.y.y.x, &e.p.y.y.x)
montEncode(&e.p.y.y.y, &e.p.y.y.y)
montEncode(&e.p.y.z.x, &e.p.y.z.x)
montEncode(&e.p.y.z.y, &e.p.y.z.y)
montEncode(&g.p.x.x.x, &g.p.x.x.x)
montEncode(&g.p.x.x.y, &g.p.x.x.y)
montEncode(&g.p.x.y.x, &g.p.x.y.x)
montEncode(&g.p.x.y.y, &g.p.x.y.y)
montEncode(&g.p.x.z.x, &g.p.x.z.x)
montEncode(&g.p.x.z.y, &g.p.x.z.y)
montEncode(&g.p.y.x.x, &g.p.y.x.x)
montEncode(&g.p.y.x.y, &g.p.y.x.y)
montEncode(&g.p.y.y.x, &g.p.y.y.x)
montEncode(&g.p.y.y.y, &g.p.y.y.y)
montEncode(&g.p.y.z.x, &g.p.y.z.x)
montEncode(&g.p.y.z.y, &g.p.y.z.y)
return m[12*numBytes:], nil
}

View file

@ -110,7 +110,7 @@ func (e *gfP12) MulScalar(a *gfP12, b *gfP6) *gfP12 {
return e
}
func (c *gfP12) Exp(a *gfP12, power *big.Int) *gfP12 {
func (e *gfP12) Exp(a *gfP12, power *big.Int) *gfP12 {
sum := (&gfP12{}).SetOne()
t := &gfP12{}
@ -123,8 +123,8 @@ func (c *gfP12) Exp(a *gfP12, power *big.Int) *gfP12 {
}
}
c.Set(sum)
return c
e.Set(sum)
return e
}
func (e *gfP12) Square(a *gfP12) *gfP12 {

View file

@ -6,7 +6,7 @@
//
// Bilinear groups are the basis of many of the new cryptographic protocols
// that have been proposed over the past decade. They consist of a triplet of
// groups (G₁, G₂ and GT) such that there exists a function e(g₁ˣ,g₂ʸ)=gTˣʸ
// groups (G₁, G₂ and GT) such that there exists a function g(g₁ˣ,g₂ʸ)=gTˣʸ
// (where gₓ is a generator of the respective group). That function is called
// a pairing function.
//
@ -55,54 +55,54 @@ func (g *G1) String() string {
}
// CurvePoints returns p's curve points in big integer
func (e *G1) CurvePoints() (*big.Int, *big.Int, *big.Int, *big.Int) {
return e.p.x, e.p.y, e.p.z, e.p.t
func (g *G1) CurvePoints() (*big.Int, *big.Int, *big.Int, *big.Int) {
return g.p.x, g.p.y, g.p.z, g.p.t
}
// ScalarBaseMult sets e to g*k where g is the generator of the group and
// then returns e.
func (e *G1) ScalarBaseMult(k *big.Int) *G1 {
if e.p == nil {
e.p = newCurvePoint(nil)
// ScalarBaseMult sets g to g*k where g is the generator of the group and
// then returns g.
func (g *G1) ScalarBaseMult(k *big.Int) *G1 {
if g.p == nil {
g.p = newCurvePoint(nil)
}
e.p.Mul(curveGen, k, new(bnPool))
return e
g.p.Mul(curveGen, k, new(bnPool))
return g
}
// ScalarMult sets e to a*k and then returns e.
func (e *G1) ScalarMult(a *G1, k *big.Int) *G1 {
if e.p == nil {
e.p = newCurvePoint(nil)
// ScalarMult sets g to a*k and then returns g.
func (g *G1) ScalarMult(a *G1, k *big.Int) *G1 {
if g.p == nil {
g.p = newCurvePoint(nil)
}
e.p.Mul(a.p, k, new(bnPool))
return e
g.p.Mul(a.p, k, new(bnPool))
return g
}
// Add sets e to a+b and then returns e.
// Add sets g to a+b and then returns g.
// BUG(agl): this function is not complete: a==b fails.
func (e *G1) Add(a, b *G1) *G1 {
if e.p == nil {
e.p = newCurvePoint(nil)
func (g *G1) Add(a, b *G1) *G1 {
if g.p == nil {
g.p = newCurvePoint(nil)
}
e.p.Add(a.p, b.p, new(bnPool))
return e
g.p.Add(a.p, b.p, new(bnPool))
return g
}
// Neg sets e to -a and then returns e.
func (e *G1) Neg(a *G1) *G1 {
if e.p == nil {
e.p = newCurvePoint(nil)
// Neg sets g to -a and then returns g.
func (g *G1) Neg(a *G1) *G1 {
if g.p == nil {
g.p = newCurvePoint(nil)
}
e.p.Negative(a.p)
return e
g.p.Negative(a.p)
return g
}
// Marshal converts n to a byte slice.
func (n *G1) Marshal() []byte {
n.p.MakeAffine(nil)
// Marshal converts g to a byte slice.
func (g *G1) Marshal() []byte {
g.p.MakeAffine(nil)
xBytes := new(big.Int).Mod(n.p.x, P).Bytes()
yBytes := new(big.Int).Mod(n.p.y, P).Bytes()
xBytes := new(big.Int).Mod(g.p.x, P).Bytes()
yBytes := new(big.Int).Mod(g.p.y, P).Bytes()
// Each value is a 256-bit number.
const numBytes = 256 / 8
@ -114,37 +114,37 @@ func (n *G1) Marshal() []byte {
return ret
}
// Unmarshal sets e to the result of converting the output of Marshal back into
// a group element and then returns e.
func (e *G1) Unmarshal(m []byte) ([]byte, error) {
// Unmarshal sets g to the result of converting the output of Marshal back into
// a group element and then returns g.
func (g *G1) Unmarshal(m []byte) ([]byte, error) {
// Each value is a 256-bit number.
const numBytes = 256 / 8
if len(m) != 2*numBytes {
return nil, errors.New("bn256: not enough data")
}
// Unmarshal the points and check their caps
if e.p == nil {
e.p = newCurvePoint(nil)
if g.p == nil {
g.p = newCurvePoint(nil)
}
e.p.x.SetBytes(m[0*numBytes : 1*numBytes])
if e.p.x.Cmp(P) >= 0 {
g.p.x.SetBytes(m[0*numBytes : 1*numBytes])
if g.p.x.Cmp(P) >= 0 {
return nil, errors.New("bn256: coordinate exceeds modulus")
}
e.p.y.SetBytes(m[1*numBytes : 2*numBytes])
if e.p.y.Cmp(P) >= 0 {
g.p.y.SetBytes(m[1*numBytes : 2*numBytes])
if g.p.y.Cmp(P) >= 0 {
return nil, errors.New("bn256: coordinate exceeds modulus")
}
// Ensure the point is on the curve
if e.p.x.Sign() == 0 && e.p.y.Sign() == 0 {
if g.p.x.Sign() == 0 && g.p.y.Sign() == 0 {
// This is the point at infinity.
e.p.y.SetInt64(1)
e.p.z.SetInt64(0)
e.p.t.SetInt64(0)
g.p.y.SetInt64(1)
g.p.z.SetInt64(0)
g.p.t.SetInt64(0)
} else {
e.p.z.SetInt64(1)
e.p.t.SetInt64(1)
g.p.z.SetInt64(1)
g.p.t.SetInt64(1)
if !e.p.IsOnCurve() {
if !g.p.IsOnCurve() {
return nil, errors.New("bn256: malformed point")
}
}
@ -157,7 +157,7 @@ type G2 struct {
p *twistPoint
}
// RandomG1 returns x and g₂ˣ where x is a random, non-zero number read from r.
// RandomG2 returns x and g₂ˣ where x is a random, non-zero number read from r.
func RandomG2(r io.Reader) (*big.Int, *G2, error) {
var k *big.Int
var err error
@ -181,47 +181,47 @@ func (g *G2) String() string {
// CurvePoints returns the curve points of p which includes the real
// and imaginary parts of the curve point.
func (e *G2) CurvePoints() (*gfP2, *gfP2, *gfP2, *gfP2) {
return e.p.x, e.p.y, e.p.z, e.p.t
func (g *G2) CurvePoints() (*gfP2, *gfP2, *gfP2, *gfP2) {
return g.p.x, g.p.y, g.p.z, g.p.t
}
// ScalarBaseMult sets e to g*k where g is the generator of the group and
// ScalarBaseMult sets g to g*k where g is the generator of the group and
// then returns out.
func (e *G2) ScalarBaseMult(k *big.Int) *G2 {
if e.p == nil {
e.p = newTwistPoint(nil)
func (g *G2) ScalarBaseMult(k *big.Int) *G2 {
if g.p == nil {
g.p = newTwistPoint(nil)
}
e.p.Mul(twistGen, k, new(bnPool))
return e
g.p.Mul(twistGen, k, new(bnPool))
return g
}
// ScalarMult sets e to a*k and then returns e.
func (e *G2) ScalarMult(a *G2, k *big.Int) *G2 {
if e.p == nil {
e.p = newTwistPoint(nil)
// ScalarMult sets g to a*k and then returns g.
func (g *G2) ScalarMult(a *G2, k *big.Int) *G2 {
if g.p == nil {
g.p = newTwistPoint(nil)
}
e.p.Mul(a.p, k, new(bnPool))
return e
g.p.Mul(a.p, k, new(bnPool))
return g
}
// Add sets e to a+b and then returns e.
// Add sets g to a+b and then returns g.
// BUG(agl): this function is not complete: a==b fails.
func (e *G2) Add(a, b *G2) *G2 {
if e.p == nil {
e.p = newTwistPoint(nil)
func (g *G2) Add(a, b *G2) *G2 {
if g.p == nil {
g.p = newTwistPoint(nil)
}
e.p.Add(a.p, b.p, new(bnPool))
return e
g.p.Add(a.p, b.p, new(bnPool))
return g
}
// Marshal converts n into a byte slice.
func (n *G2) Marshal() []byte {
n.p.MakeAffine(nil)
// Marshal converts g into a byte slice.
func (g *G2) Marshal() []byte {
g.p.MakeAffine(nil)
xxBytes := new(big.Int).Mod(n.p.x.x, P).Bytes()
xyBytes := new(big.Int).Mod(n.p.x.y, P).Bytes()
yxBytes := new(big.Int).Mod(n.p.y.x, P).Bytes()
yyBytes := new(big.Int).Mod(n.p.y.y, P).Bytes()
xxBytes := new(big.Int).Mod(g.p.x.x, P).Bytes()
xyBytes := new(big.Int).Mod(g.p.x.y, P).Bytes()
yxBytes := new(big.Int).Mod(g.p.y.x, P).Bytes()
yyBytes := new(big.Int).Mod(g.p.y.y, P).Bytes()
// Each value is a 256-bit number.
const numBytes = 256 / 8
@ -235,48 +235,48 @@ func (n *G2) Marshal() []byte {
return ret
}
// Unmarshal sets e to the result of converting the output of Marshal back into
// a group element and then returns e.
func (e *G2) Unmarshal(m []byte) ([]byte, error) {
// Unmarshal sets g to the result of converting the output of Marshal back into
// a group element and then returns g.
func (g *G2) Unmarshal(m []byte) ([]byte, error) {
// Each value is a 256-bit number.
const numBytes = 256 / 8
if len(m) != 4*numBytes {
return nil, errors.New("bn256: not enough data")
}
// Unmarshal the points and check their caps
if e.p == nil {
e.p = newTwistPoint(nil)
if g.p == nil {
g.p = newTwistPoint(nil)
}
e.p.x.x.SetBytes(m[0*numBytes : 1*numBytes])
if e.p.x.x.Cmp(P) >= 0 {
g.p.x.x.SetBytes(m[0*numBytes : 1*numBytes])
if g.p.x.x.Cmp(P) >= 0 {
return nil, errors.New("bn256: coordinate exceeds modulus")
}
e.p.x.y.SetBytes(m[1*numBytes : 2*numBytes])
if e.p.x.y.Cmp(P) >= 0 {
g.p.x.y.SetBytes(m[1*numBytes : 2*numBytes])
if g.p.x.y.Cmp(P) >= 0 {
return nil, errors.New("bn256: coordinate exceeds modulus")
}
e.p.y.x.SetBytes(m[2*numBytes : 3*numBytes])
if e.p.y.x.Cmp(P) >= 0 {
g.p.y.x.SetBytes(m[2*numBytes : 3*numBytes])
if g.p.y.x.Cmp(P) >= 0 {
return nil, errors.New("bn256: coordinate exceeds modulus")
}
e.p.y.y.SetBytes(m[3*numBytes : 4*numBytes])
if e.p.y.y.Cmp(P) >= 0 {
g.p.y.y.SetBytes(m[3*numBytes : 4*numBytes])
if g.p.y.y.Cmp(P) >= 0 {
return nil, errors.New("bn256: coordinate exceeds modulus")
}
// Ensure the point is on the curve
if e.p.x.x.Sign() == 0 &&
e.p.x.y.Sign() == 0 &&
e.p.y.x.Sign() == 0 &&
e.p.y.y.Sign() == 0 {
if g.p.x.x.Sign() == 0 &&
g.p.x.y.Sign() == 0 &&
g.p.y.x.Sign() == 0 &&
g.p.y.y.Sign() == 0 {
// This is the point at infinity.
e.p.y.SetOne()
e.p.z.SetZero()
e.p.t.SetZero()
g.p.y.SetOne()
g.p.z.SetZero()
g.p.t.SetZero()
} else {
e.p.z.SetOne()
e.p.t.SetOne()
g.p.z.SetOne()
g.p.t.SetOne()
if !e.p.IsOnCurve() {
if !g.p.IsOnCurve() {
return nil, errors.New("bn256: malformed point")
}
}
@ -293,49 +293,49 @@ func (g *GT) String() string {
return "bn256.GT" + g.p.String()
}
// ScalarMult sets e to a*k and then returns e.
func (e *GT) ScalarMult(a *GT, k *big.Int) *GT {
if e.p == nil {
e.p = newGFp12(nil)
// ScalarMult sets g to a*k and then returns g.
func (g *GT) ScalarMult(a *GT, k *big.Int) *GT {
if g.p == nil {
g.p = newGFp12(nil)
}
e.p.Exp(a.p, k, new(bnPool))
return e
g.p.Exp(a.p, k, new(bnPool))
return g
}
// Add sets e to a+b and then returns e.
func (e *GT) Add(a, b *GT) *GT {
if e.p == nil {
e.p = newGFp12(nil)
// Add sets g to a+b and then returns g.
func (g *GT) Add(a, b *GT) *GT {
if g.p == nil {
g.p = newGFp12(nil)
}
e.p.Mul(a.p, b.p, new(bnPool))
return e
g.p.Mul(a.p, b.p, new(bnPool))
return g
}
// Neg sets e to -a and then returns e.
func (e *GT) Neg(a *GT) *GT {
if e.p == nil {
e.p = newGFp12(nil)
// Neg sets g to -a and then returns g.
func (g *GT) Neg(a *GT) *GT {
if g.p == nil {
g.p = newGFp12(nil)
}
e.p.Invert(a.p, new(bnPool))
return e
g.p.Invert(a.p, new(bnPool))
return g
}
// Marshal converts n into a byte slice.
func (n *GT) Marshal() []byte {
n.p.Minimal()
// Marshal converts g into a byte slice.
func (g *GT) Marshal() []byte {
g.p.Minimal()
xxxBytes := n.p.x.x.x.Bytes()
xxyBytes := n.p.x.x.y.Bytes()
xyxBytes := n.p.x.y.x.Bytes()
xyyBytes := n.p.x.y.y.Bytes()
xzxBytes := n.p.x.z.x.Bytes()
xzyBytes := n.p.x.z.y.Bytes()
yxxBytes := n.p.y.x.x.Bytes()
yxyBytes := n.p.y.x.y.Bytes()
yyxBytes := n.p.y.y.x.Bytes()
yyyBytes := n.p.y.y.y.Bytes()
yzxBytes := n.p.y.z.x.Bytes()
yzyBytes := n.p.y.z.y.Bytes()
xxxBytes := g.p.x.x.x.Bytes()
xxyBytes := g.p.x.x.y.Bytes()
xyxBytes := g.p.x.y.x.Bytes()
xyyBytes := g.p.x.y.y.Bytes()
xzxBytes := g.p.x.z.x.Bytes()
xzyBytes := g.p.x.z.y.Bytes()
yxxBytes := g.p.y.x.x.Bytes()
yxyBytes := g.p.y.x.y.Bytes()
yyxBytes := g.p.y.y.x.Bytes()
yyyBytes := g.p.y.y.y.Bytes()
yzxBytes := g.p.y.z.x.Bytes()
yzyBytes := g.p.y.z.y.Bytes()
// Each value is a 256-bit number.
const numBytes = 256 / 8
@ -357,9 +357,9 @@ func (n *GT) Marshal() []byte {
return ret
}
// Unmarshal sets e to the result of converting the output of Marshal back into
// a group element and then returns e.
func (e *GT) Unmarshal(m []byte) (*GT, bool) {
// Unmarshal sets g to the result of converting the output of Marshal back into
// a group element and then returns g.
func (g *GT) Unmarshal(m []byte) (*GT, bool) {
// Each value is a 256-bit number.
const numBytes = 256 / 8
@ -367,24 +367,24 @@ func (e *GT) Unmarshal(m []byte) (*GT, bool) {
return nil, false
}
if e.p == nil {
e.p = newGFp12(nil)
if g.p == nil {
g.p = newGFp12(nil)
}
e.p.x.x.x.SetBytes(m[0*numBytes : 1*numBytes])
e.p.x.x.y.SetBytes(m[1*numBytes : 2*numBytes])
e.p.x.y.x.SetBytes(m[2*numBytes : 3*numBytes])
e.p.x.y.y.SetBytes(m[3*numBytes : 4*numBytes])
e.p.x.z.x.SetBytes(m[4*numBytes : 5*numBytes])
e.p.x.z.y.SetBytes(m[5*numBytes : 6*numBytes])
e.p.y.x.x.SetBytes(m[6*numBytes : 7*numBytes])
e.p.y.x.y.SetBytes(m[7*numBytes : 8*numBytes])
e.p.y.y.x.SetBytes(m[8*numBytes : 9*numBytes])
e.p.y.y.y.SetBytes(m[9*numBytes : 10*numBytes])
e.p.y.z.x.SetBytes(m[10*numBytes : 11*numBytes])
e.p.y.z.y.SetBytes(m[11*numBytes : 12*numBytes])
g.p.x.x.x.SetBytes(m[0*numBytes : 1*numBytes])
g.p.x.x.y.SetBytes(m[1*numBytes : 2*numBytes])
g.p.x.y.x.SetBytes(m[2*numBytes : 3*numBytes])
g.p.x.y.y.SetBytes(m[3*numBytes : 4*numBytes])
g.p.x.z.x.SetBytes(m[4*numBytes : 5*numBytes])
g.p.x.z.y.SetBytes(m[5*numBytes : 6*numBytes])
g.p.y.x.x.SetBytes(m[6*numBytes : 7*numBytes])
g.p.y.x.y.SetBytes(m[7*numBytes : 8*numBytes])
g.p.y.y.x.SetBytes(m[8*numBytes : 9*numBytes])
g.p.y.y.y.SetBytes(m[9*numBytes : 10*numBytes])
g.p.y.z.x.SetBytes(m[10*numBytes : 11*numBytes])
g.p.y.z.y.SetBytes(m[11*numBytes : 12*numBytes])
return e, true
return g, true
}
// Pair calculates an Optimal Ate pairing.

View file

@ -16,7 +16,7 @@ func bigFromBase10(s string) *big.Int {
// u is the BN parameter that determines the prime: 1868033³.
var u = bigFromBase10("4965661367192848881")
// p is a prime over which we form a basic field: 36u⁴+36u³+24u²+6u+1.
// P is a prime over which we form a basic field: 36u⁴+36u³+24u²+6u+1.
var P = bigFromBase10("21888242871839275222246405745257275088696311157297823662689037894645226208583")
// Order is the number of elements in both G₁ and G₂: 36u⁴+36u³+18u²+6u+1.

View file

@ -186,14 +186,14 @@ func (c *curvePoint) Double(a *curvePoint, pool *bnPool) {
A.Mod(A, P)
B := pool.Get().Mul(a.y, a.y)
B.Mod(B, P)
C_ := pool.Get().Mul(B, B)
C_.Mod(C_, P)
_C := pool.Get().Mul(B, B)
_C.Mod(_C, P)
t := pool.Get().Add(a.x, B)
t2 := pool.Get().Mul(t, t)
t2.Mod(t2, P)
t.Sub(t2, A)
t2.Sub(t, C_)
t2.Sub(t, _C)
d := pool.Get().Add(t2, t2)
t.Add(A, A)
e := pool.Get().Add(t, A)
@ -203,7 +203,7 @@ func (c *curvePoint) Double(a *curvePoint, pool *bnPool) {
t.Add(d, d)
c.x.Sub(f, t)
t.Add(C_, C_)
t.Add(_C, _C)
t2.Add(t, t)
t.Add(t2, t2)
c.y.Sub(d, c.x)
@ -217,7 +217,7 @@ func (c *curvePoint) Double(a *curvePoint, pool *bnPool) {
pool.Put(A)
pool.Put(B)
pool.Put(C_)
pool.Put(_C)
pool.Put(t)
pool.Put(t2)
pool.Put(d)

View file

@ -130,7 +130,7 @@ func (e *gfP12) MulScalar(a *gfP12, b *gfP6, pool *bnPool) *gfP12 {
return e
}
func (c *gfP12) Exp(a *gfP12, power *big.Int, pool *bnPool) *gfP12 {
func (e *gfP12) Exp(a *gfP12, power *big.Int, pool *bnPool) *gfP12 {
sum := newGFp12(pool)
sum.SetOne()
t := newGFp12(pool)
@ -144,12 +144,12 @@ func (c *gfP12) Exp(a *gfP12, power *big.Int, pool *bnPool) *gfP12 {
}
}
c.Set(sum)
e.Set(sum)
sum.Put(pool)
t.Put(pool)
return c
return e
}
func (e *gfP12) Square(a *gfP12, pool *bnPool) *gfP12 {

View file

@ -102,7 +102,7 @@ func (e *gfP2) Double(a *gfP2) *gfP2 {
return e
}
func (c *gfP2) Exp(a *gfP2, power *big.Int, pool *bnPool) *gfP2 {
func (e *gfP2) Exp(a *gfP2, power *big.Int, pool *bnPool) *gfP2 {
sum := newGFp2(pool)
sum.SetOne()
t := newGFp2(pool)
@ -116,12 +116,12 @@ func (c *gfP2) Exp(a *gfP2, power *big.Int, pool *bnPool) *gfP2 {
}
}
c.Set(sum)
e.Set(sum)
sum.Put(pool)
t.Put(pool)
return c
return e
}
// See "Multiplication and Squaring in Pairing-Friendly Fields",

View file

@ -266,13 +266,13 @@ func (e *gfP6) Invert(a *gfP6, pool *bnPool) *gfP6 {
t1.Mul(a.y, a.z, pool)
B.Sub(B, t1)
C_ := newGFp2(pool)
C_.Square(a.y, pool)
_C := newGFp2(pool)
_C.Square(a.y, pool)
t1.Mul(a.x, a.z, pool)
C_.Sub(C_, t1)
_C.Sub(_C, t1)
F := newGFp2(pool)
F.Mul(C_, a.y, pool)
F.Mul(_C, a.y, pool)
F.MulXi(F, pool)
t1.Mul(A, a.z, pool)
F.Add(F, t1)
@ -282,14 +282,14 @@ func (e *gfP6) Invert(a *gfP6, pool *bnPool) *gfP6 {
F.Invert(F, pool)
e.x.Mul(C_, F, pool)
e.x.Mul(_C, F, pool)
e.y.Mul(B, F, pool)
e.z.Mul(A, F, pool)
t1.Put(pool)
A.Put(pool)
B.Put(pool)
C_.Put(pool)
_C.Put(pool)
F.Put(pool)
return e

View file

@ -88,12 +88,12 @@ func lineFunctionDouble(r *twistPoint, q *curvePoint, pool *bnPool) (a, b, c *gf
A := newGFp2(pool).Square(r.x, pool)
B := newGFp2(pool).Square(r.y, pool)
C_ := newGFp2(pool).Square(B, pool)
_C := newGFp2(pool).Square(B, pool)
D := newGFp2(pool).Add(r.x, B)
D.Square(D, pool)
D.Sub(D, A)
D.Sub(D, C_)
D.Sub(D, _C)
D.Add(D, D)
E := newGFp2(pool).Add(A, A)
@ -112,7 +112,7 @@ func lineFunctionDouble(r *twistPoint, q *curvePoint, pool *bnPool) (a, b, c *gf
rOut.y.Sub(D, rOut.x)
rOut.y.Mul(rOut.y, E, pool)
t := newGFp2(pool).Add(C_, C_)
t := newGFp2(pool).Add(_C, _C)
t.Add(t, t)
t.Add(t, t)
rOut.y.Sub(rOut.y, t)
@ -142,7 +142,7 @@ func lineFunctionDouble(r *twistPoint, q *curvePoint, pool *bnPool) (a, b, c *gf
A.Put(pool)
B.Put(pool)
C_.Put(pool)
_C.Put(pool)
D.Put(pool)
E.Put(pool)
G.Put(pool)

View file

@ -171,12 +171,12 @@ func (c *twistPoint) Double(a *twistPoint, pool *bnPool) {
// See http://hyperelliptic.org/EFD/g1p/auto-code/shortw/jacobian-0/doubling/dbl-2009-l.op3
A := newGFp2(pool).Square(a.x, pool)
B := newGFp2(pool).Square(a.y, pool)
C_ := newGFp2(pool).Square(B, pool)
_C := newGFp2(pool).Square(B, pool)
t := newGFp2(pool).Add(a.x, B)
t2 := newGFp2(pool).Square(t, pool)
t.Sub(t2, A)
t2.Sub(t, C_)
t2.Sub(t, _C)
d := newGFp2(pool).Add(t2, t2)
t.Add(A, A)
e := newGFp2(pool).Add(t, A)
@ -185,7 +185,7 @@ func (c *twistPoint) Double(a *twistPoint, pool *bnPool) {
t.Add(d, d)
c.x.Sub(f, t)
t.Add(C_, C_)
t.Add(_C, _C)
t2.Add(t, t)
t.Add(t2, t2)
c.y.Sub(d, c.x)
@ -197,7 +197,7 @@ func (c *twistPoint) Double(a *twistPoint, pool *bnPool) {
A.Put(pool)
B.Put(pool)
C_.Put(pool)
_C.Put(pool)
t.Put(pool)
t2.Put(pool)
d.Put(pool)

View file

@ -58,12 +58,12 @@ type PublicKey struct {
Params *ECIESParams
}
// Export an ECIES public key as an ECDSA public key.
//ExportECDSA exports an ECIES public key as an ECDSA public key.
func (pub *PublicKey) ExportECDSA() *ecdsa.PublicKey {
return &ecdsa.PublicKey{Curve: pub.Curve, X: pub.X, Y: pub.Y}
}
// Import an ECDSA public key as an ECIES public key.
//ImportECDSAPublic imports an ECDSA public key as an ECIES public key.
func ImportECDSAPublic(pub *ecdsa.PublicKey) *PublicKey {
return &PublicKey{
X: pub.X,
@ -79,21 +79,21 @@ type PrivateKey struct {
D *big.Int
}
// Export an ECIES private key as an ECDSA private key.
// ExportECDSA exports an ECIES private key as an ECDSA private key.
func (prv *PrivateKey) ExportECDSA() *ecdsa.PrivateKey {
pub := &prv.PublicKey
pubECDSA := pub.ExportECDSA()
return &ecdsa.PrivateKey{PublicKey: *pubECDSA, D: prv.D}
}
// Import an ECDSA private key as an ECIES private key.
//ImportECDSA imports an ECDSA private key as an ECIES private key.
func ImportECDSA(prv *ecdsa.PrivateKey) *PrivateKey {
pub := ImportECDSAPublic(&prv.PublicKey)
return &PrivateKey{*pub, prv.D}
}
// Generate an elliptic curve public / private keypair. If params is nil,
// the recommended default parameters for the key will be chosen.
// GenerateKey generates an elliptic curve public / private keypair.
// If params is nil,the recommended default parameters for the key will be chosen.
func GenerateKey(rand io.Reader, curve elliptic.Curve, params *ECIESParams) (prv *PrivateKey, err error) {
pb, x, y, err := elliptic.GenerateKey(curve, rand)
if err != nil {
@ -117,7 +117,7 @@ func MaxSharedKeyLength(pub *PublicKey) int {
return (pub.Curve.Params().BitSize + 7) / 8
}
// ECDH key agreement method used to establish secret keys for encryption.
//GenerateShared is the ECDH key agreement method used to establish secret keys for encryption.
func (prv *PrivateKey) GenerateShared(pub *PublicKey, skLen, macLen int) (sk []byte, err error) {
if prv.PublicKey.Curve != pub.Curve {
return nil, ErrInvalidCurve

View file

@ -101,9 +101,8 @@ func cmpPrivate(prv1, prv2 *PrivateKey) bool {
return false
} else if prv1.D.Cmp(prv2.D) != 0 {
return false
} else {
return cmpPublic(prv1.PublicKey, prv2.PublicKey)
}
return cmpPublic(prv1.PublicKey, prv2.PublicKey)
}
// Validate the ECDH component.

View file

@ -351,7 +351,7 @@ func (api *PrivateDebugAPI) Preimage(ctx context.Context, hash common.Hash) (hex
return nil, errors.New("unknown preimage")
}
// GetBadBLocks returns a list of the last 'bad blocks' that the client has seen on the network
// GetBadBlocks returns a list of the last 'bad blocks' that the client has seen on the network
// and returns them as a JSON list of block-hashes
func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]core.BadBlockArgs, error) {
return api.eth.BlockChain().BadBlocks()
@ -406,7 +406,7 @@ func storageRangeAt(st state.Trie, start []byte, maxResult int) (StorageRangeRes
return result, nil
}
// GetModifiedAccountsByumber returns all accounts that have changed between the
// GetModifiedAccountsByNumber returns all accounts that have changed between the
// two blocks specified. A change is defined as a difference in nonce, balance,
// code hash, or storage hash.
//

View file

@ -43,6 +43,7 @@ type EthAPIBackend struct {
gpo *gasprice.Oracle
}
// ChainConfig returns the the core config which determined the blockchain settings
func (b *EthAPIBackend) ChainConfig() *params.ChainConfig {
return b.eth.chainConfig
}

View file

@ -88,7 +88,7 @@ type Ethereum struct {
gasPrice *big.Int
etherbase common.Address
networkId uint64
networkID uint64
netRPCService *ethapi.PublicNetAPI
lock sync.RWMutex // Protects the variadic fields (e.g. gas price and etherbase)
@ -126,7 +126,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
accountManager: ctx.AccountManager,
engine: CreateConsensusEngine(ctx, &config.Ethash, chainConfig, chainDb),
shutdownChan: make(chan bool),
networkId: config.NetworkId,
networkID: config.NetworkId,
gasPrice: config.GasPrice,
etherbase: config.Etherbase,
bloomRequests: make(chan chan *bloombits.Retrieval),
@ -369,7 +369,7 @@ func (s *Ethereum) Engine() consensus.Engine { return s.engine }
func (s *Ethereum) ChainDb() ethdb.Database { return s.chainDb }
func (s *Ethereum) IsListening() bool { return true } // Always listening
func (s *Ethereum) EthVersion() int { return int(s.protocolManager.SubProtocols[0].Version) }
func (s *Ethereum) NetVersion() uint64 { return s.networkId }
func (s *Ethereum) NetVersion() uint64 { return s.networkID }
func (s *Ethereum) Downloader() *downloader.Downloader { return s.protocolManager.downloader }
// Protocols implements node.Service, returning all the currently configured

View file

@ -900,7 +900,7 @@ func (d *Downloader) fillHeaderSkeleton(from uint64, skeleton []*types.Header) (
var (
deliver = func(packet dataPack) (int, error) {
pack := packet.(*headerPack)
return d.queue.DeliverHeaders(pack.peerId, pack.headers, d.headerProcCh)
return d.queue.DeliverHeaders(pack.peerID, pack.headers, d.headerProcCh)
}
expire = func() map[string]int { return d.queue.ExpireHeaders(d.requestTTL()) }
throttle = func() bool { return false }
@ -930,7 +930,7 @@ func (d *Downloader) fetchBodies(from uint64) error {
var (
deliver = func(packet dataPack) (int, error) {
pack := packet.(*bodyPack)
return d.queue.DeliverBodies(pack.peerId, pack.transactions, pack.uncles)
return d.queue.DeliverBodies(pack.peerID, pack.transactions, pack.uncles)
}
expire = func() map[string]int { return d.queue.ExpireBodies(d.requestTTL()) }
fetch = func(p *peerConnection, req *fetchRequest) error { return p.FetchBodies(req) }
@ -954,7 +954,7 @@ func (d *Downloader) fetchReceipts(from uint64) error {
var (
deliver = func(packet dataPack) (int, error) {
pack := packet.(*receiptPack)
return d.queue.DeliverReceipts(pack.peerId, pack.receipts)
return d.queue.DeliverReceipts(pack.peerID, pack.receipts)
}
expire = func() map[string]int { return d.queue.ExpireReceipts(d.requestTTL()) }
fetch = func(p *peerConnection, req *fetchRequest) error { return p.FetchReceipts(req) }

View file

@ -596,21 +596,21 @@ func (q *queue) cancel(request *fetchRequest, taskQueue *prque.Prque, pendPool m
// Revoke cancels all pending requests belonging to a given peer. This method is
// meant to be called during a peer drop to quickly reassign owned data fetches
// to remaining nodes.
func (q *queue) Revoke(peerId string) {
func (q *queue) Revoke(peerID string) {
q.lock.Lock()
defer q.lock.Unlock()
if request, ok := q.blockPendPool[peerId]; ok {
if request, ok := q.blockPendPool[peerID]; ok {
for _, header := range request.Headers {
q.blockTaskQueue.Push(header, -float32(header.Number.Uint64()))
}
delete(q.blockPendPool, peerId)
delete(q.blockPendPool, peerID)
}
if request, ok := q.receiptPendPool[peerId]; ok {
if request, ok := q.receiptPendPool[peerID]; ok {
for _, header := range request.Headers {
q.receiptTaskQueue.Push(header, -float32(header.Number.Uint64()))
}
delete(q.receiptPendPool, peerId)
delete(q.receiptPendPool, peerID)
}
}

View file

@ -34,22 +34,22 @@ type dataPack interface {
// headerPack is a batch of block headers returned by a peer.
type headerPack struct {
peerId string
peerID string
headers []*types.Header
}
func (p *headerPack) PeerId() string { return p.peerId }
func (p *headerPack) PeerId() string { return p.peerID }
func (p *headerPack) Items() int { return len(p.headers) }
func (p *headerPack) Stats() string { return fmt.Sprintf("%d", len(p.headers)) }
// bodyPack is a batch of block bodies returned by a peer.
type bodyPack struct {
peerId string
peerID string
transactions [][]*types.Transaction
uncles [][]*types.Header
}
func (p *bodyPack) PeerId() string { return p.peerId }
func (p *bodyPack) PeerId() string { return p.peerID }
func (p *bodyPack) Items() int {
if len(p.transactions) <= len(p.uncles) {
return len(p.transactions)
@ -60,20 +60,20 @@ func (p *bodyPack) Stats() string { return fmt.Sprintf("%d:%d", len(p.transactio
// receiptPack is a batch of receipts returned by a peer.
type receiptPack struct {
peerId string
peerID string
receipts [][]*types.Receipt
}
func (p *receiptPack) PeerId() string { return p.peerId }
func (p *receiptPack) PeerId() string { return p.peerID }
func (p *receiptPack) Items() int { return len(p.receipts) }
func (p *receiptPack) Stats() string { return fmt.Sprintf("%d", len(p.receipts)) }
// statePack is a batch of states returned by a peer.
type statePack struct {
peerId string
peerID string
states [][]byte
}
func (p *statePack) PeerId() string { return p.peerId }
func (p *statePack) PeerId() string { return p.peerID }
func (p *statePack) Items() int { return len(p.states) }
func (p *statePack) Stats() string { return fmt.Sprintf("%d", len(p.states)) }

View file

@ -64,7 +64,7 @@ func errResp(code errCode, format string, v ...interface{}) error {
}
type ProtocolManager struct {
networkId uint64
networkID uint64
fastSync uint32 // Flag whether fast sync is enabled (gets disabled if we already have blocks)
acceptTxs uint32 // Flag whether we're considered synchronised (enables transaction processing)
@ -98,10 +98,10 @@ type ProtocolManager struct {
// NewProtocolManager returns a new Ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
// with the Ethereum network.
func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, networkId uint64, mux *event.TypeMux, txpool txPool, engine consensus.Engine, blockchain *core.BlockChain, chaindb ethdb.Database) (*ProtocolManager, error) {
func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, networkID uint64, mux *event.TypeMux, txpool txPool, engine consensus.Engine, blockchain *core.BlockChain, chaindb ethdb.Database) (*ProtocolManager, error) {
// Create the protocol manager with the base fields
manager := &ProtocolManager{
networkId: networkId,
networkID: networkID,
eventMux: mux,
txpool: txpool,
blockchain: blockchain,
@ -263,7 +263,7 @@ func (pm *ProtocolManager) handle(p *peer) error {
number = head.Number.Uint64()
td = pm.blockchain.GetTd(hash, number)
)
if err := p.Handshake(pm.networkId, td, hash, genesis.Hash()); err != nil {
if err := p.Handshake(pm.networkID, td, hash, genesis.Hash()); err != nil {
p.Log().Debug("Ethereum handshake failed", "err", err)
return err
}
@ -770,7 +770,7 @@ type NodeInfo struct {
func (pm *ProtocolManager) NodeInfo() *NodeInfo {
currentBlock := pm.blockchain.CurrentBlock()
return &NodeInfo{
Network: pm.networkId,
Network: pm.networkID,
Difficulty: pm.blockchain.GetTd(currentBlock.Hash(), currentBlock.NumberU64()),
Genesis: pm.blockchain.Genesis().Hash(),
Config: pm.blockchain.Config(),