diff --git a/pairing/bn256/suite_test.go b/pairing/bn256/suite_test.goindex f15d93ff..dc0da60c 100644--- a/pairing/bn256/suite_test.go+++ b/pairing/bn256/suite_test.go@@ -3,6 +3,7 @@ package bn256import ("bytes""fmt"+ "math/big""testing"@@ -92,6 +93,38 @@ func TestG1Marshal(t *testing.T) {require.Equal(t, ma, mb)}+func TestG1ToSolidity(t *testing.T) {+ bi := new(big.Int)+ suite := NewSuite()++ // Try first with a Zero point.+ k := suite.G1().Scalar().Zero()+ pa := suite.G1().Point().Mul(k, nil)+ ma, err := pa.MarshalBinary()+ require.Nil(t, err)++ // To Solidity, uint256 x 2+ // SetBytes docs (pay attention to endianess!)+ bi.SetBytes(ma[0:32])+ // formatting bi as %s is the same as calling math/big.(*Int).String().+ t.Logf("uint256 g1x = %s", bi)+ bi.SetBytes(ma[32:])+ t.Logf("uint256 g1y = %s", bi)++ // Now try with a random point.+ k = suite.G1().Scalar().Pick(random.New())+ pa = suite.G1().Point().Mul(k, nil)+ ma, err = pa.MarshalBinary()+ require.Nil(t, err)+ // To Solidity, uint256 x 2+ bi.SetBytes(ma[0:32])+ t.Logf("uint256 g1x = %s", bi)+ bi.SetBytes(ma[32:])+ t.Logf("uint256 g1y = %s", bi)+}+func TestG1Ops(t *testing.T) {suite := NewSuite()a := suite.G1().Point().Pick(random.New())
go test -v -run Solidity=== RUN TestG1ToSoliditysuite_test.go:112: uint256 g1x = 0suite_test.go:114: uint256 g1y = 0suite_test.go:123: uint256 g1x = 6405964296151888589283369946297049615071462629409801671981178704280765222701suite_test.go:125: uint256 g1y = 24022460114782135406283456758820742407489033477860850282126363655584048101784--- PASS: TestG1ToSolidity (0.00s)PASS
On 3 Feb 2021, at 16:45, ChronosX88 <chron...@gmail.com> wrote:
Hello, Jeff.I'm Denis Davydov, the Software Engineer at Secured Finance. We are making cross-chain interoperability system called Dione, and in this project we are using Kyber as crypto library for creating BLS signatures. These signatures will be verified on Ethereum smart-contract side (there are precompiled contracts for doing this).
So, as far as I know, you are leading the Kyber library development at DEDIS. Do you know the person who is responsible for the BLS signature implementation? As I said, I need to verify BLS signatures on the side of Ethereum smart contracts, and for verification, input data (signature and public keys) must be in the form of ordinary decimal numbers. So, the question is how I can convert the points of BN256 curve to plain integer values to provide it to Ethereum smart-contracts?
I've tried to convert it by myself, looking at the code in pairing/bn256/point.go, but it didn't work - the Ethereum side is throwing the error "point not on curve".
The code for converting that I've written is provided below:
- G1 points:
func (p *pointG1) AffineCoords() []*big.Int {
p = p.Clone().(*pointG1)
pgtemp := *p.g
pgtemp.MakeAffine()
x := new(gfP)
xi := new(big.Int)
montDecode(x, &pgtemp.x)
bufX := make([]byte, 32)
x.Marshal(bufX)
xi.SetBytes(bufX)
y := new(gfP)
yi := new(big.Int)
montDecode(y, &pgtemp.y)
bufY := make([]byte, 32)
y.Marshal(bufY)
yi.SetBytes(bufY)
return []*big.Int{xi, yi}
}
- G2 points:
func (p *pointG2) AffineCoords() []*big.Int {
p = p.Clone().(*pointG2)
pgtemp := *p.g
pgtemp.MakeAffine()
xx := new(gfP)
xxi := new(big.Int)
montDecode(xx, &pgtemp.x.x)
bufXX := make([]byte, 32)
xx.Marshal(bufXX)
xxi.SetBytes(bufXX)
xy := new(gfP)
xyi := new(big.Int)
montDecode(xy, &pgtemp.x.y)
bufXY := make([]byte, 32)
xy.Marshal(bufXY)
xyi.SetBytes(bufXY)
yx := new(gfP)
yxi := new(big.Int)
montDecode(yx, &pgtemp.y.x)
bufYX := make([]byte, 32)
yx.Marshal(bufYX)
yxi.SetBytes(bufYX)
yy := new(gfP)
yyi := new(big.Int)
montDecode(yy, &pgtemp.y.y)
bufYY := make([]byte, 32)
yy.Marshal(bufYY)
yyi.SetBytes(bufYY)
return []*big.Int{xxi, xyi, yxi, yyi}
}If it's difficult to answer my question could you please recommend which person I can contact, who is responsible for the BLS signature implementation?
I appreciate your contribution to the Kyber library, that's very fascinating stuff. Looking forward to hearing back from you.P.S. Sorry for the second letter, don't know which email address is better to contact you.
Sincerely,
Denis Davydov
Software Engineer, Secured Finance.
On 4 Feb 2021, at 16:52, ChronosX88 <chron...@gmail.com> wrote:
Oh, thank you very much, Jeff. I think this is what I need. I will try and tell back about results. Thank you again!
On 4 Feb 2021, at 19:05, ChronosX88 <chron...@gmail.com> wrote:
So, for decoding the uint256 value I need to reproduce montDecode logic on the Solidity side? Are there any extra steps needed?
On 8 Feb 2021, at 16:10, ChronosX88 <chron...@gmail.com> wrote:
By the way, I want to ask you - what is montEncode/Decode? What is the algorithm inside these functions?
On 9 Feb 2021, at 12:00, Allen Jeffrey Richard <jeff....@epfl.ch> wrote:
Again, everything depends on your Solidity implementation.
I've tried your testing code, and it has somehow worked correctly:
bn256.G1(5dd340bac1fbcc639cc4e0521ba53f33d54400dd144eb4ed22b4a8f87a0af770,8aa2032034c8f9d6a93ef4c6e38563d5519979a090e35a79e4fbbc9fbcf1f0dc) =? bn256.G1(5dd340bac1fbcc639cc4e0521ba53f33d54400dd144eb4ed22b4a8f87a0af770, 8aa2032034c8f9d6a93ef4c6e38563d5519979a090e35a79e4fbbc9fbcf1f0dc)
I've used Cloudflare's bn256 library for comparing.
Sincerely,
Denis Davydov
Software Engineer, Secured Finance.
--
You received this message because you are subscribed to the Google Groups "Cothority Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cothority+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cothority/71c248a7-1543-d857-c515-5e357ffc8364%40gmail.com.
On 10 Feb 2021, at 07:58, Gasser Linus <linus....@epfl.ch> wrote:
Also: the golang.org one outputs decimal numbers, so you’ll have to convert them to hex numbers. Then it works.
At least for (un)marshalling. As soon as you start calculating, things fail of course. In Jeff’s test you can add the following between the unmarshalling and the t.Log:
g1.Add(g1, g1)
pa.Add(pa, pa)
With g1 from cloud flare’s bn256 implementation, it works. With g1 from golang's implementation, it fails.
So depending on what implementation you have in your solidity contract, it might work - or it might not ;) If you use the kyber library, you’ll have to make sure that the solidity contract does the montEncode in the unmarshalling, so it correctly interprets your points.
At least for (un)marshalling. As soon as you start calculating, things fail of course. In Jeff’s test you can add the following between the unmarshalling and the t.Log:
g1.Add(g1, g1)
pa.Add(pa, pa)
With g1 from cloud flare’s bn256 implementation, it works. With g1 from golang's implementation, it fails.
This is because Go’s bn256 implementation says this is not supported. See TestG1InteropAddSelf below.
On 12 Feb 2021, at 07:12, Gasser Linus <linus....@epfl.ch> wrote:
Oh my - didn’t go this far. Thanks for checking this out. So the go-bn256 _does_ correctly unmarshal the kyber-bn256? Because the ‘mountEncode’ is not in there, so I’m quite surprised.
Guys, what is twistB constant in bn256/twist.go?
var twistB = &gfP2{
gfP{0x75046774386b8d71, 0x5bd0854a46d36cf8,
0x664327a1d41c8414, 0x96c9abb932eeb2f},
gfP{0xb94f760fb4c5ee14, 0xdae9f8f24c3b6eb4,
0x77a675d2e52f4fe4, 0x736f31b09116c66b},
}
P.S. It is used for checking if G2 point is on curve. So I need to know what this constant does mean.
Sincerely,
Denis Davydov
Software Engineer, Secured Finance.