Skip to content

Commit

Permalink
drop custom implementations of BFieldCodec; derive it everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
aszepieniec committed Jul 25, 2023
1 parent edaadb9 commit 8ee3465
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 36 deletions.
32 changes: 1 addition & 31 deletions src/models/blockchain/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,44 +103,14 @@ impl GetSize for SingleProof {

// TODO: Remove this allow once `ValidityLogic` is more sane
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, GetSize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, GetSize, BFieldCodec)]
pub enum Witness {
Primitive(PrimitiveWitness),
SingleProof(SingleProof),
ValidityLogic((TransactionValidityLogic, PrimitiveWitness)),
Faith,
}

impl BFieldCodec for Witness {
fn decode(sequence: &[BFieldElement]) -> Result<Box<Self>> {
if sequence.is_empty() {
Ok(Box::new(Self::Faith))
} else {
Ok(Box::new(Self::Primitive(*PrimitiveWitness::decode(
sequence,
)?)))
}
}

fn encode(&self) -> Vec<BFieldElement> {
let inner_encoding = match self {
Witness::Primitive(pw) => pw.encode(),
Witness::SingleProof(sp) => sp.encode(),
Witness::ValidityLogic(vl) => vl.encode(),
Witness::Faith => vec![],
};
[
vec![BFieldElement::new(self.get_index() as u64)],
inner_encoding,
]
.concat()
}

fn static_length() -> Option<usize> {
None
}
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, GetSize, BFieldCodec)]
pub struct Transaction {
pub kernel: TransactionKernel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use get_size::GetSize;
use serde::{Deserialize, Serialize};
use tasm_lib::compiled_program::CompiledProgram;
use tasm_lib::library::Library;
use twenty_first::shared_math::bfield_codec::BFieldCodec;

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, GetSize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, GetSize, BFieldCodec)]
pub struct KernelToLockScripts {
pub supported_claim: SupportedClaim,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use serde::{Deserialize, Serialize};
use tasm_lib::compiled_program::CompiledProgram;
use tasm_lib::library::Library;
use triton_vm::instruction::LabelledInstruction;
use twenty_first::shared_math::bfield_codec::BFieldCodec;

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, GetSize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, GetSize, BFieldCodec)]
pub struct KernelToTypeScripts {
pub supported_claim: SupportedClaim,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use itertools::Itertools;
use serde::{Deserialize, Serialize};
use tracing::{debug, info, warn};
use triton_vm::StarkParameters;
use twenty_first::shared_math::b_field_element::BFieldElement;
use twenty_first::shared_math::{b_field_element::BFieldElement, bfield_codec::BFieldCodec};

use super::{ClaimSupport, SupportedClaim, ValidationLogic};
use crate::models::blockchain::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl RemovalRecordsIntegrityWitness {
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, GetSize, FieldCount)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, GetSize, FieldCount, BFieldCodec)]
pub struct RemovalRecordsIntegrity {
pub supported_claim: SupportedClaim,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use get_size::GetSize;
use serde::{Deserialize, Serialize};
use twenty_first::shared_math::bfield_codec::BFieldCodec;

use super::{SupportedClaim, ValidationLogic};

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, GetSize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, GetSize, BFieldCodec)]
pub struct TypeScriptsHalt {
pub supported_claims: Vec<SupportedClaim>,
}
Expand Down

0 comments on commit 8ee3465

Please sign in to comment.