Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next #210

Merged
merged 23 commits into from
Sep 4, 2023
Merged

Next #210

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
54052c0
get rid of ValidityPredicateConfig trait and use the concrete Validit…
XuyangSong Aug 18, 2023
44a84fa
get rid of ValidityPredicateInfo trait
XuyangSong Aug 18, 2023
813f816
rename app_vp_verifying_info_dynamic to dynamic_vps
XuyangSong Aug 18, 2023
4d887a9
rename app_vp_verifying_info to application_vp
XuyangSong Aug 18, 2023
eb3a0e2
fix bench
XuyangSong Aug 18, 2023
17b0be0
Add Rustler as a dependency
mariari Aug 4, 2023
05e6cda
Specify the the specific topic branch for patch.crates-io
mariari Aug 25, 2023
0e65d03
Change Pasta Curve to use a more NIF friendly crate
mariari Aug 4, 2023
e0b9cea
Add Nif derivication encodings for types that can be derieved
mariari Aug 4, 2023
56fb46e
Create proxy Types to Allow easier derivation
mariari Aug 7, 2023
5123828
Implement Encoder and Decoder for Transaction
mariari Aug 8, 2023
85fa6ed
Made the BEAM NIF integration locked behind a feature flag
mariari Aug 25, 2023
00c86ca
Bump the rust toolchain version
mariari Aug 25, 2023
64a6fa8
Merge branch 'mariari/bump-rust-toolchain'
mariari Aug 28, 2023
5892ad0
Merge branch 'mariari/specify-branch-of-patched-files' into next
mariari Aug 28, 2023
fc9717a
Merge branch 'xuyang/simplify_vp_trait' into next
mariari Aug 28, 2023
cba8398
Merge branch 'mariari/nifing' into next
mariari Aug 28, 2023
3875554
add serde as a mode of serialization, put both serde and borash behin…
bazzilic Aug 28, 2023
6b8a181
fix tests
bazzilic Aug 28, 2023
1029ab9
pasta_curves enables serde option only if taiga has serde option enabled
bazzilic Aug 28, 2023
1451b4f
transaction test
bazzilic Aug 30, 2023
6f4b6be
serialization and hash for NoteCommitment
bazzilic Aug 30, 2023
1dc8911
Merge branch vasily/serde
mariari Aug 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.67.1
1.72.0
22 changes: 16 additions & 6 deletions taiga_halo2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@ version = "0.1.0"
edition = "2021"

[dependencies]
rustler = {version = "0.29.1", optional = true}
rand = "0.8"
lazy_static = "1.4"
blake2b_simd = "1.0"
pasta_curves = "0.5.1"
pasta_curves = {git = "https://github.com/heliaxdev/pasta_curves", branch = "taiga", features = ["repr-erlang"]}
ff = "0.13"
group = "0.13"
halo2_gadgets = { version = "0.3", features = ["test-dependencies"] }
halo2_proofs = { version = "0.3", features = ["dev-graph"] }
halo2_gadgets = {git = "https://github.com/heliaxdev/halo2", branch = "taiga", features = ["test-dependencies"]}
halo2_proofs = {git = "https://github.com/heliaxdev/halo2", branch = "taiga", features = ["dev-graph"]}
bitvec = "1.0"
subtle = { version = "2.3", default-features = false }
dyn-clone = "1.0"
reddsa = {git = "https://github.com/heliaxdev/reddsa.git", branch = "taiga"}
vamp-ir = { git = "https://github.com/anoma/vamp-ir.git", rev = "6d401f8a479951727586ef0c44c42edab3139090"}
bincode = "2.0.0-rc.3"
borsh = { version = "0.10", features = ["const-generics"] }
byteorder = "1.4"
num-bigint = "0.4"

serde = { version = "1.0", features = ["derive"], optional = true }
borsh = { version = "0.10", features = ["const-generics"], optional = true }

[dev-dependencies]
criterion = "0.5"
proptest = "1.2"
serde_json = "1.0"

[[bench]]
name = "action_proof"
Expand All @@ -34,8 +38,14 @@ harness = false
name = "vp_proof"
harness = false

[[example]]
name = "taiga_sudoku"
# [[example]]
# name = "taiga_sudoku"

[[example]]
name = "tx_examples"

[features]
default = ["borsh", "serde"]
nif = ["rustler", "pasta_curves/repr-erlang"]
serde = ["dep:serde", "pasta_curves/serde"]
borsh = ["dep:borsh"]
9 changes: 5 additions & 4 deletions taiga_halo2/benches/vp_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use pasta_curves::pallas;
use rand::rngs::OsRng;
use rand::Rng;
use taiga_halo2::{
circuit::{vp_circuit::ValidityPredicateInfo, vp_examples::TrivialValidityPredicateCircuit},
circuit::{vp_circuit::ValidityPredicateCircuit, vp_examples::TrivialValidityPredicateCircuit},
constant::{NUM_NOTE, SETUP_PARAMS_MAP},
note::{Note, NoteType, RandomSeed},
nullifier::{Nullifier, NullifierKeyContainer},
Expand Down Expand Up @@ -87,7 +87,8 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {
vp_circuit.clone(),
&[public_inputs.inner()],
&mut rng,
);
)
.unwrap();
})
});

