Skip to content

Latest commit

 

History

History
145 lines (111 loc) · 3.36 KB

File metadata and controls

145 lines (111 loc) · 3.36 KB

Gas Benchmarks - Quick Reference

Files Added/Modified

✓ contracts/attestation/src/gas_benchmark_test.rs  (NEW - 600+ lines)
✓ contracts/attestation/run_benchmarks.sh          (NEW - executable script)
✓ docs/contract-gas-benchmarks.md                  (NEW - comprehensive docs)
✓ BENCHMARK_IMPLEMENTATION_SUMMARY.md              (NEW - implementation summary)
✓ README.md                                        (MODIFIED - added benchmark section)
✓ contracts/attestation/src/lib.rs                 (MODIFIED - added test module)

Quick Start

# Navigate to contract directory
cd contracts/attestation

# Run all benchmarks
./run_benchmarks.sh --all

# Run specific categories
./run_benchmarks.sh --core      # Core operations
./run_benchmarks.sh --batch     # Batch operations
./run_benchmarks.sh --fee       # Fee calculations
./run_benchmarks.sh --summary   # Summary only

# Run individual test
cargo test bench_submit_attestation_no_fee -- --nocapture

Test Coverage

  • Total tests: 106 (20 new benchmark tests)
  • All passing: ✓
  • Coverage: >95%

Benchmark Categories

  1. Core Operations (7 tests)

    • submit_attestation (no fee)
    • submit_attestation (with fee)
    • verify_attestation
    • revoke_attestation
    • migrate_attestation
    • get_attestation
    • get_fee_quote
  2. Batch Operations (2 tests)

    • Small batch (n=5)
    • Large batch (n=20)
  3. Fee Calculations (4 tests)

    • Tier discount
    • Volume discount
    • Combined discounts
    • Fee quote
  4. Access Control (2 tests)

    • grant_role
    • has_role
  5. Edge Cases (2 tests)

    • Verify revoked
    • Max entropy root
  6. Analysis (2 tests)

    • Read vs Write comparison
    • Summary report

Target Ranges

Operation CPU Target Memory Target
submit_attestation (no fee) < 500k < 10k
submit_attestation (with fee) < 1M < 15k
verify_attestation < 200k < 5k
revoke_attestation < 300k < 8k
migrate_attestation < 400k < 10k
get_attestation < 100k < 3k
get_fee_quote < 150k < 5k

Regression threshold: 150% of target values

Sample Results

=== submit_attestation (no fee) ===
CPU instructions: 35,750
Memory bytes: 5,648

=== submit_attestation (with fee) ===
CPU instructions: 150,524
Memory bytes: 21,975

=== Batch (n=5) ===
Average per operation - CPU: 26,212, Memory: 4,381

Integration with CI/CD

# .github/workflows/test.yml
- name: Run gas benchmarks
  run: |
    cd contracts/attestation
    cargo test gas_benchmark_test

Documentation

  • Methodology: docs/contract-gas-benchmarks.md
  • Implementation: BENCHMARK_IMPLEMENTATION_SUMMARY.md
  • Usage: README.md

Git Branch

# Current branch
git branch
# * feature/contract-gas-benchmarks

# View commits
git log --oneline -4
# 76dc348 fix: update budget API
# 1efa5c5 docs: add implementation summary
# 5f0c770 docs: add sample output
# e068da1 test: add gas benchmarks

Next Steps

  1. Review implementation
  2. Merge to main
  3. Integrate into CI/CD
  4. Monitor benchmark results
  5. Update targets as needed

Support

For questions or issues:

  • See docs/contract-gas-benchmarks.md for detailed documentation
  • Check BENCHMARK_IMPLEMENTATION_SUMMARY.md for implementation details
  • Run ./run_benchmarks.sh --help for usage information