Skip to content

Commit

Permalink
Add skeleton for proving blocks valid because valid successors
Browse files Browse the repository at this point in the history
  • Loading branch information
aszepieniec committed Feb 5, 2024
1 parent 99e8da6 commit a79bc42
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "tasm_neptune_transaction_removal_records_integrity",
"clock_cycle_count": 29649,
"hash_table_height": 5633,
"u32_table_height": 13245,
"u32_table_height": 13250,
"case": "CommonCase"
}
]
43 changes: 38 additions & 5 deletions src/models/blockchain/block/validity.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
use get_size::GetSize;
use serde::{Deserialize, Serialize};
use tasm_lib::twenty_first;
use tasm_lib::{
triton_vm::program::{NonDeterminism, Program},
twenty_first::{self, shared_math::b_field_element::BFieldElement},
};
use twenty_first::shared_math::bfield_codec::BFieldCodec;

use crate::models::consensus::SecretWitness;

use self::{
coinbase_is_valid::CoinbaseIsValid,
correct_control_parameter_update::CorrectControlParameterUpdate,
correct_mmr_update::CorrectMmrUpdate, correct_mutator_set_update::CorrectMutatorSetUpdate,
predecessor_is_valid::PredecessorIsValid, transaction_is_valid::TransactionIsValid,
mmr_membership::MmrMembership, predecessor_is_valid::PredecessorIsValid,
transaction_is_valid::TransactionIsValid,
};

use super::Block;

pub mod coinbase_is_valid;
pub mod correct_control_parameter_update;
pub mod correct_mmr_update;
pub mod correct_mutator_set_update;
pub mod mmr_membership;
pub mod predecessor_is_valid;
pub mod transaction_is_valid;

/// The validity of a block, when it is not the genesis block and when it does not
/// come with proofs, decomposes into these subclaims.
/// The validity of a block, in the principal case, decomposes into these subclaims.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, GetSize, BFieldCodec)]
pub struct BlockValidationLogic {
pub struct PrincipalBlockValidationLogic {
// program: recursive-verify-or-is-genesis, input: block kernel, output: []
pub predecessor_is_valid: PredecessorIsValid,

Expand All @@ -39,3 +47,28 @@ pub struct BlockValidationLogic {
// program: update-control-parameters, input: block kernel, output: []
pub correct_control_parameter_update: CorrectControlParameterUpdate,
}

/// Alternatively, the validity of a block follows from that of a successor. This pathway
/// two subclaims, both of which are relative to the successor block.
/// 1. the current block lives in the block mmr of the successor block
/// 2. the successor block is valid
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, GetSize, BFieldCodec)]
pub struct AlternativeBlockValidationLogic {
pub mmr_membership: MmrMembership,
pub successor_is_valid: PrincipalBlockValidationLogic,
}

#[derive(Debug, Clone, BFieldCodec, GetSize, PartialEq, Eq, Serialize, Deserialize)]
pub struct PrincipalBlockValidationWitness {
pub successor: Block, // includes proof
}

impl SecretWitness for PrincipalBlockValidationWitness {
fn nondeterminism(&self) -> NonDeterminism<BFieldElement> {
todo!()
}

fn subprogram(&self) -> Program {
todo!()
}
}
31 changes: 31 additions & 0 deletions src/models/blockchain/block/validity/mmr_membership.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::models::blockchain::block::BFieldCodec;
use crate::models::blockchain::block::Deserialize;
use crate::models::blockchain::block::GetSize;
use crate::models::blockchain::block::Serialize;
use crate::models::blockchain::shared::Hash;
use crate::models::consensus::SecretWitness;
use crate::models::consensus::SupportedClaim;
use crate::triton_vm::program::Program;
use tasm_lib::triton_vm::program::NonDeterminism;
use tasm_lib::twenty_first::shared_math::b_field_element::BFieldElement;
use tasm_lib::twenty_first::util_types::mmr::mmr_membership_proof::MmrMembershipProof;

#[derive(Debug, Clone, BFieldCodec, GetSize, PartialEq, Eq, Serialize, Deserialize)]
pub struct MmrMembershipWitness {
pub membership_proof: MmrMembershipProof<Hash>,
}

impl SecretWitness for MmrMembershipWitness {
fn nondeterminism(&self) -> NonDeterminism<BFieldElement> {
todo!()
}

fn subprogram(&self) -> Program {
todo!()
}
}

#[derive(Debug, Clone, BFieldCodec, GetSize, PartialEq, Eq, Serialize, Deserialize)]
pub struct MmrMembership {
supported_claim: SupportedClaim<MmrMembershipWitness>,
}

0 comments on commit a79bc42

Please sign in to comment.