pub struct GasAnalyzer;Expand description
Analyses gas usage for opcode sequences without full execution context.
Implementations§
Source§impl GasAnalyzer
impl GasAnalyzer
Sourcepub fn analyze_gas_usage(opcodes: &[u8], fork: Fork) -> GasAnalysis
pub fn analyze_gas_usage(opcodes: &[u8], fork: Fork) -> GasAnalysis
Analyse gas usage for a raw opcode byte sequence.
Operands are estimated heuristically; for precise analysis, use
DynamicGasCalculator::analyze_sequence_gas with explicit operands.
Examples found in repository?
examples/gas_analysis.rs (line 36)
10fn main() {
11 println!("EOT - Gas Analysis Example\n");
12
13 // 1. Dynamic gas calculation
14 println!("== Dynamic Gas (Berlin) ==");
15 let calc = DynamicGasCalculator::new(Fork::Berlin);
16 let mut ctx = ExecutionContext::new();
17
18 let cold = calc.calculate_gas_cost(0x54, &ctx, &[0x100]).unwrap();
19 println!("SLOAD cold: {cold} gas");
20
21 // Warm the slot
22 let key = {
23 let mut k = [0u8; 32];
24 k[24..32].copy_from_slice(&0x100u64.to_be_bytes());
25 k
26 };
27 let addr = ctx.current_address;
28 ctx.mark_storage_accessed(&addr, &key);
29 let warm = calc.calculate_gas_cost(0x54, &ctx, &[0x100]).unwrap();
30 println!("SLOAD warm: {warm} gas");
31 println!();
32
33 // 2. Sequence analysis
34 println!("== Sequence Analysis ==");
35 let seq = [0x60, 0x54, 0x54, 0x01, 0x55];
36 let analysis = GasAnalyzer::analyze_gas_usage(&seq, Fork::London);
37 println!("Total gas: {}", analysis.total_gas);
38 println!("Efficiency: {}%", analysis.efficiency_score());
39 for opt in analysis.get_optimization_recommendations() {
40 println!(" Tip: {opt}");
41 }
42 println!();
43
44 // 3. Fork comparison
45 println!("== Istanbul -> Berlin Changes ==");
46 let report = GasComparator::generate_comparison_report(Fork::Istanbul, Fork::Berlin);
47 report.print_report();
48 println!();
49
50 // 4. Optimization advice
51 println!("== Cancun Optimizations ==");
52 for tip in GasOptimizationAdvisor::get_fork_optimizations(Fork::Cancun) {
53 println!(" - {tip}");
54 }
55}Auto Trait Implementations§
impl Freeze for GasAnalyzer
impl RefUnwindSafe for GasAnalyzer
impl Send for GasAnalyzer
impl Sync for GasAnalyzer
impl Unpin for GasAnalyzer
impl UnsafeUnpin for GasAnalyzer
impl UnwindSafe for GasAnalyzer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more