concordium-rust-smart-contracts icon indicating copy to clipboard operation
concordium-rust-smart-contracts copied to clipboard

Look into using unchecked addition for some of the loops in LEB128

Open limemloh opened this issue 2 years ago • 0 comments

The current implementation of LEB128 for CIS2 token amounts uses checked addition to prevent overflowing when parsing each byte. Depending on the integer byte size, the overflow will not be possible for some of the first bytes being parsed and could be optimized by using non-checked addition. Before doing so, the impact on wasm code size and energy cost should be review.

for i in 0..18 {
   ... // Unchecked addition
}
for i in 18..37 {
   ... // Checked addition
}

Related discussion: https://github.com/Concordium/concordium-rust-smart-contracts/pull/108#discussion_r888835899

limemloh avatar Jun 07 '22 08:06 limemloh