|
| 1 | +# Parallel Signature Verification |
| 2 | + |
| 3 | +CipherBFT parallelizes ECDSA signature recovery during block execution using [rayon](https://docs.rs/rayon). |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +ECDSA signature recovery (`secp256k1` curve) is CPU-intensive. By recovering signatures in parallel before sequential EVM execution, we reduce block processing latency. |
| 8 | + |
| 9 | +``` |
| 10 | +Before: [Decode+Recover+Execute] → [Decode+Recover+Execute] → ... (sequential) |
| 11 | +After: [Decode+Recover ∥ Decode+Recover ∥ ...] → [Execute] → [Execute] → ... |
| 12 | +``` |
| 13 | + |
| 14 | +## API |
| 15 | + |
| 16 | +### RecoveredTx |
| 17 | + |
| 18 | +```rust |
| 19 | +pub struct RecoveredTx { |
| 20 | + pub tx_bytes: Bytes, // Original RLP bytes |
| 21 | + pub tx_env: TxEnv, // Parsed for EVM |
| 22 | + pub tx_hash: B256, // Transaction hash |
| 23 | + pub sender: Address, // Recovered signer |
| 24 | + pub to: Option<Address>, // Recipient (None = create) |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +### recover_transactions_parallel |
| 29 | + |
| 30 | +```rust |
| 31 | +impl CipherBftEvmConfig { |
| 32 | + pub fn recover_transactions_parallel(&self, txs: &[Bytes]) -> Vec<RecoveredTx>; |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +Recovers sender addresses from all transactions in parallel. Invalid transactions are filtered with debug logging. |
| 37 | + |
| 38 | +## Execution Flow |
| 39 | + |
| 40 | +1. Consensus delivers ordered transactions via `BlockInput` |
| 41 | +2. `recover_transactions_parallel()` decodes and recovers all signatures in parallel |
| 42 | +3. Transactions sorted by `(sender, nonce)` to prevent nonce errors |
| 43 | +4. Sequential EVM execution using pre-recovered `TxEnv` |
| 44 | +5. State committed after all transactions complete |
| 45 | + |
| 46 | +## Performance |
| 47 | + |
| 48 | +Parallelization benefits scale with: |
| 49 | +- Number of CPU cores |
| 50 | +- Transactions per block |
| 51 | +- Signature recovery cost (~100μs per tx) |
| 52 | + |
| 53 | +For blocks with 100+ transactions, expect 2-4x speedup on multi-core systems. |
| 54 | + |
| 55 | +## Configuration |
| 56 | + |
| 57 | +No configuration required. Rayon automatically uses available CPU cores. |
| 58 | + |
| 59 | +To limit parallelism (e.g., for testing): |
| 60 | + |
| 61 | +```rust |
| 62 | +rayon::ThreadPoolBuilder::new() |
| 63 | + .num_threads(4) |
| 64 | + .build_global() |
| 65 | + .unwrap(); |
| 66 | +``` |
0 commit comments