Skip to content

Commit

Permalink
chore: explicit IO methods in interfaces (#1266)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivokub committed Sep 3, 2024
1 parent 1f7f38f commit 8b00519
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
42 changes: 31 additions & 11 deletions backend/groth16/groth16.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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().
Expand Down
12 changes: 12 additions & 0 deletions backend/plonk/plonk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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{}
}

Expand All @@ -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().
Expand Down

0 comments on commit 8b00519

Please sign in to comment.