fuels-rs icon indicating copy to clipboard operation
fuels-rs copied to clipboard

Single-byte optimization of `u8`s and `bool`s for `Configurable`s

Open segfault-magnet opened this issue 1 year ago • 1 comments

@DefiCake raised an issue about failing to configure the configurables of a contract. A repro was provided here.

It would seem that the u8 in the configurables part of the contract binary is encoded with single byte optimizations resulting in 1B of data.

When we encode a u8 to replace the default configurable we turn the u8 into a Token::U8 and give it to the ABIEncoder. It, in turn, sees that we're encoding a single argument of the type u8 (or bool for that matter) and proceeds to encode it as a big endian u64. This edge case comes from the way a fn(u8) or fn(bool) expects its argument to be encoded.

Checked with @xunilrj, Q:

Asking because it makes our encoding context dependent. The encoding of a u8 or bool changes depending if you're trying to call a function or configure some configurables.

Answer:

Yes. It is context-sensitive, because it depends on where the data is. When calling functions they are read from registers; and from configurable they are read from memory. 

We didn't catch this (even though we have u8s in test configurables) because we never set it. Don't know why it was singled out as all other members were set.

segfault-magnet avatar Jan 31 '24 15:01 segfault-magnet

Waiting for https://github.com/FuelLabs/fuels-rs/pull/1249 to land so that we have some place to put the config needed.

segfault-magnet avatar Feb 03 '24 07:02 segfault-magnet