Skip to content

zrlcode-55/FinVerify

Repository files navigation

FinVerify - Project Progress Report

Status: Core implementation complete and working

What's Working

  • Z3 SMT solver integrated and verifying properties
  • Hoare logic verification conditions implemented
  • ERC-20 token conservation proven mathematically
  • Bridge replay attack vulnerability detected
  • Test suite passing (all 11 tests green)

Automated Verification in Action

The system is fully automated - just run it and Z3 proves properties or finds bugs:

Verification Results:

  • good! ERC-20 Conservation: VERIFIED (proven impossible to create/destroy tokens)
  • good! Bridge Conservation: VERIFIED(locked == minted guaranteed)
  • good! Overflow Protection: VERIFIED (arithmetic overflow prevented)
  • still workin! Buggy Bridge: VIOLATED(replay attack found automatically!)

Time to verify all properties: about 0.1 seconds

This demonstrates the power of SMT based verification - mathematical proofs happen automatically, no manual theorem proving needed.

Testing Progress

Built comprehensive test suite with 11 tests covering:

  • Property Checker Tests (4 tests)

    • Token conservation verification
    • Bridge conservation verification
    • Overflow protection verification
    • Buggy bridge detection
  • ERC-20 Contract Tests (4 tests)

    • Initial supply correctness
    • Transfer functionality
    • Insufficient balance handling
    • Unauthorized mint detection (bug)
  • Bridge Contract Tests (3)

    • Lock mechanism
    • Mint mechanism
    • Replay protection (finds vulnerability)

All tests pass and demonstrate both correct verification AND bug finding capabilities.

Sample Code - Token Conservation Proof

Here's the Z3 encoding that proves tokens can't be created and or destroyed:

# variables for transfer
alice_before = Int('alice_before')
bob_before = Int('bob_before')
transfer_amount = Int('transfer_amount')

# Transfer logic
solver.add(alice_after == alice_before - transfer_amount)
solver.add(bob_after == bob_before + transfer_amount)

# Try to violate conservation
total_before = alice_before + bob_before
total_after = alice_after + bob_after
solver.add(total_before != total_after)

# Result: UNSAT (impossible) - conservation is PROVEN

Sample Code - Bug Detection

Found real replay attack vulnerability in bridge:

def verify_buggy_bridge(self):
    # Lock 1000 tokens once
    solver.add(locked_A_1 == locked_A + 1000)
    
    # Mint twice (replay attack!)
    solver.add(minted_B_1 == minted_B + 1000)
    solver.add(minted_B_2 == minted_B_1 + 1000)  # No replay protection
    
    # Check invariant violation
    solver.add(locked_A_1 != minted_B_2)
    
    # Result: SAT - BUG FOUND! Attacker steals 1000 tokens

Sample Code - Automated Test suite

Tests verify the verifier actually itself works:

def test_erc20_conservation(self):
    checker = PropertyChecker()
    result = checker.verify_erc20_conservation(1000,2)
    assert result == VerificationResult.VERIFIED
    # passes! conservation property proven automatically

def test_buggy_bridge(self):
    checker = PropertyChecker()
    result = checker.verify_buggy_bridge()
    assert result == VerificationResult.VIOLATED
    # it passes! bug detected automatically

Next Steps

  • Document formal verification theory connections
  • Add more complex properties (temp logic)
  • Performance benchmarks

Running the Code

pip install z3-solver pytest
python run_full_pipeline.py
python -m pytest test_suite.py -v

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages