Closed limemloh closed 2 years ago
I have implemented a token amount of u64 using LEB128 for serializing and deserializing and compared it to the current implementation, which is using the serialization and deserialization of u64.
On testnet I deployed the wCCD example with LEB128 and with u64 for token amount. I then initialized each contract, wrapped 10 CCD, transferred 10 wrapped microCCD, unwrapped 10 microCCD while recording the costs.
Both contracts are build with no-std, embedded schema using:
Contract | Module Size | Deploy | Init | wrap 10 | transfer 10 | unwrap 10 |
---|---|---|---|---|---|---|
Fixed u64 | 48759 B | 53796 NRG | 1945 NRG | 1890 NRG | 2156 NRG | 2185 NRG |
LEB amount u64 | 49781 B | 54919 NRG | 1956 NRG | 1903 NRG | 2162 NRG | 2194 NRG |
From the above results we have concluded to use LEB128 encoding of token amount in CIS2
Tokens standards on Ethereum uses an unsigned 256 integer to represent token amounts, which might cause issues with CIS2's choice of using u64 when application across bridges.
We should reseach the implications of using a variable length encoding such as LEB128 for token amounts in order to support large token amounts while still keeping the option to use a smaller type for the smart contract implementation.
We do this by implementing LEB128 for serializing token amounts in one of the examples and observe the difference in energy cost for interaction and smart contract module size.