Expand All @@ -105,9 +106,9 @@ fn bench_vp_proof(name: &str, c: &mut Criterion) {
let verifier_name = name.to_string() + "-verifier";
c.bench_function(&verifier_name, |b| {
b.iter(|| {
proof
assert!(proof
.verify(pk.get_vk(), &params, &[public_inputs.inner()])
.is_ok();
.is_ok());
})
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,6 @@ pub struct SudokuVPConfig {
sudoku_config: SudokuConfig,
}

impl ValidityPredicateConfig for SudokuVPConfig {
fn get_note_config(&self) -> NoteConfig {
self.note_config.clone()
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self {
let note_config = Self::configure_note(meta);
let sudoku_config = SudokuCircuit::configure(meta);
Self {
note_config,
sudoku_config,
}
}
}

#[derive(Clone, Debug, Default)]
pub struct SudokuVP {
pub sudoku: SudokuCircuit,
Expand All @@ -53,11 +38,9 @@ pub struct SudokuVP {
}

impl ValidityPredicateCircuit for SudokuVP {
type VPConfig = SudokuVPConfig;

fn custom_constraints(
&self,
config: Self::VPConfig,
config: ValidityPredicateConfig,
layouter: impl Layouter<pallas::Base>,
_basic_variables: BasicValidityPredicateVariables,
) -> Result<(), plonk::Error> {
Expand Down
20 changes: 16 additions & 4 deletions taiga_halo2/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ use crate::{
nullifier::Nullifier,
value_commitment::ValueCommitment,
};
use borsh::{BorshDeserialize, BorshSerialize};
use ff::PrimeField;
use halo2_proofs::arithmetic::Field;
use pasta_curves::pallas;
use rand::RngCore;
use std::io;
#[cfg(feature = "nif")]
use rustler::NifStruct;
#[cfg(feature = "serde")]
use serde;

#[cfg(feature = "borsh")]
use borsh::{BorshDeserialize, BorshSerialize};

/// The action result used in transaction.
#[derive(Copy, Debug, Clone)]
#[cfg_attr(feature = "nif", derive(NifStruct))]
#[cfg_attr(feature = "nif", module = "Taiga.Action.Instance")]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ActionInstance {
/// The root of the note commitment Merkle tree.
pub anchor: pallas::Base,
Expand Down Expand Up @@ -46,8 +53,10 @@ impl ActionInstance {
}
}

#[cfg(feature = "borsh")]
impl BorshSerialize for ActionInstance {
fn serialize<W: std::io::Write>(&self, writer: &mut W) -> borsh::maybestd::io::Result<()> {
use ff::PrimeField;
writer.write_all(&self.anchor.to_repr())?;
writer.write_all(&self.nf.to_bytes())?;
writer.write_all(&self.cm_x.to_repr())?;
Expand All @@ -56,8 +65,11 @@ impl BorshSerialize for ActionInstance {
}
}

#[cfg(feature = "borsh")]
impl BorshDeserialize for ActionInstance {
fn deserialize_reader<R: io::Read>(reader: &mut R) -> io::Result<Self> {
fn deserialize_reader<R: std::io::Read>(reader: &mut R) -> std::io::Result<Self> {
use ff::PrimeField;
use std::io;
let anchor_bytes = <[u8; 32]>::deserialize_reader(reader)?;
let anchor = Option::from(pallas::Base::from_repr(anchor_bytes))
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, "anchor not in field"))?;
Expand Down
22 changes: 17 additions & 5 deletions taiga_halo2/src/binding_signature.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use crate::constant::NOTE_COMMITMENT_R_GENERATOR;
use borsh::{BorshDeserialize, BorshSerialize};
use pasta_curves::group::cofactor::CofactorCurveAffine;
use pasta_curves::group::{ff::PrimeField, GroupEncoding};
use pasta_curves::pallas;
use rand::{CryptoRng, RngCore};
use reddsa::{private, Error, SigType, Signature, SigningKey, VerificationKey};
use std::io;

#[cfg(feature = "serde")]
use serde;

#[cfg(feature = "borsh")]
use borsh::{BorshDeserialize, BorshSerialize};

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum TaigaBinding {}
Expand All @@ -29,12 +33,15 @@ impl private::Sealed<TaigaBinding> for TaigaBinding {
impl SigType for TaigaBinding {}

#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BindingSignature(Signature<TaigaBinding>);

#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BindingSigningKey(SigningKey<TaigaBinding>);

#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BindingVerificationKey(VerificationKey<TaigaBinding>);

impl BindingSignature {
Expand All @@ -48,14 +55,16 @@ impl BindingSignature {
}
}

#[cfg(feature = "borsh")]
impl BorshSerialize for BindingSignature {
fn serialize<W: std::io::Write>(&self, writer: &mut W) -> borsh::maybestd::io::Result<()> {
fn serialize<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
writer.write_all(&self.to_bytes())
}
}

#[cfg(feature = "borsh")]
impl BorshDeserialize for BindingSignature {
fn deserialize_reader<R: io::Read>(reader: &mut R) -> io::Result<Self> {
fn deserialize_reader<R: std::io::Read>(reader: &mut R) -> std::io::Result<Self> {
let mut sig_bytes = [0u8; 64];
reader.read_exact(&mut sig_bytes)?;
Ok(Self::from_bytes(sig_bytes))
Expand All @@ -81,14 +90,17 @@ impl BindingSigningKey {
}
}

#[cfg(feature = "borsh")]
impl BorshSerialize for BindingSigningKey {
fn serialize<W: std::io::Write>(&self, writer: &mut W) -> borsh::maybestd::io::Result<()> {
writer.write_all(&self.to_bytes())
}
}

#[cfg(feature = "borsh")]
impl BorshDeserialize for BindingSigningKey {
fn deserialize_reader<R: io::Read>(reader: &mut R) -> io::Result<Self> {
fn deserialize_reader<R: std::io::Read>(reader: &mut R) -> std::io::Result<Self> {
use std::io;
let mut key_bytes = [0u8; 32];
reader.read_exact(&mut key_bytes)?;
Self::from_bytes(key_bytes).map_err(|_| {
Expand Down
Loading
Loading