dusk-network / rusk-vm

The Dusk Rust WASM VM implementation
Mozilla Public License 2.0
54 stars 12 forks source link

Consider different mechanism for creating contract id #348

Closed miloszm closed 2 years ago

miloszm commented 2 years ago

Describe what you want implemented Implement contract id creation mechanism that has no 1-1 mapping with contract bytecode.

Describe "Why" this is needed Currently, in VM2 (and in VM1), contract id is a 256 bit hash of contract's bytecode. This is not only relatively time-consuming to calculate but also makes it impossible to have more than one contract with the same bytecode.

Describe alternatives you've considered Alternative is to keep current solution, which is to calculate blake2b hash from a bytecode each time a given wasm module is compiled and added to the cache.

Additional context Contract id needs to be calculated only once and there is no need to calculate it again. Hence, it could be a random, UUID- based constant. That would have two advantages - improved performance and the ability of having multiple contracts with the same code. Related to issues #344 and #333.

ZER0 commented 2 years ago

I will close it as wontfix, for the reasons below:

  1. The contract id has to be deterministic, and it has to be tied to the bytecode (plus additional metadata, currently is only bytecode)

  2. The contract id has to be a valid BlsScalar: this is not something the VM should be bother with, since the ZK layer is added on top of it, and that's why we have deploy_with_contract_id method.

To sum up, since the 1-1 mapping with the contract is a pre-requisite this cannot be "fixed".