-
Notifications
You must be signed in to change notification settings - Fork 711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The new opcode to calculate the ContractId
or PredicateId
inside of the script/contract
#490
Comments
Can you describe what the use case would be for calculating the predicate ID on the fly? How would we handle cases for things like configuration time constants? |
Let's imagine you have a script/contract that needs to create a personal predicate (where the owner or any other data is hardcoded into the predicate's bytecode). The script/contract should have/load the predicate's bytecode into memory, replace the dummy values with the actual owner's data, and calculate a new predicate id. Because the predicate's bytecode is a part of the script/contract, it has to be compiled before with some "default"/"dummy" values from configurable constants. The developer of the script/contract should handle the actualization of the data to personalize the predicate. |
Calculating contract IDs & predicate IDs is definitely a useful feature. IMO the most difficult part is filling in the configurable constants before calculating the root, I guess that's something that should probably be a feature added to Sway? Regarding this opcode, I guess it would primarily be used to take a byte array and calculate the binary merkle tree root? Would it be possible to do this as a precompile instead of an opcode? |
Why can't this be done at the language level? I understand it may be complex, but still feels like something that can be done through library and not an opcode. |
It can be done on the language level, but it would be much cheaper in terms of gas for the end-user. We already provide the The code root calculation requires a binary Merkle tree, and implement it on the Sway will be too expensive. |
Some users have use cases where they need to calculate the predicate id on the fly inside of the script. Adding a new opcode would be nice because it would be much cheaper to do inside on the VM side than on the Sway side.
We can add an opcode that calculates the contract's root, and then on the Sway side, the user can concatenate it with the
ChainId
and generate a predicate id. Or we can add an opcode that returns the predicate id directly.Another question, do we want to do the same for
ContractId
? Maybe it is not too actual because usually, you also need state root(storage slots).The text was updated successfully, but these errors were encountered: