diff --git a/src/models/blockchain/transaction/mod.rs b/src/models/blockchain/transaction/mod.rs index 8d3e7fcb..afe4213c 100644 --- a/src/models/blockchain/transaction/mod.rs +++ b/src/models/blockchain/transaction/mod.rs @@ -103,7 +103,7 @@ 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), @@ -111,36 +111,6 @@ pub enum Witness { Faith, } -impl BFieldCodec for Witness { - fn decode(sequence: &[BFieldElement]) -> Result> { - if sequence.is_empty() { - Ok(Box::new(Self::Faith)) - } else { - Ok(Box::new(Self::Primitive(*PrimitiveWitness::decode( - sequence, - )?))) - } - } - - fn encode(&self) -> Vec { - 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 { - None - } -} - #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, GetSize, BFieldCodec)] pub struct Transaction { pub kernel: TransactionKernel, diff --git a/src/models/blockchain/transaction/validity/kernel_to_lock_scripts.rs b/src/models/blockchain/transaction/validity/kernel_to_lock_scripts.rs index 384da87e..88cf5f93 100644 --- a/src/models/blockchain/transaction/validity/kernel_to_lock_scripts.rs +++ b/src/models/blockchain/transaction/validity/kernel_to_lock_scripts.rs @@ -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, } diff --git a/src/models/blockchain/transaction/validity/kernel_to_typescripts.rs b/src/models/blockchain/transaction/validity/kernel_to_typescripts.rs index 120eaf50..308f829a 100644 --- a/src/models/blockchain/transaction/validity/kernel_to_typescripts.rs +++ b/src/models/blockchain/transaction/validity/kernel_to_typescripts.rs @@ -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, } diff --git a/src/models/blockchain/transaction/validity/lockscripts_halt.rs b/src/models/blockchain/transaction/validity/lockscripts_halt.rs index 0d9be790..78306488 100644 --- a/src/models/blockchain/transaction/validity/lockscripts_halt.rs +++ b/src/models/blockchain/transaction/validity/lockscripts_halt.rs @@ -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::{ diff --git a/src/models/blockchain/transaction/validity/tasm/removal_records_integrity.rs b/src/models/blockchain/transaction/validity/tasm/removal_records_integrity.rs index abb700fd..d4706395 100644 --- a/src/models/blockchain/transaction/validity/tasm/removal_records_integrity.rs +++ b/src/models/blockchain/transaction/validity/tasm/removal_records_integrity.rs @@ -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, } diff --git a/src/models/blockchain/transaction/validity/typescripts_halt.rs b/src/models/blockchain/transaction/validity/typescripts_halt.rs index a115e673..8f1e02d4 100644 --- a/src/models/blockchain/transaction/validity/typescripts_halt.rs +++ b/src/models/blockchain/transaction/validity/typescripts_halt.rs @@ -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, }