private (Bn128Fp, Bn128Fp2) DecodePair(byte[] input, int offset) { byte[] x = input.Slice(offset + 0, 32); byte[] y = input.Slice(offset + 32, 32); Bn128Fp p1 = Bn128Fp.CreateInG1(x, y); // fail if point is invalid if (p1 == null) { return(null, null); } // (b, a) byte[] b = input.Slice(offset + 64, 32); byte[] a = input.Slice(offset + 96, 32); // (d, c) byte[] d = input.Slice(offset + 128, 32); byte[] c = input.Slice(offset + 160, 32); Bn128Fp2 p2 = Bn128Fp2.CreateInG2(a, b, c, d); // fail if point is invalid if (p2 == null) { return(null, null); } return(p1, p2); }
public (byte[], bool) Run(byte[] inputData) { if (inputData == null) { inputData = Bytes.Empty; } if (inputData.Length < 96) { inputData = inputData.PadRight(96); } byte[] x = inputData.Slice(0, 32); byte[] y = inputData.Slice(32, 32); byte[] s = inputData.Slice(64, 32); Bn128Fp p = Bn128Fp.Create(x, y); if (p == null) { return(Bytes.Empty, false); } Bn128Fp res = p.Mul(s.ToUnsignedBigInteger()).ToEthNotation(); return(EncodeResult(res.X.GetBytes(), res.Y.GetBytes()), true); }
public void Zero_reused() { Bn128Fp p1 = Bn128Fp.Create(new byte[] { 0 }, new byte[] { 0 }); // ReSharper disable once EqualExpressionComparison Assert.True(ReferenceEquals(p1.Zero, p1.Zero)); }
public void Equals_works_with_nulls() { Bn128Fp bn128Fp = new Bn128Fp(1, 1, 1); Assert.False(bn128Fp == null, "null to the right"); Assert.False(null == bn128Fp, "null to the left"); Assert.True((Bn128Fp)null == null, "null both sides"); }
public (byte[], bool) Run(byte[] inputData) { Metrics.Bn128AddPrecompile++; if (inputData == null) { inputData = Bytes.Empty; } if (inputData.Length < 128) { inputData = inputData.PadRight(128); } byte[] x1 = inputData.Slice(0, 32); byte[] y1 = inputData.Slice(32, 32); byte[] x2 = inputData.Slice(64, 32); byte[] y2 = inputData.Slice(96, 32); Bn128Fp p1 = Bn128Fp.Create(x1, y1); if (p1 == null) { return(Bytes.Empty, false); } Bn128Fp p2 = Bn128Fp.Create(x2, y2); if (p2 == null) { return(Bytes.Empty, false); } Bn128Fp res = p1.Add(p2).ToEthNotation(); return(EncodeResult(res.X.GetBytes(), res.Y.GetBytes()), true); }
public void Zero_initializes() { Bn128Fp p1 = Bn128Fp.Create(new byte[] { 0 }, new byte[] { 0 }); Assert.NotNull(p1.Zero); }