txivc

package
v0.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InnerCurve = ecc.BLS12_377
View Source
var OuterCurve = ecc.BW6_761

Functions

func ComputeProof

func ComputeProof(ccs constraint.ConstraintSystem, provingKey native_groth16.ProvingKey, outerWitness witness.Witness) (native_groth16.Proof, error)

func CreateBaseCaseFullWitness added in v0.1.4

func CreateBaseCaseFullWitness(
	rawTxBytes []byte,
	currTxId []byte,
) (witness.Witness, error)

func CreateBaseCaseLightWitness added in v0.1.4

func CreateBaseCaseLightWitness(
	currTxId []byte,
	innerField *big.Int,
) (witness.Witness, error)

func CreateNormalFullWitness added in v0.1.4

func CreateNormalFullWitness(
	innerWitness witness.Witness,
	innerProof native_groth16.Proof,
	innerVk native_groth16.VerifyingKey,
	prefixBytes []byte, prevTxnIdBytes []byte, postFixBytes []byte, currTxId []byte, field *big.Int) (witness.Witness, error)

* Full witness is used for generating a new proof

func CreateNormalLightWitness added in v0.1.4

func CreateNormalLightWitness(txId []byte, outerField *big.Int) (witness.Witness, error)

* Light witness is used for verification of an existing proof. I.e. only public params are filled.

func SetupNormalCase

func SetupNormalCase(prefixSize int, postfixSize int, outerField *big.Int, parentCcs constraint.ConstraintSystem) (constraint.ConstraintSystem, native_groth16.ProvingKey, native_groth16.VerifyingKey, error)

func SliceTx added in v0.1.9

func SliceTx(rawTx []byte, inputIndex int) ([]byte, []byte, []byte, error)

Split a Raw Transaction into it's component "prefix", "suffix" and "postfix" parts

inputIndex - the index of the input that

func UnmarshalProof added in v0.1.9

func UnmarshalProof(proof string, curveId ecc.ID) (native_groth16.Proof, error)

func VerifyProof

func VerifyProof(pubWitness witness.Witness, genesisProof native_groth16.Proof, verifyingKey native_groth16.VerifyingKey) bool

Types

type BaseProofInfo added in v0.1.4

type BaseProofInfo struct {
	RawTx string `json:"raw_tx" binding:"required"`
}

type G1Affine

type G1Affine = sw_bls12377.G1Affine

type G2Affine

type G2Affine = sw_bls12377.G2Affine

type GTEl

type GTEl = sw_bls12377.GT

type NormalProofInfo added in v0.1.4

type NormalProofInfo struct {
	RawTx        string `json:"raw_tx" binding:"required"`
	InputIndex   int    `json:"input_index"`
	IsParentBase bool   `json:"is_parent_base"`
	Proof        string `json:"proof" binding:"required"`
}

type ScalarField

type ScalarField = sw_bls12377.ScalarField

type Sha256Circuit

type Sha256Circuit[FR emulated.FieldParams, G1El algebra.G1ElementT, G2El algebra.G2ElementT, GtEl algebra.GtElementT] struct {
	PreviousProof   stdgroth16.Proof[G1El, G2El]
	PreviousVk      stdgroth16.VerifyingKey[G1El, G2El, GtEl]
	PreviousWitness stdgroth16.Witness[FR]

	CurrTxPrefix []frontend.Variable //5
	PrevTxId     []frontend.Variable //32
	CurrTxPost   []frontend.Variable //188

	//double-sha256 hash of the concatenation of above fields. Not reversed, so not quite a TxId
	CurrTxId []frontend.Variable `gnark:",public"` //probably needs to provide the reversed version to save circuit space
}

* General case to continue with proofs

func (*Sha256Circuit[FR, G1El, G2El, GtEl]) Define

func (circuit *Sha256Circuit[FR, G1El, G2El, GtEl]) Define(api frontend.API) error

type Sha256CircuitBaseCase

type Sha256CircuitBaseCase struct {
	RawTx []frontend.Variable

	//double-sha256 hash of the concatenation of above fields. Not reversed, so not quite a TxId
	CurrTxId []frontend.Variable `gnark:",public"` //probably needs to provide the reversed version to save circuit space
}

* Base case to generate initial proof to get things started

func (*Sha256CircuitBaseCase) Define

func (circuit *Sha256CircuitBaseCase) Define(api frontend.API) error

* Base case implementation

type Sha256InnerCircuit

type Sha256InnerCircuit struct {
	CurrTxPrefix [5]uints.U8 //5
	PrevTxId     [32]uints.U8
	CurrTxPost   [154]uints.U8 //81

	//double-sha256 hash of the concatenation of above fields. Not reversed, so not quite a TxId
	CurrTxId [32]uints.U8 `gnark:",public"` //probably needs to provide the reversed version to save circuit space
}

circuit that proves in zero knowledge that there exists a Transaction with Id == CurrTxId which is composed of sha256(sha256(CurrTxPrefix || PrevTxId || CurrTxPost))

func (*Sha256InnerCircuit) Define

func (circuit *Sha256InnerCircuit) Define(api frontend.API) error

type Sha256OuterCircuit

type Sha256OuterCircuit[FR emulated.FieldParams, G1El algebra.G1ElementT, G2El algebra.G2ElementT, GtEl algebra.GtElementT] struct {
	Proof        stdplonk.Proof[FR, G1El, G2El]
	VerifyingKey stdplonk.VerifyingKey[FR, G1El, G2El] `gnark:"-"` // constant verification key
	InnerWitness stdplonk.Witness[FR]                  `gnark:",public"`

	/* The PrevTxId of the Outer Circuit must be matched and equal to the CurrTxId of the InnerProof.
	   Because the InnerProof that we are verifying for the current Transaction
	   was actually generated in/for the parent transaction (in who's context it was the )

	   Furthermore, both of the following must be public, because the verifying wallet
	   will need to look at current Txn, extract these public values.
	   And use them to validate the provided Outer PreviousProof.
	*/
	PrevTxId [32]uints.U8 `gnark:",public"`
}

func (*Sha256OuterCircuit[FR, G1El, G2El, GtEl]) Define

func (circuit *Sha256OuterCircuit[FR, G1El, G2El, GtEl]) Define(api frontend.API) error

*

The outer circuit for our recursive proof that accumulates a chain of transactions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL