mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
crypto: Rename Spend to Burn.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::{io, time::Instant};
|
||||
use std::time::Instant;
|
||||
|
||||
use halo2_gadgets::primitives::{
|
||||
poseidon,
|
||||
@@ -20,13 +20,13 @@ use crate::{
|
||||
merkle_node::MerkleNode,
|
||||
types::*,
|
||||
},
|
||||
util::serial::{Decodable, Encodable},
|
||||
zk::circuit::spend_contract::SpendContract,
|
||||
util::serial::{SerialDecodable, SerialEncodable},
|
||||
zk::circuit::burn_contract::BurnContract,
|
||||
Result,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct SpendRevealedValues {
|
||||
#[derive(Debug, Clone, PartialEq, SerialEncodable, SerialDecodable)]
|
||||
pub struct BurnRevealedValues {
|
||||
pub value_commit: DrkValueCommit,
|
||||
pub token_commit: DrkValueCommit,
|
||||
pub nullifier: Nullifier,
|
||||
@@ -34,7 +34,7 @@ pub struct SpendRevealedValues {
|
||||
pub signature_public: PublicKey,
|
||||
}
|
||||
|
||||
impl SpendRevealedValues {
|
||||
impl BurnRevealedValues {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn compute(
|
||||
value: u64,
|
||||
@@ -77,7 +77,7 @@ impl SpendRevealedValues {
|
||||
let value_commit = pedersen_commitment_u64(value, value_blind);
|
||||
let token_commit = pedersen_commitment_scalar(mod_r_p(token_id), token_blind);
|
||||
|
||||
SpendRevealedValues {
|
||||
BurnRevealedValues {
|
||||
value_commit,
|
||||
token_commit,
|
||||
nullifier: Nullifier(nullifier),
|
||||
@@ -107,32 +107,8 @@ impl SpendRevealedValues {
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for SpendRevealedValues {
|
||||
fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
|
||||
let mut len = 0;
|
||||
len += self.value_commit.encode(&mut s)?;
|
||||
len += self.token_commit.encode(&mut s)?;
|
||||
len += self.nullifier.encode(&mut s)?;
|
||||
len += self.merkle_root.encode(&mut s)?;
|
||||
len += self.signature_public.encode(s)?;
|
||||
Ok(len)
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for SpendRevealedValues {
|
||||
fn decode<D: io::Read>(mut d: D) -> Result<Self> {
|
||||
Ok(Self {
|
||||
value_commit: Decodable::decode(&mut d)?,
|
||||
token_commit: Decodable::decode(&mut d)?,
|
||||
nullifier: Decodable::decode(&mut d)?,
|
||||
merkle_root: Decodable::decode(&mut d)?,
|
||||
signature_public: Decodable::decode(d)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn create_spend_proof(
|
||||
pub fn create_burn_proof(
|
||||
pk: &ProvingKey,
|
||||
value: u64,
|
||||
token_id: DrkTokenId,
|
||||
@@ -144,8 +120,8 @@ pub fn create_spend_proof(
|
||||
leaf_position: incrementalmerkletree::Position,
|
||||
merkle_path: Vec<MerkleNode>,
|
||||
signature_secret: SecretKey,
|
||||
) -> Result<(Proof, SpendRevealedValues)> {
|
||||
let revealed = SpendRevealedValues::compute(
|
||||
) -> Result<(Proof, BurnRevealedValues)> {
|
||||
let revealed = BurnRevealedValues::compute(
|
||||
value,
|
||||
token_id,
|
||||
value_blind,
|
||||
@@ -160,7 +136,7 @@ pub fn create_spend_proof(
|
||||
|
||||
let leaf_position: u64 = leaf_position.into();
|
||||
|
||||
let c = SpendContract {
|
||||
let c = BurnContract {
|
||||
secret_key: Some(secret.0),
|
||||
serial: Some(serial),
|
||||
value: Some(DrkValue::from(value)),
|
||||
@@ -181,10 +157,10 @@ pub fn create_spend_proof(
|
||||
Ok((proof, revealed))
|
||||
}
|
||||
|
||||
pub fn verify_spend_proof(
|
||||
pub fn verify_burn_proof(
|
||||
vk: &VerifyingKey,
|
||||
proof: Proof,
|
||||
revealed: &SpendRevealedValues,
|
||||
proof: &Proof,
|
||||
revealed: &BurnRevealedValues,
|
||||
) -> Result<()> {
|
||||
let public_inputs = revealed.make_outputs();
|
||||
Ok(proof.verify(vk, &public_inputs)?)
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{io, time::Instant};
|
||||
use std::time::Instant;
|
||||
|
||||
use halo2_gadgets::primitives::{
|
||||
poseidon,
|
||||
@@ -16,12 +16,12 @@ use crate::{
|
||||
types::{DrkCoinBlind, DrkSerial, DrkTokenId, DrkValue, DrkValueBlind, DrkValueCommit},
|
||||
util::{mod_r_p, pedersen_commitment_scalar, pedersen_commitment_u64},
|
||||
},
|
||||
util::serial::{Decodable, Encodable},
|
||||
util::serial::{SerialDecodable, SerialEncodable},
|
||||
zk::circuit::mint_contract::MintContract,
|
||||
Result,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, SerialEncodable, SerialDecodable)]
|
||||
pub struct MintRevealedValues {
|
||||
pub value_commit: DrkValueCommit,
|
||||
pub token_commit: DrkValueCommit,
|
||||
@@ -66,26 +66,6 @@ impl MintRevealedValues {
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for MintRevealedValues {
|
||||
fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
|
||||
let mut len = 0;
|
||||
len += self.value_commit.encode(&mut s)?;
|
||||
len += self.token_commit.encode(&mut s)?;
|
||||
len += self.coin.encode(&mut s)?;
|
||||
Ok(len)
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for MintRevealedValues {
|
||||
fn decode<D: io::Read>(mut d: D) -> Result<Self> {
|
||||
Ok(Self {
|
||||
value_commit: Decodable::decode(&mut d)?,
|
||||
token_commit: Decodable::decode(&mut d)?,
|
||||
coin: Decodable::decode(d)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn create_mint_proof(
|
||||
pk: &ProvingKey,
|
||||
|
||||
@@ -4,21 +4,21 @@ pub mod constants;
|
||||
pub mod diffie_hellman;
|
||||
pub mod keypair;
|
||||
//pub mod loader;
|
||||
pub mod burn_proof;
|
||||
pub mod merkle_node;
|
||||
pub mod mint_proof;
|
||||
pub mod note;
|
||||
pub mod nullifier;
|
||||
pub mod proof;
|
||||
pub mod schnorr;
|
||||
pub mod spend_proof;
|
||||
pub mod token_id;
|
||||
pub mod token_list;
|
||||
pub mod types;
|
||||
pub mod util;
|
||||
|
||||
pub use burn_proof::BurnRevealedValues;
|
||||
pub use mint_proof::MintRevealedValues;
|
||||
pub use proof::Proof;
|
||||
pub use spend_proof::SpendRevealedValues;
|
||||
|
||||
use keypair::SecretKey;
|
||||
|
||||
@@ -28,6 +28,7 @@ pub struct OwnCoin {
|
||||
pub note: note::Note,
|
||||
pub secret: SecretKey,
|
||||
pub nullifier: nullifier::Nullifier,
|
||||
pub leaf_position: incrementalmerkletree::Position,
|
||||
}
|
||||
|
||||
pub type OwnCoins = Vec<OwnCoin>;
|
||||
|
||||
@@ -31,7 +31,7 @@ use crate::crypto::{
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SpendConfig {
|
||||
pub struct BurnConfig {
|
||||
primary: Column<InstanceColumn>,
|
||||
advices: [Column<Advice>; 10],
|
||||
ecc_config: EccConfig<OrchardFixedBases>,
|
||||
@@ -44,7 +44,7 @@ pub struct SpendConfig {
|
||||
poseidon_config: PoseidonConfig<pallas::Base, 3, 2>,
|
||||
}
|
||||
|
||||
impl SpendConfig {
|
||||
impl BurnConfig {
|
||||
fn ecc_chip(&self) -> EccChip<OrchardFixedBases> {
|
||||
EccChip::construct(self.ecc_config.clone())
|
||||
}
|
||||
@@ -91,7 +91,7 @@ const BURN_SIGKEYX_OFFSET: usize = 6;
|
||||
const BURN_SIGKEYY_OFFSET: usize = 7;
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct SpendContract {
|
||||
pub struct BurnContract {
|
||||
pub secret_key: Option<pallas::Base>,
|
||||
pub serial: Option<pallas::Base>,
|
||||
pub value: Option<pallas::Base>,
|
||||
@@ -105,12 +105,12 @@ pub struct SpendContract {
|
||||
pub sig_secret: Option<pallas::Base>,
|
||||
}
|
||||
|
||||
impl UtilitiesInstructions<pallas::Base> for SpendContract {
|
||||
impl UtilitiesInstructions<pallas::Base> for BurnContract {
|
||||
type Var = AssignedCell<Fp, Fp>;
|
||||
}
|
||||
|
||||
impl Circuit<pallas::Base> for SpendContract {
|
||||
type Config = SpendConfig;
|
||||
impl Circuit<pallas::Base> for BurnContract {
|
||||
type Config = BurnConfig;
|
||||
type FloorPlanner = SimpleFloorPlanner;
|
||||
|
||||
fn without_witnesses(&self) -> Self {
|
||||
@@ -218,7 +218,7 @@ impl Circuit<pallas::Base> for SpendContract {
|
||||
(sinsemilla_config_2, merkle_config_2)
|
||||
};
|
||||
|
||||
SpendConfig {
|
||||
BurnConfig {
|
||||
primary,
|
||||
advices,
|
||||
ecc_config,
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod mint_contract;
|
||||
pub mod spend_contract;
|
||||
pub mod burn_contract;
|
||||
pub use burn_contract::BurnContract;
|
||||
|
||||
pub mod mint_contract;
|
||||
pub use mint_contract::MintContract;
|
||||
pub use spend_contract::SpendContract;
|
||||
|
||||
Reference in New Issue
Block a user