use prefixes for the merkle tree

Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
Uncle Stretch 2026-09-08 22:08:12 +03:00
parent 33161daa00
commit 16006babb7
Signed by: str3tch
GPG Key ID: 84F3190747EE79AA
2 changed files with 21 additions and 11 deletions

View File

@ -18,13 +18,15 @@ pip install web3 tqdm
The Ghost Preclaim Snapshot Tool provides a straightforward command-line interface for collecting NFT snapshot data across multiple blockchain networks. Before running the tool, ensure you have properly configured your environment with the necessary RPC endpoints and network access credentials.
```bash
python finder.py --rpc <RPC_URL> [--delay 0.3]
```
usage: finder.py [-h] --rpc RPC [--bonus BONUS] [--delay DELAY]
Parameters:
```bash
--rpc: EVM JSON-RPC endpoint URL
--delay: (Optional) Delay between RPC requests in seconds (default: 0.3)
EVM NFT Snapshot Collector for Ghostchain Preclaims
options:
-h, --help show this help message and exit
--rpc RPC EVM JSON-RPC Node URL
--bonus BONUS Additional JML ownership amounton top of the collateral (default: 6.9 CSPR)
--delay DELAY Delay between RPC requests in seconds (default: 0.3)
```
Example:
@ -38,13 +40,20 @@ python finder.py --rpc https://sepolia.infura.io/v3/YOUR_KEY
The Merkle proof generation module transforms raw snapshot data into cryptographically verifiable proofs that enable efficient and secure preclaim verification on the Ghostchain governance platform. This critical component ensures that only legitimate NFT holders can participate in governance decisions and claim their allocations.
```bash
python forester.py --chain <CHAIN_NAME>
usage: forester.py [-h] --network-id NETWORK_ID
Dynamic Merkle Tree for Ghost Preclaims
options:
-h, --help show this help message and exit
--network-id NETWORK_ID
EVM numeric Network ID to mix into preimage (e.g., 11155111)
```
Example:
```bash
python forester.py --chain 11155111
python forester.py --network-id 11155111
```
Output:

View File

@ -17,7 +17,8 @@ def parse_arguments():
def keccak256(data: bytes) -> bytes:
return keccak(data)
EMPTY_HASH = keccak256(b'')
# prefix + empty bytes
EMPTY_HASH = keccak256(b'\x00' + b'\x00' * 32)
def next_power_of_two(n: int) -> int:
if n <= 1:
@ -47,7 +48,7 @@ def generate_tree(raw_values, network_id):
for item in raw_values:
idx = item['index']
preimage = generate_preimage(item['token_id'], item['address'], item['shares'], network_id)
merkle_tree[idx] = keccak256(preimage)
merkle_tree[idx] = keccak256(b'\x00' + preimage)
layer_start = 0
current_layer_len = padded_leaves
@ -59,7 +60,7 @@ def generate_tree(raw_values, network_id):
left_bytes = merkle_tree[layer_index]
right_bytes = merkle_tree[layer_index | 1]
combined = left_bytes + right_bytes
combined = b'\x01' + left_bytes + right_bytes
merkle_tree[write_ptr] = keccak256(combined)
write_ptr += 1