Skip to content

Commit

Permalink
Remove validity condition (#1446)
Browse files Browse the repository at this point in the history
Co-authored-by: jfldde <[email protected]>
  • Loading branch information
yaziciahmet and jfldde authored Nov 8, 2024
1 parent 04bedcb commit ba25e9a
Show file tree
Hide file tree
Showing 36 changed files with 149 additions and 350 deletions.
8 changes: 4 additions & 4 deletions bin/citrea/proptest-regressions/test_rpc.txt

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions crates/batch-prover/src/proving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ where
for (tx_id, proof) in txs_and_proofs {
let tx_id_u8 = tx_id.into();

// l1_height => (tx_id, proof, transition_data)
// l1_height => (tx_id, proof, circuit_output)
// save proof along with tx id to db, should be queryable by slot number or slot hash
let transition_data = Vm::extract_output::<
let circuit_output = Vm::extract_output::<
<Da as DaService>::Spec,
BatchProofCircuitOutput<<Da as DaService>::Spec, StateRoot>,
>(&proof)
Expand All @@ -303,27 +303,26 @@ where
info!("Verifying proof!");

let last_active_spec_id =
fork_from_block_number(FORKS.to_vec(), transition_data.last_l2_height).spec_id;
fork_from_block_number(FORKS.to_vec(), circuit_output.last_l2_height).spec_id;
let code_commitment = code_commitments_by_spec
.get(&last_active_spec_id)
.expect("Proof public input must contain valid spec id");
Vm::verify(proof.as_slice(), code_commitment)
.map_err(|err| anyhow!("Failed to verify proof: {:?}. Skipping it...", err))?;

debug!("transition data: {:?}", transition_data);
debug!("circuit output: {:?}", circuit_output);

let slot_hash = transition_data.da_slot_hash.into();
let slot_hash = circuit_output.da_slot_hash.into();

let stored_batch_proof_output = StoredBatchProofOutput {
initial_state_root: transition_data.initial_state_root.as_ref().to_vec(),
final_state_root: transition_data.final_state_root.as_ref().to_vec(),
state_diff: transition_data.state_diff,
initial_state_root: circuit_output.initial_state_root.as_ref().to_vec(),
final_state_root: circuit_output.final_state_root.as_ref().to_vec(),
state_diff: circuit_output.state_diff,
da_slot_hash: slot_hash,
sequencer_commitments_range: transition_data.sequencer_commitments_range,
sequencer_public_key: transition_data.sequencer_public_key,
sequencer_da_public_key: transition_data.sequencer_da_public_key,
preproven_commitments: transition_data.preproven_commitments,
validity_condition: borsh::to_vec(&transition_data.validity_condition).unwrap(),
sequencer_commitments_range: circuit_output.sequencer_commitments_range,
sequencer_public_key: circuit_output.sequencer_public_key,
sequencer_da_public_key: circuit_output.sequencer_da_public_key,
preproven_commitments: circuit_output.preproven_commitments,
};
let l1_height = ledger_db
.get_l1_height_of_l1_hash(slot_hash)?
Expand Down
5 changes: 1 addition & 4 deletions crates/batch-prover/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ where
Da: DaService,
Sm: HierarchicalStorageManager<Da::Spec>,
Vm: ZkvmHost,
Stf: StateTransitionFunction<Vm, Da::Spec, Condition = <Da::Spec as DaSpec>::ValidityCondition>
+ StfBlueprintTrait<C, Da::Spec, Vm>,
Stf: StateTransitionFunction<Vm, Da::Spec> + StfBlueprintTrait<C, Da::Spec, Vm>,

Ps: ProverService,
DB: BatchProverLedgerOps + Clone,
Expand Down Expand Up @@ -81,7 +80,6 @@ where
Stf: StateTransitionFunction<
Vm,
Da::Spec,
Condition = <Da::Spec as DaSpec>::ValidityCondition,
PreState = Sm::NativeStorage,
ChangeSet = Sm::NativeChangeSet,
> + StfBlueprintTrait<C, Da::Spec, Vm>,
Expand Down Expand Up @@ -398,7 +396,6 @@ where
Default::default(),
Default::default(),
current_l1_block.header(),
&current_l1_block.validity_condition(),
&mut signed_soft_confirmation,
)?;
let txs_bodies = signed_soft_confirmation.txs().to_owned();
Expand Down
11 changes: 4 additions & 7 deletions crates/batch-prover/tests/prover_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use std::sync::Arc;
use prover_services::{ParallelProverService, ProofGenMode};
use sov_db::ledger_db::LedgerDB;
use sov_db::rocks_db_config::RocksdbConfig;
use sov_mock_da::{
MockAddress, MockBlockHeader, MockDaService, MockDaSpec, MockHash, MockValidityCond,
};
use sov_mock_da::{MockAddress, MockBlockHeader, MockDaService, MockDaSpec, MockHash};
use sov_mock_zkvm::MockZkvm;
use sov_rollup_interface::da::Time;
use sov_rollup_interface::zk::BatchProofCircuitInput;
Expand Down Expand Up @@ -75,13 +73,12 @@ async fn test_parallel_proving_and_submit() {
}

struct TestProver {
prover_service:
ParallelProverService<MockDaService, MockZkvm<MockValidityCond>, MockStf<MockValidityCond>>,
vm: MockZkvm<MockValidityCond>,
prover_service: ParallelProverService<MockDaService, MockZkvm, MockStf>,
vm: MockZkvm,
}

fn make_new_prover(thread_pool_size: usize, da_service: Arc<MockDaService>) -> TestProver {
let vm = MockZkvm::new(MockValidityCond::default());
let vm = MockZkvm::new();
let proof_mode = ProofGenMode::Execute;

let tmpdir = tempfile::tempdir().unwrap();
Expand Down
9 changes: 0 additions & 9 deletions crates/bitcoin-da/src/spec/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use sov_rollup_interface::services::da::SlotData;

use super::header::HeaderWrapper;
use super::transaction::TransactionWrapper;
use crate::verifier::ChainValidityCondition;

// BitcoinBlock is a wrapper around Block to remove unnecessary fields and implement SlotData
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
Expand All @@ -15,7 +14,6 @@ pub struct BitcoinBlock {

impl SlotData for BitcoinBlock {
type BlockHeader = HeaderWrapper;
type Cond = ChainValidityCondition;

fn hash(&self) -> [u8; 32] {
self.header.hash().to_byte_array()
Expand All @@ -24,11 +22,4 @@ impl SlotData for BitcoinBlock {
fn header(&self) -> &Self::BlockHeader {
&self.header
}

fn validity_condition(&self) -> Self::Cond {
ChainValidityCondition {
prev_hash: self.header.prev_hash().to_byte_array(),
block_hash: self.hash(),
}
}
}
3 changes: 0 additions & 3 deletions crates/bitcoin-da/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use self::block_hash::BlockHashWrapper;
use self::header::HeaderWrapper;
use self::proof::InclusionMultiProof;
use self::transaction::TransactionWrapper;
use crate::verifier::ChainValidityCondition;

pub mod address;
pub mod blob;
Expand Down Expand Up @@ -43,6 +42,4 @@ impl DaSpec for BitcoinSpec {
type InclusionMultiProof = InclusionMultiProof;

type CompletenessProof = Vec<TransactionWrapper>;

type ValidityCondition = ChainValidityCondition;
}
53 changes: 5 additions & 48 deletions crates/bitcoin-da/src/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use std::collections::BTreeSet;

use bitcoin::hashes::Hash;
use borsh::{BorshDeserialize, BorshSerialize};
use citrea_primitives::compression::decompress_blob;
use crypto_bigint::{Encoding, U256};
use serde::{Deserialize, Serialize};
use sov_rollup_interface::da::{
BlockHeaderTrait, CountedBufReader, DaNamespace, DaSpec, DaVerifier, UpdatedDaState,
};
use sov_rollup_interface::digest::Digest;
use sov_rollup_interface::zk::{LightClientCircuitOutput, ValidityCondition};
use thiserror::Error;
use sov_rollup_interface::zk::LightClientCircuitOutput;

use crate::helpers::parsers::{
parse_batch_proof_transaction, parse_light_client_transaction, ParsedBatchProofTransaction,
Expand Down Expand Up @@ -62,39 +58,6 @@ pub enum ValidationError {
InvalidTimestamp,
}

#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Serialize,
Deserialize,
Hash,
BorshDeserialize,
BorshSerialize,
)]
/// A validity condition expressing that a chain of DA layer blocks is contiguous and canonical
pub struct ChainValidityCondition {
pub prev_hash: [u8; 32],
pub block_hash: [u8; 32],
}
#[derive(Error, Debug)]
pub enum ValidityConditionError {
#[error("conditions for validity can only be combined if the blocks are consecutive")]
BlocksNotConsecutive,
}

impl ValidityCondition for ChainValidityCondition {
type Error = ValidityConditionError;
fn combine<H: Digest>(&self, rhs: Self) -> Result<Self, Self::Error> {
if self.block_hash != rhs.prev_hash {
return Err(ValidityConditionError::BlocksNotConsecutive);
}
Ok(rhs)
}
}

impl DaVerifier for BitcoinVerifier {
type Spec = BitcoinSpec;

Expand All @@ -115,7 +78,7 @@ impl DaVerifier for BitcoinVerifier {
inclusion_proof: <Self::Spec as DaSpec>::InclusionMultiProof,
completeness_proof: <Self::Spec as DaSpec>::CompletenessProof,
namespace: DaNamespace,
) -> Result<<Self::Spec as DaSpec>::ValidityCondition, Self::Error> {
) -> Result<(), Self::Error> {
// create hash set of blobs
let mut blobs_iter = blobs.iter();

Expand Down Expand Up @@ -283,10 +246,7 @@ impl DaVerifier for BitcoinVerifier {
return Err(ValidationError::IncorrectInclusionProof);
}

Ok(ChainValidityCondition {
prev_hash: block_header.prev_hash().to_byte_array(),
block_hash: block_header.block_hash().to_byte_array(),
})
Ok(())
}

fn verify_header_chain(
Expand Down Expand Up @@ -530,7 +490,7 @@ mod tests {
use crate::spec::proof::InclusionMultiProof;
use crate::spec::transaction::TransactionWrapper;
use crate::spec::RollupParams;
use crate::verifier::{ChainValidityCondition, ValidationError, WITNESS_COMMITMENT_PREFIX};
use crate::verifier::{ValidationError, WITNESS_COMMITMENT_PREFIX};

#[test]
fn correct() {
Expand Down Expand Up @@ -626,10 +586,7 @@ mod tests {
completeness_proof,
DaNamespace::ToBatchProver,
),
Ok(ChainValidityCondition {
prev_hash: _,
block_hash: _
})
Ok(()),
));
}

Expand Down
1 change: 0 additions & 1 deletion crates/citrea-stf/src/hooks_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ impl<C: Context, Da: DaSpec> SlotHooks<Da> for Runtime<C, Da> {
fn begin_slot_hook(
&self,
_slot_header: &Da::BlockHeader,
_validity_condition: &Da::ValidityCondition,
_pre_state_root: &<<Self::Context as Spec>::Storage as Storage>::Root,
_working_set: &mut sov_modules_api::WorkingSet<C>,
) {
Expand Down
4 changes: 1 addition & 3 deletions crates/citrea-stf/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where
panic!("Invalid hash of DA block header of commitments");
}

let validity_condition = self.da_verifier.verify_transactions(
self.da_verifier.verify_transactions(
&data.da_block_header_of_commitments,
&data.da_data,
data.inclusion_proof,
Expand Down Expand Up @@ -83,7 +83,6 @@ where
data.sequencer_commitments_range,
data.state_transition_witnesses,
data.da_block_headers_of_soft_confirmations,
&validity_condition,
data.soft_confirmations,
data.preproven_commitments.clone(),
FORKS.to_vec(),
Expand All @@ -101,7 +100,6 @@ where
final_state_root,
prev_soft_confirmation_hash: data.prev_soft_confirmation_hash,
final_soft_confirmation_hash,
validity_condition, // TODO: not sure about what to do with this yet
state_diff,
da_slot_hash: data.da_block_header_of_commitments.hash(),
sequencer_public_key: data.sequencer_public_key,
Expand Down
1 change: 0 additions & 1 deletion crates/fullnode/src/da_block_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ where
sequencer_public_key: batch_proof_output.sequencer_public_key,
sequencer_da_public_key: batch_proof_output.sequencer_da_public_key,
preproven_commitments: batch_proof_output.preproven_commitments.clone(),
validity_condition: borsh::to_vec(&batch_proof_output.validity_condition).unwrap(),
};

let l1_hash = batch_proof_output.da_slot_hash.into();
Expand Down
5 changes: 1 addition & 4 deletions crates/fullnode/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ where
Da: DaService,
Vm: ZkvmHost + Zkvm,
Sm: HierarchicalStorageManager<Da::Spec>,
Stf: StateTransitionFunction<Vm, Da::Spec, Condition = <Da::Spec as DaSpec>::ValidityCondition>
+ StfBlueprintTrait<C, Da::Spec, Vm>,
Stf: StateTransitionFunction<Vm, Da::Spec> + StfBlueprintTrait<C, Da::Spec, Vm>,
C: Context,
DB: NodeLedgerOps + Clone,
{
Expand Down Expand Up @@ -80,7 +79,6 @@ where
Stf: StateTransitionFunction<
Vm,
Da::Spec,
Condition = <Da::Spec as DaSpec>::ValidityCondition,
PreState = Sm::NativeStorage,
ChangeSet = Sm::NativeChangeSet,
> + StfBlueprintTrait<C, Da::Spec, Vm>,
Expand Down Expand Up @@ -258,7 +256,6 @@ where
Default::default(),
Default::default(),
current_l1_block.header(),
&current_l1_block.validity_condition(),
&mut signed_soft_confirmation,
)?;

Expand Down
Loading

0 comments on commit ba25e9a

Please sign in to comment.