Skip to content

Commit 68e3959

Browse files
committed
Merge branch 'feat/verify-agg-proof-on-chain' into feat/full-example-and-docs-for-agg-mod
2 parents 3c32349 + 5981a77 commit 68e3959

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1300
-671
lines changed

.github/workflows/build-and-test-rust.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
paths:
99
- "batcher/**"
1010
- "aggregation_mode/**"
11-
- ".github/workflows/build-rust.yml"
11+
- ".github/workflows/build-and-test-rust.yml"
1212

1313
jobs:
1414
build:
@@ -20,7 +20,7 @@ jobs:
2020
- name: Set up Rust
2121
uses: actions-rs/toolchain@v1
2222
with:
23-
toolchain: stable
23+
toolchain: 1.86.0
2424
components: rustfmt, clippy
2525
override: true
2626

Makefile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,19 @@ start_proof_aggregator_dev: is_aggregator_set reset_last_aggregated_block ## Sta
178178
start_proof_aggregator: is_aggregator_set reset_last_aggregated_block ## Starts proof aggregator with proving activated
179179
AGGREGATOR=$(AGGREGATOR) cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove --bin proof_aggregator -- config-files/config-proof-aggregator.yaml
180180

181+
start_proof_aggregator_dev_ethereum_package: is_aggregator_set reset_last_aggregated_block ## Starts proof aggregator with mock proofs (DEV mode) in ethereum package
182+
AGGREGATOR=$(AGGREGATOR) RISC0_DEV_MODE=1 cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin proof_aggregator -- config-files/config-proof-aggregator-mock-ethereum-package.yaml
183+
184+
start_proof_aggregator_ethereum_package: is_aggregator_set reset_last_aggregated_block ## Starts proof aggregator with proving activated in ethereum package
185+
AGGREGATOR=$(AGGREGATOR) cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove --bin proof_aggregator -- config-files/config-proof-aggregator-ethereum-package.yaml
186+
181187
start_proof_aggregator_gpu: is_aggregator_set reset_last_aggregated_block ## Starts proof aggregator with proving + GPU acceleration (CUDA)
182188
AGGREGATOR=$(AGGREGATOR) SP1_PROVER=cuda cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove,gpu --bin proof_aggregator -- config-files/config-proof-aggregator.yaml
183189

190+
start_proof_aggregator_gpu_ethereum_package: is_aggregator_set reset_last_aggregated_block ## Starts proof aggregator with proving activated in ethereum package
191+
AGGREGATOR=$(AGGREGATOR) SP1_PROVER=cuda cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove,gpu --bin proof_aggregator -- config-files/config-proof-aggregator-ethereum-package.yaml
192+
193+
184194
verify_aggregated_proof_sp1_holesky_stage:
185195
@echo "Verifying SP1 in aggregated proofs on holesky..."
186196
@cd batcher/aligned/ && \
@@ -1319,6 +1329,7 @@ ethereum_package_inspect: ## Prints detailed information about the net
13191329

13201330
ethereum_package_rm: ## Stops and removes the ethereum_package environment and used resources
13211331
kurtosis enclave rm aligned -f
1332+
kurtosis engine stop
13221333

13231334
batcher_start_ethereum_package: user_fund_payment_service
13241335
@echo "Starting Batcher..."
@@ -1329,11 +1340,11 @@ aggregator_start_ethereum_package:
13291340
$(MAKE) aggregator_start AGG_CONFIG_FILE=config-files/config-aggregator-ethereum-package.yaml
13301341

13311342
operator_start_ethereum_package:
1332-
$(MAKE) operator_start OPERATOR_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 CONFIG_FILE=config-files/config-operator-1-ethereum-package.yaml
1343+
$(MAKE) operator_start ENVIRONMENT=devnet OPERATOR_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 CONFIG_FILE=config-files/config-operator-1-ethereum-package.yaml
13331344

13341345
operator_register_start_ethereum_package:
1335-
$(MAKE) operator_full_registration OPERATOR_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 CONFIG_FILE=config-files/config-operator-1-ethereum-package.yaml \
1336-
$(MAKE) operator_start OPERATOR_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 CONFIG_FILE=config-files/config-operator-1-ethereum-package.yaml
1346+
$(MAKE) operator_full_registration OPERATOR_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 CONFIG_FILE=config-files/config-operator-1-ethereum-package.yaml
1347+
$(MAKE) operator_start ENVIRONMENT=devnet OPERATOR_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 CONFIG_FILE=config-files/config-operator-1-ethereum-package.yaml
13371348

13381349

13391350
install_spamoor: ## Instal spamoor to spam transactions

aggregation_mode/src/backend/fetcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
},
1212
backend::s3::get_aligned_batch_from_s3,
1313
};
14-
use aligned_sdk::core::types::ProvingSystemId;
14+
use aligned_sdk::common::types::ProvingSystemId;
1515
use alloy::{
1616
primitives::Address,
1717
providers::{Provider, ProviderBuilder},

aggregation_mode/src/backend/s3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use aligned_sdk::core::types::VerificationData;
1+
use aligned_sdk::common::types::VerificationData;
22

33
#[derive(Debug)]
44
#[allow(dead_code)]

batcher/aligned-batcher/src/config/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub struct BatcherConfigFromYaml {
4646
pub max_proof_size: usize,
4747
pub max_batch_byte_size: usize,
4848
pub max_batch_proof_qty: usize,
49+
pub max_queue_size: usize,
4950
pub pre_verification_is_enabled: bool,
5051
pub metrics_port: u16,
5152
pub telemetry_ip_port_address: String,
@@ -92,9 +93,9 @@ impl ContractDeploymentOutput {
9293
}
9394

9495
fn default_aggregator_fee_percentage_multiplier() -> u128 {
95-
aligned_sdk::core::constants::DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER
96+
aligned_sdk::common::constants::DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER
9697
}
9798

9899
fn default_aggregator_gas_cost() -> u128 {
99-
aligned_sdk::core::constants::DEFAULT_AGGREGATOR_GAS_COST
100+
aligned_sdk::common::constants::DEFAULT_AGGREGATOR_GAS_COST
100101
}

batcher/aligned-batcher/src/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::sync::Arc;
22

33
use crate::types::{batch_queue::BatchQueueEntry, errors::BatcherError};
44
use aligned_sdk::{
5+
common::types::{BatchInclusionData, SubmitProofResponseMessage, VerificationCommitmentBatch},
56
communication::serialization::cbor_serialize,
6-
core::types::{BatchInclusionData, SubmitProofResponseMessage, VerificationCommitmentBatch},
77
};
88
use futures_util::{stream::SplitSink, SinkExt};
99
use lambdaworks_crypto::merkle_tree::merkle::MerkleTree;

batcher/aligned-batcher/src/eth/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
retry_function,
99
},
1010
};
11-
use aligned_sdk::core::constants::{
11+
use aligned_sdk::common::constants::{
1212
ETHEREUM_CALL_BACKOFF_FACTOR, ETHEREUM_CALL_MAX_RETRIES, ETHEREUM_CALL_MAX_RETRY_DELAY,
1313
ETHEREUM_CALL_MIN_RETRY_DELAY, GAS_PRICE_INCREMENT_PERCENTAGE_PER_ITERATION,
1414
OVERRIDE_GAS_PRICE_PERCENTAGE_MULTIPLIER, PERCENTAGE_DIVIDER,

batcher/aligned-batcher/src/gnark/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use aligned_sdk::core::types::ProvingSystemId;
1+
use aligned_sdk::common::types::ProvingSystemId;
22

33
#[derive(Copy, Clone, Debug)]
44
#[repr(C)]

batcher/aligned-batcher/src/lib.rs

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ use std::net::SocketAddr;
2323
use std::sync::Arc;
2424
use std::time::Duration;
2525

26-
use aligned_sdk::core::constants::{
26+
use aligned_sdk::common::constants::{
2727
ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF, BATCHER_SUBMISSION_BASE_GAS_COST,
2828
BUMP_BACKOFF_FACTOR, BUMP_MAX_RETRIES, BUMP_MAX_RETRY_DELAY, BUMP_MIN_RETRY_DELAY,
2929
CBOR_ARRAY_MAX_OVERHEAD, CONNECTION_TIMEOUT, DEFAULT_MAX_FEE_PER_PROOF,
3030
ETHEREUM_CALL_BACKOFF_FACTOR, ETHEREUM_CALL_MAX_RETRIES, ETHEREUM_CALL_MAX_RETRY_DELAY,
3131
ETHEREUM_CALL_MIN_RETRY_DELAY, GAS_PRICE_PERCENTAGE_MULTIPLIER, PERCENTAGE_DIVIDER,
3232
RESPOND_TO_TASK_FEE_LIMIT_PERCENTAGE_MULTIPLIER,
3333
};
34-
use aligned_sdk::core::types::{
34+
use aligned_sdk::common::types::{
3535
ClientMessage, GetNonceResponseMessage, NoncedVerificationData, ProofInvalidReason,
3636
ProvingSystemId, SubmitProofMessage, SubmitProofResponseMessage, VerificationCommitmentBatch,
3737
VerificationData, VerificationDataCommitment,
@@ -210,7 +210,7 @@ impl Batcher {
210210
.expect("Failed to get fallback Service Manager contract");
211211

212212
let mut user_states = HashMap::new();
213-
let mut batch_state = BatchState::new();
213+
let mut batch_state = BatchState::new(config.batcher.max_queue_size);
214214
let non_paying_config = if let Some(non_paying_config) = config.batcher.non_paying {
215215
warn!("Non-paying address configuration detected. Will replace non-paying address {} with configured address.",
216216
non_paying_config.address);
@@ -228,7 +228,8 @@ impl Batcher {
228228
non_paying_user_state,
229229
);
230230

231-
batch_state = BatchState::new_with_user_states(user_states);
231+
batch_state =
232+
BatchState::new_with_user_states(user_states, config.batcher.max_queue_size);
232233
Some(non_paying_config)
233234
} else {
234235
None
@@ -702,7 +703,7 @@ impl Batcher {
702703
// This is needed because we need to query the user state to make validations and
703704
// finally add the proof to the batch queue.
704705

705-
let batch_state_lock = self.batch_state.lock().await;
706+
let mut batch_state_lock = self.batch_state.lock().await;
706707

707708
let msg_max_fee = nonced_verification_data.max_fee;
708709
let Some(user_last_max_fee_limit) =
@@ -782,6 +783,8 @@ impl Batcher {
782783
return Ok(());
783784
}
784785

786+
// We check this after replacement logic because if user wants to replace a proof, their
787+
// new_max_fee must be greater or equal than old_max_fee
785788
if msg_max_fee > user_last_max_fee_limit {
786789
std::mem::drop(batch_state_lock);
787790
warn!("Invalid max fee for address {addr}, had fee limit of {user_last_max_fee_limit:?}, sent {msg_max_fee:?}");
@@ -794,6 +797,67 @@ impl Batcher {
794797
return Ok(());
795798
}
796799

800+
// * ---------------------------------------------------------------------*
801+
// * Perform validation over batcher queue *
802+
// * ---------------------------------------------------------------------*
803+
804+
if batch_state_lock.is_queue_full() {
805+
debug!("Batch queue is full. Evaluating if the incoming proof can replace a lower-priority entry.");
806+
807+
// This cannot panic, if the batch queue is full it has at least one item
808+
let (lowest_priority_entry, _) = batch_state_lock
809+
.batch_queue
810+
.peek()
811+
.expect("Batch queue was expected to be full, but somehow no item was inside");
812+
813+
let lowest_fee_in_queue = lowest_priority_entry.nonced_verification_data.max_fee;
814+
815+
let new_proof_fee = nonced_verification_data.max_fee;
816+
817+
// We will keep the proof with the highest fee
818+
// Note: we previously checked that if it's a new proof from the same user the fee is the same or lower
819+
// So this will never eject a proof of the same user with a lower nonce
820+
// which is the expected behaviour
821+
if new_proof_fee > lowest_fee_in_queue {
822+
// This cannot panic, if the batch queue is full it has at least one item
823+
let (removed_entry, _) = batch_state_lock
824+
.batch_queue
825+
.pop()
826+
.expect("Batch queue was expected to be full, but somehow no item was inside");
827+
828+
info!(
829+
"Incoming proof (nonce: {}, fee: {}) has higher fee. Replacing lowest fee proof from sender {} with nonce {}.",
830+
nonced_verification_data.nonce,
831+
nonced_verification_data.max_fee,
832+
removed_entry.sender,
833+
removed_entry.nonced_verification_data.nonce
834+
);
835+
836+
batch_state_lock.update_user_state_on_entry_removal(&removed_entry);
837+
838+
if let Some(removed_entry_ws) = removed_entry.messaging_sink {
839+
send_message(
840+
removed_entry_ws,
841+
SubmitProofResponseMessage::UnderpricedProof,
842+
)
843+
.await;
844+
};
845+
} else {
846+
info!(
847+
"Incoming proof (nonce: {}, fee: {}) has lower priority than all entries in the full queue. Rejecting submission.",
848+
nonced_verification_data.nonce,
849+
nonced_verification_data.max_fee
850+
);
851+
std::mem::drop(batch_state_lock);
852+
send_message(
853+
ws_conn_sink.clone(),
854+
SubmitProofResponseMessage::UnderpricedProof,
855+
)
856+
.await;
857+
return Ok(());
858+
}
859+
}
860+
797861
// * ---------------------------------------------------------------------*
798862
// * Add message data into the queue and update user state *
799863
// * ---------------------------------------------------------------------*
@@ -1727,6 +1791,16 @@ impl Batcher {
17271791

17281792
let batch_state_lock = self.batch_state.lock().await;
17291793

1794+
if batch_state_lock.is_queue_full() {
1795+
error!("Can't add new entry, the batcher queue is full");
1796+
send_message(
1797+
ws_sink.clone(),
1798+
SubmitProofResponseMessage::UnderpricedProof,
1799+
)
1800+
.await;
1801+
return Ok(());
1802+
}
1803+
17301804
let nonced_verification_data = NoncedVerificationData::new(
17311805
client_msg.verification_data.verification_data.clone(),
17321806
client_msg.verification_data.nonce,

batcher/aligned-batcher/src/types/batch_queue.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use aligned_sdk::{
2-
communication::serialization::cbor_serialize,
3-
core::{
2+
common::{
43
constants::CBOR_ARRAY_MAX_OVERHEAD,
54
types::{NoncedVerificationData, VerificationDataCommitment},
65
},
6+
communication::serialization::cbor_serialize,
77
};
88
use ethers::types::{Address, Signature, U256};
99
use priority_queue::PriorityQueue;
@@ -214,9 +214,9 @@ fn calculate_fee_per_proof(batch_len: usize, gas_price: U256, constant_gas_cost:
214214

215215
#[cfg(test)]
216216
mod test {
217-
use aligned_sdk::core::constants::DEFAULT_CONSTANT_GAS_COST;
218-
use aligned_sdk::core::types::ProvingSystemId;
219-
use aligned_sdk::core::types::VerificationData;
217+
use aligned_sdk::common::constants::DEFAULT_CONSTANT_GAS_COST;
218+
use aligned_sdk::common::types::ProvingSystemId;
219+
use aligned_sdk::common::types::VerificationData;
220220
use ethers::types::Address;
221221

222222
use super::*;

0 commit comments

Comments
 (0)