Skip to content

Instantly share code, notes, and snippets.

@nzenov
nzenov / Suggestion-lucky-draw.md
Last active March 24, 2026 03:48
Suggestion to Lucky draw vault

Smart Contract Gas Optimization: Scaling a Weighted Lucky Drop Vault

1. Problem Statement

The original LuckyDropVault smart contract implemented a weighted random lottery but was constrained to a maximum of 255 participants due to gas limits. The goal was to scale the contract to support thousands of participants without exceeding block gas limits during registration, drawing, and state resets.

2. The Power of 2 (Adjusting for 4,096 Users)

To maintain a perfectly balanced binary tree in a flat array, the maximum capacity (MAX_LEAVES) must be a power of 2.

  • To support roughly 4K to 5K users with the absolute minimum storage footprint, we are optimizing the tree to exactly 4,096.
  • For 4,096 leaves, the tree requires (4096 * 2) - 1 = 8191 total nodes.
  • Gas Note: Reducing the tree size to 4,096 decreases the tree depth to 12. This requires at most 12 loop iterations for any registration or draw operation, ensuring gas costs remain predictably low and entirely safe from block limits.
@nzenov
nzenov / audit_claude_sonnet_4.6.md
Last active March 1, 2026 09:25
FlapBNBDividendTrackerWithFlap Smart Contract Audit Report

Smart Contract Audit Report

Auditor: GitHub Copilot (Claude Sonnet 4.6)
Contract(s): FlapBNBDividendTrackerWithFlap.sol (V1) · FlapBNBDividendTrackerWithFlapV2.sol (V2) · FlapBNBDividendTrackerWithFlapV4.sol (V4) · FlapBNBDividendTrackerWithFlapV5.sol (V5 — remediation review)
Date: February 28, 2026

NOTE: This report is generated by an AI model and should be reviewed by a human auditor for accuracy and completeness.