From 8b005194c2b74fc06101340d9e0885f1a5986a86 Mon Sep 17 00:00:00 2001 From: Ivo Kubjas Date: Wed, 4 Sep 2024 00:45:05 +0200 Subject: [PATCH] chore: explicit IO methods in interfaces (#1266) --- backend/groth16/groth16.go | 42 ++++++++++++++++++++++++++++---------- backend/plonk/plonk.go | 12 +++++++++++ 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/backend/groth16/groth16.go b/backend/groth16/groth16.go index 9cdf99eba..a56b5730a 100644 --- a/backend/groth16/groth16.go +++ b/backend/groth16/groth16.go @@ -55,26 +55,37 @@ import ( groth16_bw6761 "github.com/consensys/gnark/backend/groth16/bw6-761" ) -type groth16Object interface { - gnarkio.WriterRawTo - io.WriterTo - io.ReaderFrom - CurveID() ecc.ID -} - // Proof represents a Groth16 proof generated by groth16.Prove // // it's underlying implementation is curve specific (see gnark/internal/backend) type Proof interface { - groth16Object + CurveID() ecc.ID + + io.WriterTo + io.ReaderFrom + + // Raw methods for faster serialization-deserialization. Does not perform checks on the data. + // Only use if you are sure of the data you are reading comes from trusted source. + gnarkio.WriterRawTo } // ProvingKey represents a Groth16 ProvingKey // // it's underlying implementation is strongly typed with the curve (see gnark/internal/backend) type ProvingKey interface { - groth16Object + CurveID() ecc.ID + + io.WriterTo + io.ReaderFrom + + // Raw methods for faster serialization-deserialization. Does not perform checks on the data. + // Only use if you are sure of the data you are reading comes from trusted source. + gnarkio.WriterRawTo gnarkio.UnsafeReaderFrom + + // BinaryDumper is the interface that wraps the WriteDump and ReadDump + // methods. It performs a very fast and very unsafe memory dump writing and + // reading. gnarkio.BinaryDumper // NbG1 returns the number of G1 elements in the ProvingKey @@ -83,7 +94,8 @@ type ProvingKey interface { // NbG2 returns the number of G2 elements in the ProvingKey NbG2() int - IsDifferent(interface{}) bool + // IsDifferent compares against another proving key and returns true if they are different. + IsDifferent(any) bool } // VerifyingKey represents a Groth16 VerifyingKey @@ -92,8 +104,16 @@ type ProvingKey interface { // // ExportSolidity is implemented for BN254 and will return an error with other curves type VerifyingKey interface { - groth16Object + CurveID() ecc.ID + + io.WriterTo + io.ReaderFrom + + // Raw methods for faster serialization-deserialization. Does not perform checks on the data. + // Only use if you are sure of the data you are reading comes from trusted source. + gnarkio.WriterRawTo gnarkio.UnsafeReaderFrom + // VerifyingKey are the methods required for generating the Solidity // verifier contract from the VerifyingKey. This will return an error if not // supported on the CurveID(). diff --git a/backend/plonk/plonk.go b/backend/plonk/plonk.go index 60de0b8b3..6b19ef154 100644 --- a/backend/plonk/plonk.go +++ b/backend/plonk/plonk.go @@ -70,6 +70,9 @@ import ( type Proof interface { io.WriterTo io.ReaderFrom + + // Raw methods for faster serialization-deserialization. Does not perform checks on the data. + // Only use if you are sure of the data you are reading comes from trusted source. gnarkio.WriterRawTo } @@ -79,8 +82,13 @@ type Proof interface { type ProvingKey interface { io.WriterTo io.ReaderFrom + + // Raw methods for faster serialization-deserialization. Does not perform checks on the data. + // Only use if you are sure of the data you are reading comes from trusted source. gnarkio.WriterRawTo gnarkio.UnsafeReaderFrom + + // VerifyingKey returns the corresponding VerifyingKey. VerifyingKey() interface{} } @@ -90,8 +98,12 @@ type ProvingKey interface { type VerifyingKey interface { io.WriterTo io.ReaderFrom + + // Raw methods for faster serialization-deserialization. Does not perform checks on the data. + // Only use if you are sure of the data you are reading comes from trusted source. gnarkio.WriterRawTo gnarkio.UnsafeReaderFrom + // VerifyingKey are the methods required for generating the Solidity // verifier contract from the VerifyingKey. This will return an error if not // supported on the CurveID().