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.
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 = 8191total 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.