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

feat!: new encoding scheme for logs and encode `RawSlice` as `u8`

Open danielbate opened this issue 1 year ago • 0 comments

Closes #1671

This PR adds support for sway's experimental encoding in logs. This is demonstrated via a new test suite, which is a subset of fuel-gauge, which builds another forc workspace using the experimental flag (--experimental-new-encoding).

Breaking Change

RawSlice data encoded as unpadded u8, also implemented by the RS SDK. Currently we are encoding it as u64 and doing additional arithmetic on encode and decode to compute the byte length. A RawSlice indicates a slice of bytes so we should treat it as so.

This poses a problem either on v0 or v1, one will have to compromise to the other as v1 assumes the data as u8 so we'd have to do additional arithmetic to get the correct len, rather than decoding it from the byte data. I have opted to introduce the breaking change in v0 as it brings us closer to v1.

Type Support

  • [x] u8
  • [x] u16
  • [x] u32
  • [x] u64
  • [x] b256
  • [x] b512
  • [x] Array
  • [x] String Array (str[n])
  • [x] Option
  • [x] Raw Slice
  • [x] Tuple
  • [x] Struct
  • [x] Enum
  • [x] String Dynamic (struct String)
  • [x] Vec
  • [x] Bytes

:warning: String Slices are currently not supported in the TS SDK by encoding v0. This is possible in v1, however requires contract calls to be encoded as well, so the value can be encoded/decoded, and thus the logs. I have added a StrSlice coder using the specs and partially tested, but I have left it unimplemented within AbiCoder. Therefore it is currently blocked by this Sway issue.

Further changes

  • [x] Experimental integration test suite in parallel
  • [x] Use ABIEncode implementations from sway-std-lib
  • [ ] Unit tests for v1 coders
  • [ ] Refactor to ABICoder for versioning and obtaining coders
  • [ ] Needs TOB validation changes - #1426

Blockers

  • [ ] Forc 0.49.1 upgrade
  • [ ] Get encoding version from ABI - https://github.com/FuelLabs/sway/pull/5481

danielbate avatar Jan 22 '24 16:01 danielbate