7.7 KiB
WETH9 1:1 Ratio Verification - Complete Implementation
Overview
This document provides a complete guide for verifying that WETH9 maintains a strict 1:1 ratio with ETH. All verification tools and scripts have been created and are ready to use.
Tools Created
1. Contract Inspection Script
File: scripts/inspect-weth9-contract.sh
Purpose: Inspects the WETH9 contract implementation without requiring transactions.
Usage:
./scripts/inspect-weth9-contract.sh
What it checks:
- Contract existence and bytecode
- ERC-20 function availability (balanceOf, totalSupply, decimals)
- 1:1 backing verification (contract ETH balance = total supply)
- Function signatures in bytecode
- Bytecode size analysis
Output: Reports whether contract appears to maintain 1:1 backing.
2. Ratio Verification Script
File: scripts/verify-weth9-ratio.sh
Purpose: Tests the actual 1:1 ratio by performing a real deposit transaction.
Usage:
./scripts/verify-weth9-ratio.sh [private_key] [test_amount]
Example:
./scripts/verify-weth9-ratio.sh 0xYourPrivateKey 0.001
What it does:
- Checks initial balances
- Wraps a test amount (e.g., 0.001 ETH)
- Measures exact WETH9 received
- Calculates and reports the ratio
- Verifies contract backing
Output: Reports if ratio is exactly 1:1 or if there's a mismatch.
3. Deposit Test Suite
File: scripts/test-weth9-deposit.sh
Purpose: Comprehensive testing with multiple amounts to verify consistency.
Usage:
./scripts/test-weth9-deposit.sh [private_key] [amount1] [amount2] ...
Example:
./scripts/test-weth9-deposit.sh 0xYourPrivateKey 0.001 0.01 0.1
What it does:
- Tests multiple deposit amounts
- Verifies 1:1 ratio for each amount
- Calculates gas costs separately
- Provides detailed results for each test
- Summary report of all tests
Output: Pass/fail for each test amount and overall summary.
4. Standard Comparison Script
File: scripts/compare-weth9-standard.sh
Purpose: Compares local WETH9 contract with standard WETH9 implementation.
Usage:
./scripts/compare-weth9-standard.sh
What it checks:
- Function signatures match standard WETH9
- Contract behavior matches standard (1:1 backing)
- Decimals function (if available)
- Bytecode characteristics
Output: Reports differences from standard WETH9.
5. Updated Wrap Script
File: scripts/wrap-and-bridge-to-ethereum.sh
Enhancement: Now includes automatic 1:1 ratio verification after wrapping.
What it does:
- Wraps ETH to WETH9
- Automatically verifies 1:1 ratio after wrap
- Warns if ratio is not 1:1
- Provides detailed logging
Verification Workflow
Step 1: Inspect Contract (No Transaction Required)
./scripts/inspect-weth9-contract.sh
This will:
- ✅ Check if contract exists
- ✅ Verify 1:1 backing (balance = supply)
- ✅ Check function availability
- ✅ Analyze bytecode
If this passes: Contract structure looks correct.
If this fails: Contract may have implementation issues.
Step 2: Test Actual Ratio (Requires Private Key)
./scripts/verify-weth9-ratio.sh [private_key] 0.001
This will:
- ✅ Perform actual deposit transaction
- ✅ Measure exact WETH9 received
- ✅ Calculate actual ratio
- ✅ Report if ratio is 1:1
If this passes: 1:1 ratio is confirmed.
If this fails: Contract has non-1:1 behavior (fees or modifications).
Step 3: Comprehensive Testing (Optional)
./scripts/test-weth9-deposit.sh [private_key] 0.001 0.01 0.1 1.0
This will:
- ✅ Test multiple amounts
- ✅ Verify consistency across different amounts
- ✅ Identify if issue is amount-specific
- ✅ Provide comprehensive report
If all pass: 1:1 ratio is consistent across all amounts.
If some fail: Issue may be amount-specific or inconsistent.
Step 4: Compare with Standard (Optional)
./scripts/compare-weth9-standard.sh
This will:
- ✅ Compare function signatures
- ✅ Check standard behavior
- ✅ Identify deviations
If matches: Contract likely matches standard WETH9.
If differs: Contract may be modified version.
Expected Results
✅ Correct 1:1 Ratio
Input: 1.0 ETH
Output: 1.0 WETH9
Ratio: 1.0 ✅
Contract Balance: 100 ETH
Total Supply: 100 WETH9
Backing: 1:1 ✅
❌ Non-1:1 Ratio (Problem)
Input: 1.0 ETH
Output: 0.99 WETH9
Ratio: 0.99 ❌
This indicates:
- Fees being deducted
- Modified contract implementation
- Accounting errors
Troubleshooting
Issue: Verification Script Fails
Possible Causes:
- Contract has fees in deposit()
- Contract implementation modified
- Network/RPC issues
Solutions:
- Run inspection script to check contract structure
- Compare with standard WETH9
- Check transaction details for hidden fees
- Consider deploying standard WETH9 if contract is modified
Issue: Ratio Varies by Amount
Possible Causes:
- Percentage-based fees
- Minimum fee thresholds
- Rounding errors at different scales
Solutions:
- Test multiple amounts (use test suite)
- Identify fee pattern
- Document fee structure
- Consider if fees are acceptable
Issue: Contract Balance ≠ Total Supply
Possible Causes:
- ETH withdrawn without burning WETH9
- Accounting errors
- Contract bugs
Solutions:
- This is a CRITICAL issue
- Contract may be compromised
- Consider emergency measures
- May need contract replacement
Documentation
All documentation is available in the docs/ directory:
- WETH9_1_TO_1_RATIO_VERIFICATION.md - Detailed verification guide
- WETH9_RATIO_ISSUE_REVIEW.md - Problem analysis and investigation
- WRAP_AND_BRIDGE_TO_ETHEREUM.md - Wrapping and bridging guide
- WETH9_VERIFICATION_COMPLETE.md - This document
Quick Reference
Run All Verifications
# 1. Inspect contract (no key needed)
./scripts/inspect-weth9-contract.sh
# 2. Test ratio (needs private key)
./scripts/verify-weth9-ratio.sh [private_key] 0.001
# 3. Comprehensive test (needs private key)
./scripts/test-weth9-deposit.sh [private_key] 0.001 0.01 0.1
# 4. Compare with standard (no key needed)
./scripts/compare-weth9-standard.sh
Check Specific Values
# Contract balance
cast balance 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 \
--rpc-url http://192.168.11.250:8545
# Total supply
cast call 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 \
"totalSupply()" --rpc-url http://192.168.11.250:8545
# User balance
cast call 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 \
"balanceOf(address)" [address] \
--rpc-url http://192.168.11.250:8545
Next Steps After Verification
If Ratio is 1:1 ✅
- Document the verification - Record test results
- Update documentation - Note that ratio is confirmed
- Continue using contract - No changes needed
If Ratio is NOT 1:1 ❌
- Document the issue - Record exact amounts and ratio
- Investigate contract - Decompile and analyze bytecode
- Compare with standard - Identify differences
- Determine solution:
- If fees are intentional: Document fee structure
- If bug: Report and fix
- If modified: Consider deploying standard WETH9
Summary
All verification tools are now available:
✅ Contract inspection script
✅ Ratio verification script
✅ Comprehensive test suite
✅ Standard comparison script
✅ Updated wrap script with verification
To verify 1:1 ratio, run:
./scripts/verify-weth9-ratio.sh [private_key] 0.001
For comprehensive testing:
./scripts/test-weth9-deposit.sh [private_key] 0.001 0.01 0.1
All tools are ready to use and will provide detailed reports on whether the WETH9 contract maintains the required 1:1 ratio with ETH.