-
Notifications
You must be signed in to change notification settings - Fork 391
Fix: Batcher User Balance Checks #1404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
9278ed3
cf9cc7b
baf8370
91c0690
929dde4
906ca55
ed3e589
f760fff
e242905
9a0e459
42d5d27
35514a2
94ece7a
73c27c2
2eae3b4
69ebfc3
0631a47
fcede86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ use aligned_sdk::core::constants::{ | |
| ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF, AGGREGATOR_GAS_COST, CANCEL_TRANSACTION_MAX_RETRIES, | ||
| CONSTANT_GAS_COST, DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER, DEFAULT_BACKOFF_FACTOR, | ||
| DEFAULT_MAX_FEE_PER_PROOF, DEFAULT_MAX_RETRIES, DEFAULT_MIN_RETRY_DELAY, | ||
| GAS_PRICE_PERCENTAGE_MULTIPLIER, MIN_FEE_PER_PROOF, PERCENTAGE_DIVIDER, | ||
| GAS_PRICE_PERCENTAGE_MULTIPLIER, PERCENTAGE_DIVIDER, | ||
| RESPOND_TO_TASK_FEE_LIMIT_PERCENTAGE_MULTIPLIER, | ||
| }; | ||
| use aligned_sdk::core::types::{ | ||
|
|
@@ -672,7 +672,21 @@ impl Batcher { | |
| return Ok(()); | ||
| }; | ||
|
|
||
| if !self.check_min_balance(proofs_in_batch + 1, user_balance) { | ||
| let msg_max_fee = nonced_verification_data.max_fee; | ||
| let Some(user_min_fee) = batch_state_lock.get_user_min_fee(&addr).await else { | ||
| std::mem::drop(batch_state_lock); | ||
| send_message( | ||
| ws_conn_sink.clone(), | ||
| SubmitProofResponseMessage::InvalidNonce, | ||
| ) | ||
| .await; | ||
| self.metrics.user_error(&["invalid_nonce", ""]); | ||
| return Ok(()); | ||
| }; | ||
|
|
||
| // We estimate the minimum balance for submission to be the product of the user's `user_min_fee`, | ||
| // and the number of user's proof in a batch including the currently submitted proof (`proofs_in_the_batch + 1`). | ||
| if !self.check_min_balance(user_min_fee, proofs_in_batch + 1, user_balance, msg_max_fee) { | ||
| std::mem::drop(batch_state_lock); | ||
| send_message( | ||
| ws_conn_sink.clone(), | ||
|
|
@@ -724,18 +738,6 @@ impl Batcher { | |
| return Ok(()); | ||
| } | ||
|
|
||
| let msg_max_fee = nonced_verification_data.max_fee; | ||
| let Some(user_min_fee) = batch_state_lock.get_user_min_fee(&addr).await else { | ||
| std::mem::drop(batch_state_lock); | ||
| send_message( | ||
| ws_conn_sink.clone(), | ||
| SubmitProofResponseMessage::InvalidNonce, | ||
| ) | ||
| .await; | ||
| self.metrics.user_error(&["invalid_nonce", ""]); | ||
| return Ok(()); | ||
| }; | ||
|
|
||
| if msg_max_fee > user_min_fee { | ||
| std::mem::drop(batch_state_lock); | ||
| warn!("Invalid max fee for address {addr}, had fee {user_min_fee:?} < {msg_max_fee:?}"); | ||
|
|
@@ -777,9 +779,20 @@ impl Batcher { | |
| zk_utils::is_verifier_disabled(*disabled_verifiers, verifier) | ||
| } | ||
|
|
||
| // Checks user has sufficient balance for paying all its the proofs in the current batch. | ||
| fn check_min_balance(&self, user_proofs_in_batch: usize, user_balance: U256) -> bool { | ||
| let min_balance = U256::from(user_proofs_in_batch) * U256::from(MIN_FEE_PER_PROOF); | ||
| // Checks user has sufficient balance for paying all the users proofs in the current batch. | ||
| fn check_min_balance( | ||
| &self, | ||
| user_min_fee: U256, | ||
| user_proofs_in_batch: usize, | ||
| user_balance: U256, | ||
| user_max_fee: U256, | ||
| ) -> bool { | ||
| // `user_min_fee` is the minimum `max_fee` the user submitted to the batcher and represents the maximium price that the user will pay for each submitted proof. We define 'user_min_fee' as an upper bound for the proof submission cost of the user, and use it to validate the user's balance has enough fund available to pay for all submitted proofs. | ||
| let mut min_fee = user_min_fee; | ||
| if user_min_fee == U256::max_value() { | ||
| min_fee = user_max_fee | ||
| } | ||
| let min_balance: U256 = U256::from(user_proofs_in_batch) * min_fee; | ||
|
||
| user_balance >= min_balance | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.