You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reason for the difference is that the decode_vector function does not match the encode_vector function. While the encoding adds a pointer, capacity and length of the array, the decoding function interprets them as values.
Figure 14.1: Decoding function for vectors. (fuels-rs/packages/fuels-core/src/codec/abi_decoder.rs#92–100)
Short term, change the decode_vector function such that it expects a pointer, length and capacity.
Long term, add tests which verify that the encoded value always decodes to its original value.
The text was updated successfully, but these errors were encountered:
So it turns out that this is actually expected behavior.
Vectors can be returned from contracts only thanks to custom bytecode injection, as can be seen in
// The instructions are different if you want to return data that was on the heap
. This bytecode injection is necessary because otherwise, what the VM returns is only the pointer to the data.
It is therefore necessary that the decoding is different from the encoding.
Description
The encoding and decoding of vectors is inconsistent. The decoded values do not match the original values. The following test demonstrates this.
Figure 14.1: Test which demonstrates that encoding and decoding a vector results in two different vectors.
Figure 14.2: The output of executing the test form 14.1.
Tokens: Vector([U64(42)]) Encoded: "000000000000001800000000000000010000000000000001000000000000002a" Type: Vector(U64) Decoded: [Vector([U64(24), U64(1), U64(1), U64(42)])]
The reason for the difference is that the decode_vector function does not match the encode_vector function. While the encoding adds a pointer, capacity and length of the array, the decoding function interprets them as values.
Figure 14.1: Decoding function for vectors. (fuels-rs/packages/fuels-core/src/codec/abi_decoder.rs#92–100)
Recommendations
Short term, change the decode_vector function such that it expects a pointer, length and capacity.
Long term, add tests which verify that the encoded value always decodes to its original value.
The text was updated successfully, but these errors were encountered: