Bug Description
Segmentation fault crash when running examples/03_send_transaction at "Example 3: Transaction with Middleware". The crash occurs after successfully creating legacy and EIP-1559 transactions, specifically when attempting to use middleware functionality.
Error Output
Example 3: Transaction with Middleware
───────────────────────────────────────
zsh: segmentation fault ./zig-out/examples/03_send_transaction
Successful Output Before Crash
The example successfully completes:
- ✅ Wallet creation
- ✅ Provider connection to Sepolia
- ✅ Example 1: Legacy transaction creation
- ✅ Example 2: EIP-1559 transaction creation
- ❌ CRASH at Example 3: Transaction with Middleware
Steps to Reproduce
-
Build the examples:
zig build -Dexamples examples
-
Run example 03:
./zig-out/examples/03_send_transaction
-
Crash occurs at Example 3 (middleware section)
Expected Behavior
Should successfully demonstrate transaction creation with gas middleware without crashing.
Environment
- Zig Version: 0.14.1
- OS: macOS (darwin 23.6.0)
- Architecture: ARM64 (Apple Silicon)
- Network: Sepolia testnet
Code Context
Check examples/03_send_transaction.zig around Example 3:
// Example 3: Transaction with Middleware
std.debug.print("Example 3: Transaction with Middleware\n", .{});
std.debug.print("───────────────────────────────────────\n", .{});
{
// Likely creating GasMiddleware and using it
// Crash happens here when interacting with middleware
}
Potential Root Causes
- Middleware initialization issue - GasMiddleware may not be properly initialized
- Provider lifetime - Middleware holds reference to provider that's invalid
- u256 arithmetic issue - After migrating to native u256, some gas calculations might have issues
- Memory corruption - Pointer issue in middleware code
Related Code Areas
src/middleware/gas.zig - Gas middleware implementation
examples/03_send_transaction.zig - Failing example (around line 120-140)
- Related to recent u256 migration where we changed:
.mulScalar() → *
.add() → +
.sub() → -
Additional Context
- This crash occurs after the u256 migration where arithmetic operations were changed
- Other examples work fine:
Impact
- Severity: High - Segmentation fault is a critical error
- Scope: Affects middleware usage in examples (possibly production code too)
- User Impact: Cannot use gas middleware functionality
Related Issues
Next Steps
- Review
examples/03_send_transaction.zig lines around Example 3
- Check if GasMiddleware properly handles native u256 arithmetic
- Verify all gas calculation methods work with native u256
- Add null pointer checks in middleware
- Run under debugger to get exact crash location
Testing
After fix, verify with:
zig build -Dexamples examples
./zig-out/examples/03_send_transaction
# Should complete all examples without crash
Bug Description
Segmentation fault crash when running
examples/03_send_transactionat "Example 3: Transaction with Middleware". The crash occurs after successfully creating legacy and EIP-1559 transactions, specifically when attempting to use middleware functionality.Error Output
Successful Output Before Crash
The example successfully completes:
Steps to Reproduce
Build the examples:
Run example 03:
Crash occurs at Example 3 (middleware section)
Expected Behavior
Should successfully demonstrate transaction creation with gas middleware without crashing.
Environment
Code Context
Check
examples/03_send_transaction.zigaround Example 3:Potential Root Causes
Related Code Areas
src/middleware/gas.zig- Gas middleware implementationexamples/03_send_transaction.zig- Failing example (around line 120-140).mulScalar()→*.add()→+.sub()→-Additional Context
Impact
Related Issues
Next Steps
examples/03_send_transaction.ziglines around Example 3Testing
After fix, verify with:
zig build -Dexamples examples ./zig-out/examples/03_send_transaction # Should complete all examples without crash