pub fn build_tx<F>(
        program: Program,
        header: TxHeader,
        bp_gens: &BulletproofGens,
        sign_tx_fn: F,
    ) -> Result<(Tx, TxID, TxLog), VMError>
    where
        F: FnOnce(&mut Transcript, &Vec<VerificationKey>) -> Result<Signature, VMError>,
    {
        // Prepare the constraint system
        let mut r1cs_transcript = Transcript::new(b"ZkVM.r1cs");
        let pc_gens = PedersenGens::default();
        let cs = r1cs::Prover::new(&pc_gens, &mut r1cs_transcript);

        // Serialize the tx program
        let mut bytecode = Vec::new();
        program.encode(&mut bytecode);

        let mut prover = Prover {
            signtx_keys: Vec::new(),
            cs,
        };

        let vm = VM::new(
            header,
            ProverRun {
                program: program.to_vec().into(),
            },
            &mut prover,
        );

        let (txid, txlog) = vm.run()?;

        // Sign txid
        // TBD: implement holistic Signer trait/interface for tx signing
        let mut signtx_transcript = Transcript::new(b"ZkVM.signtx");
        signtx_transcript.commit_bytes(b"txid", &txid.0);
        // TODO: change this to use multi-message context
        let signature = sign_tx_fn(&mut signtx_transcript, &prover.signtx_keys)?;

        // Generate the R1CS proof
        let proof = prover
            .cs
            .prove(bp_gens)
            .map_err(|_| VMError::InvalidR1CSProof)?;

        Ok((
            Tx {
                header,
                signature,
                proof,
                program: bytecode,
            },
            txid,
            txlog,
        ))
    }
/// Builds a transaction with a given list of instructions and a `TxHeader`.
/// Returns a transaction `Tx` along with its ID (`TxID`) and a transaction log (`TxLog`).
/// Fails if the input program is malformed, or some witness data is missing.
Builds a transaction with a given list of instructions and a `TxHeader`.
Builds a transaction with a given list of instructions and a ` TxHeader ` .
pub fn build_tx<F>(
        program: Program,
        header: TxHeader,
        bp_gens: &BulletproofGens,
        sign_tx_fn: F,
    ) -> Result<(Tx, TxID, TxLog), VMError>
    where
        F: FnOnce(&mut Transcript, &Vec<VerificationKey>) -> Result<Signature, VMError>,
    {
        // Prepare the constraint system
        let mut r1cs_transcript = Transcript::new(b"ZkVM.r1cs");
        let pc_gens = PedersenGens::default();
        let cs = r1cs::Prover::new(&pc_gens, &mut r1cs_transcript);
        // Serialize the tx program
        let mut bytecode = Vec::new();
        program.encode(&mut bytecode);
        let mut prover = Prover {
            signtx_keys: Vec::new(),
            cs,
        };
        let vm = VM::new(
            header,
            ProverRun {
                program: program.to_vec().into(),
            },
            &mut prover,
        );
        let (txid, txlog) = vm.run()?;
        // Sign txid
        // TBD: implement holistic Signer trait/interface for tx signing
        let mut signtx_transcript = Transcript::new(b"ZkVM.signtx");
        signtx_transcript.commit_bytes(b"txid", &txid.0);
        // TODO: change this to use multi-message context
        let signature = sign_tx_fn(&mut signtx_transcript, &prover.signtx_keys)?;
        // Generate the R1CS proof
        let proof = prover
            .cs
            .prove(bp_gens)
            .map_err(|_| VMError::InvalidR1CSProof)?;
        Ok((
            Tx {
                header,
                signature,
                proof,
                program: bytecode,
            },
            txid,
            txlog,
        ))
    }
pub fn build_tx < F > ( program : Program , header : TxHeader , bp_gens : & BulletproofGens , sign_tx_fn : F , ) -> Result < ( Tx , TxID , TxLog ) , VMError > where F : FnOnce ( & mut Transcript , & Vec < VerificationKey > ) -> Result < Signature , VMError > , { // Prepare the constraint system let mut r1cs_transcript = Transcript :: new ( b" " ) ; let pc_gens = PedersenGens :: default ( ) ; let cs = r1cs :: Prover :: new ( & pc_gens , & mut r1cs_transcript ) ; // Serialize the tx program let mut bytecode = Vec :: new ( ) ; program . encode ( & mut bytecode ) ; let mut prover = Prover { signtx_keys : Vec :: new ( ) , cs , } ; let vm = VM :: new ( header , ProverRun { program : program . to_vec ( ) . into ( ) , } , & mut prover , ) ; let ( txid , txlog ) = vm . run ( ) ? ; // Sign txid // TBD: implement holistic Signer trait/interface for tx signing let mut signtx_transcript = Transcript :: new ( b" " ) ; signtx_transcript . commit_bytes ( b" " , & txid . 0 ) ; // TODO: change this to use multi-message context let signature = sign_tx_fn ( & mut signtx_transcript , & prover . signtx_keys ) ? ; // Generate the R1CS proof let proof = prover . cs . prove ( bp_gens ) . map_err ( | _ | VMError :: InvalidR1CSProof ) ? ; Ok ( ( Tx { header , signature , proof , program : bytecode , } , txid , txlog , ) ) }
Builds a transaction with a given list of instructions and a `TxHeader`.
Builds a transaction with a given list of instructions and a ` TxHeader ` .
program
Program
header
TxHeader
bp_gens
&BulletproofGens
sign_tx_fn
F
program
Program
header
TxHeader
bp_gens
&BulletproofGens
sign_tx_fn
F