Predicate address

Hello FuelWorld i have a question regarding predicate . so when i compile my predicate i have always the same output (Root and address) . what if i want to generate a new predicate with differente address with the same code .

1 Like

Hey @Raoufboukyxz great question! To summarize a predicate root/address is deterministic by the calculation below so a predicate with the same code will ALWAYS return the same address.

the predicate owner is calculated as: sha256(0x4655454C ++ root(input.predicate)), where root is the Merkle root of the binary Merkle tree each leaf being 16KiB of instructions.

Please refer to this part of the documentation for more information
Predicate tutorial: Predicate Root | Fuel Docs
Predicate calculation: Fuel Specifications | Fuel Docs

3 Likes

Correct if im wrong . but if someone create a predicate and send some amount of fuel to the address generated by the predicate , and another dev create the same predicate with exactly the same code and the same condition , they are going to have the same address ?

3 Likes

Yeah, the same code does indeed produce the same predicate root.

Predicate Root | Fuel Docs
image

3 Likes

Yes that is correct like @crypt0mate says! Hope this helps :slight_smile:

2 Likes

To add a little more context, you’ll often use configurables in predicates to update addresses for different users.

For example, if you’re making a special wallet predicate, you probably want to add an OWNER configurable. You write the predicate code in Sway once, but you customize the value of this configurable for each user that wants to use the predicate.

By updating this configurable, you change the full bytecode, and therefore the predicate address, meaning each user ends up with a unique predicate.

4 Likes

Ok Cool ,Thank you guys .

2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.