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 (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); }