Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
Prueba de Merkle en python usando Keccak256

Estoy tratando de crear una lista blanca para un NFT usando un árbol de Merkle para ahorrar en costos de gasolina. Vi una gran implementación aquí , en javascript, pero me gustaría hacerlo en Python. No parece que pueda crear un árbol merkle usando hash keccak, lo que creo que es necesario hacer para la cadena de bloques etheruem. MerkleProof.sol de Open-zeppelin utiliza hash kaccack para verificar una hoja. Supongo que puedo cambiar esto para usar sha256 en su lugar, pero no me gustan estas soluciones rápidas.

Esto es lo que probé a continuación:

 from pymerkle import MerkleTree from Crypto.Hash import keccak from scripts.helpful_scripts import get_account from brownie import NFTCollectible, network, config def hash(address): k = keccak.new(digest_bits=256) k.update(address.encode("utf_8")) return k.hexdigest() def main(): account = get_account() nft_collectible = NFTCollectible[-1] whitelistedAddresses = [ "0x5B38Da6a701c568545dCfcB03FcB875f56beddC4", "0x78D6CF3DEF45AF458442E787FE6E64A03750AB94", "0xA7B0E4CF55AF900F6E80D619AE1E00965044BC4E", "0x38C4278F42A26A588176017F5E4F6ED831835EA2", "0x9F9A0AA0507FE79CA1FF8F26A8D84BD8BB0EC9DF", "0xDABF258F5619942D19AD87C3472FABE893B26D7D", "0xD30ED9C457C7D32F3F7B949964191E4084C53F66", ] leafNodes = [] for address in whitelistedAddresses: hashedAddress = hash(address) leafNodes.append(hashedAddress) merkleTree = MerkleTree() for leaf in leafNodes: merkleTree.update(leaf) print(merkleTree) root = merkleTree.rootHash.decode("utf-8") print(root)

Sí devuelve un árbol de Merkle, pero con hash usando sha256 ya que pymerkle no tiene hash de keccak. (La biblioteca keccak anterior se usa para codificar las billeteras). Ejecutar esto devuelve un árbol de Merkle diferente al de JS. Ni siquiera estoy seguro de si la diferencia se debe al hashing.

Así es como me gustaría verificar en solidez:

 // using merkle tree for whitelist bytes32 leaf = keccak256(abi.encodePacked(msg.sender)); // this will work good since the wallets are hashed by keccak require( MerkleProof.verify(merkleProof, whitelistedMerkleRoot, leaf), // this will fail "Not on the whitelist" );
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

¿Intentó anular los métodos Pymerkle existentes para poder usar una nueva opción de codificación?

Debería incluir el tipo aquí https://github.com/fmerg/pymerkle/blob/6d4c9eb502fe7aa6117123e7f1ab8cf84a38e7b4/pymerkle/hashing/machine.py#L9

about 4 years ago · Juan Pablo Isaza Report

0

Hice un paquete específicamente por esta razón... estaba harto de usar javascript en mis proyectos Brownie jaja.

La clase MerkleTreeKeccak debería hacer exactamente lo que desea. Debe proporcionar direcciones hash como hojas, tal como lo hace con merkletreejs.

https://pypi.org/project/evm-sc-utils/

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!