Lucky Bot uses future on-chain block data from ETH as a foundational seed to generate reproducible random results. When a draw occurs, the program fetches the most recent block relative to the current time and extracts relevant hash data from it. This data includes:
Due to the decentralized nature of the blockchain, unless an attacker controls more than 51% of the entire ETH network's computing power, the seed is guaranteed to be unpredictable, enhancing the fairness of the lottery results.
Block generation is a core process in a blockchain network. Taking Ethereum (ETH) as an example, blocks are packaged and generated by miners through the Proof of Work (PoW) mechanism. Whenever new transactions are broadcast to the network, miners collect these transactions and attempt to find a hash value (i.e., the block hash) that meets specific conditions by performing calculations. This process consumes a significant amount of computing power, making it difficult to predict or tamper with in advance.
Each block contains the hash of the previous block, transaction data for the current block, a timestamp, the miner's address, and other information. Because each block depends on the hash of the previous one, a chain-like structure is formed, ensuring the immutability and security of the blockchain. Only when a miner successfully finds a qualifying hash is the block added to the chain and recognized by all nodes in the network.
Precisely because of the unpredictability and decentralized nature of the block generation process, block hashes and related data on the blockchain can serve as a highly credible source of randomness, widely used in scenarios like lotteries and random number generation.
This is a Python implementation of the algorithm. Its logic is fundamentally the same as the original version and can produce identical results, which can be used to verify if the results have been tampered with.
The program requires Block ID, Block Hash, Miner Hash, and Block Timestamp as input. This data can be found in the Mini App or through the API of etherscan.io. It should look something like this:
countis actually an operand counter. Due to potential rollbacks, the number of operands might exceed the total number of winners. This parameter is only provided in the Mini App.
The Python implementation above includes a main.py file. Please modify the following data to reproduce the lottery results:
The order must be identical to the original list.
Format: ["Prize Name", Quantity]
The order must be identical to the participant list in the Mini App. Note that the order in the Mini App is actually a reverse chronological list of participation events, so the verification script will automatically reverse the order; no manual processing is needed.
python3 main.pypython main.pyget_random_int(max_value) is called, it generates a new pseudo-random number based on the current hash_value and takes the modulo of the target range to ensure the result falls within the specified interval.In each round of the draw, a prize is randomly selected first, then a member is randomly selected, and the winning information is recorded. If the quantity of a prize reaches 0 or a member has already won, they are removed from their respective lists, and the process continues to the next round until all prizes or members are exhausted.
Since the randomness of the entire process depends entirely on on-chain block data and the algorithm is public and transparent, anyone can reproduce the lottery results using the same block data, ensuring the fairness and immutability of the draw.