Skip to content

Commit

Permalink
Rename branches to proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
pkakelas committed Dec 4, 2023
1 parent e4e150b commit 143b8bd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
28 changes: 14 additions & 14 deletions feeder/src/prover/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const CAPELLA_FORK_SLOT: u64 = CAPELLA_FORK_EPOCH * SLOTS_PER_EPOCH;
/**
* Generates a merkle proof from the transaction to the beacon block root.
*/
pub async fn generate_transaction_branch(
pub async fn generate_transaction_proof(
state_prover: &dyn StateProverAPI,
block_id: &String,
tx_index: u64,
Expand All @@ -35,7 +35,7 @@ pub async fn generate_transaction_branch(
/**
* Generates a merkle proof from the receipts_root to the beacon block root.
*/
pub async fn generate_receipts_root_branch(
pub async fn generate_receipts_root_proof(
state_prover: &dyn StateProverAPI,
block_id: &String,
) -> Result<ProofResponse> {
Expand Down Expand Up @@ -116,7 +116,7 @@ pub async fn prove_ancestry_with_block_roots(
Ok(ancestry_proof)
}

async fn prove_historical_summaries_branch(
async fn prove_historical_summaries_proof(
state_prover: &dyn StateProverAPI,
target_block_slot: &u64,
recent_block_state_id: &String,
Expand Down Expand Up @@ -170,18 +170,18 @@ pub async fn prove_ancestry_with_historical_summaries(
"Target block epoch is less than CAPELLA_FORK_EPOCH"
));
}
let historical_summaries_branch =
prove_historical_summaries_branch(state_prover, target_block_slot, recent_block_state_id)
let historical_summaries_proof =
prove_historical_summaries_proof(state_prover, target_block_slot, recent_block_state_id)
.await?;

let block_root_to_block_summary_root =
prove_block_root_to_block_summary_root(consensus, target_block_slot).await?;

let res = AncestryProof::HistoricalRoots {
block_root_proof: block_root_to_block_summary_root,
block_summary_root_proof: historical_summaries_branch.witnesses,
block_summary_root: historical_summaries_branch.leaf,
block_summary_root_gindex: historical_summaries_branch.gindex as usize,
block_summary_root_proof: historical_summaries_proof.witnesses,
block_summary_root: historical_summaries_proof.leaf,
block_summary_root_gindex: historical_summaries_proof.gindex as usize,
};

Ok(res)
Expand All @@ -191,8 +191,8 @@ pub async fn prove_ancestry_with_historical_summaries(
mod tests {
use crate::eth::consensus::EthBeaconAPI;
use crate::prover::consensus::{
generate_receipts_root_branch, generate_transaction_branch,
prove_ancestry_with_block_roots, prove_ancestry_with_historical_summaries,
generate_receipts_root_proof, generate_transaction_proof, prove_ancestry_with_block_roots,
prove_ancestry_with_historical_summaries,
};
use crate::prover::mocks::mock_consensus_rpc::MockConsensusRPC;
use crate::prover::mocks::mock_state_prover::MockStateProver;
Expand All @@ -209,7 +209,7 @@ mod tests {
* TESTS BELOW REQUIRE NETWORK REQUESTS
*/
#[tokio_test]
async fn test_transactions_branch() {
async fn test_transactions_proof() {
let consensus = &MockConsensusRPC::new();
let state_prover = MockStateProver::new();
let mut block = consensus.get_beacon_block(7807119).await.unwrap();
Expand All @@ -220,7 +220,7 @@ mod tests {
let node = transaction.hash_tree_root().unwrap();

let proof =
generate_transaction_branch(&state_prover, &block_root.to_string(), tx_index as u64)
generate_transaction_proof(&state_prover, &block_root.to_string(), tx_index as u64)
.await
.unwrap();

Expand All @@ -235,13 +235,13 @@ mod tests {
}

#[tokio_test]
async fn test_receipts_root_branch() {
async fn test_receipts_root_proof() {
let consensus = &MockConsensusRPC::new();
let state_prover = MockStateProver::new();
let mut block = consensus.get_beacon_block(7807119).await.unwrap();
let block_root = block.hash_tree_root().unwrap();

let proof = generate_receipts_root_branch(&state_prover, &block_root.to_string())
let proof = generate_receipts_root_proof(&state_prover, &block_root.to_string())
.await
.unwrap();

Expand Down
19 changes: 10 additions & 9 deletions feeder/src/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
utils::calc_slot_from_timestamp,
},
prover::{
consensus::{generate_receipts_root_branch, generate_transaction_branch, prove_ancestry},
consensus::{generate_receipts_root_proof, generate_transaction_proof, prove_ancestry},
execution::{generate_receipt_proof, get_tx_index},
},
types::InternalMessage,
Expand Down Expand Up @@ -85,12 +85,13 @@ impl Prover {
println!("Got receipts proof");

// Consensus Proofs
let transaction_branch =
generate_transaction_branch(&self.state_prover, &block_id, tx_index).await?;
println!("Got transactions branch");
let transaction_proof =
generate_transaction_proof(&self.state_prover, &block_id, tx_index).await?;
println!("Got transactions proof");

let receipts_branch = generate_receipts_root_branch(&self.state_prover, &block_id).await?;
println!("Got receipts branch");
let receipts_root_proof =
generate_receipts_root_proof(&self.state_prover, &block_id).await?;
println!("Got receipts root proof");

let ancestry_proof = prove_ancestry(
&self.consensus_rpc,
Expand All @@ -108,13 +109,13 @@ impl Prover {
ancestry_proof,
transaction_proof: TransactionProof {
transaction_index: tx_index,
transaction_gindex: transaction_branch.gindex,
transaction_branch: transaction_branch.witnesses,
transaction_gindex: transaction_proof.gindex,
transaction_proof: transaction_proof.witnesses,
transaction,
},
receipt_proof: ReceiptProof {
receipt_proof,
receipts_root_proof: receipts_branch.witnesses,
receipts_root_proof: receipts_root_proof.witnesses,
receipts_root: Node::from_bytes(target_block.receipts_root.as_bytes().try_into()?),
},
})
Expand Down
2 changes: 1 addition & 1 deletion types/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct TransactionProof {
// Generalized index of transaction in target block
pub transaction_gindex: u64,
// Proof from target block to transaction
pub transaction_branch: Vec<Node>,
pub transaction_proof: Vec<Node>,
// Actual transaction to keccak and test against tx_hash of message
pub transaction: Transaction<MAX_BYTES_PER_TRANSACTION>,
}
Expand Down

0 comments on commit 143b8bd

Please sign in to comment.