Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARC-43 No Length in Dynamic Arrays of Static Types #214

Closed
wants to merge 5 commits into from

Conversation

joe-p
Copy link
Contributor

@joe-p joe-p commented Jun 16, 2023

Proposes the removal of element length prefix on non-nested static types.

This alone is not super important, but if we are making breaking changes to the ABI might as well include this QOL change.

@SudoWeezy SudoWeezy changed the title No Length in Dynamic Arrays of Static Types ARC-43 No Length in Dynamic Arrays of Static Types Jun 16, 2023
Copy link
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This proposal presumes that the decoder knows where the value ends. But the ABI was designed to allow decoding by walking along without knowing ahead of time where the end of a value is. PR #212 would break that design, and require extra encoding bytes, and then this PR would work. But, why would we do PR #212 which adds encoding bytes so that we can do this PR, which removes some?

@joe-p
Copy link
Contributor Author

joe-p commented Jun 16, 2023

But the ABI was designed to allow decoding by walking along without knowing ahead of time where the end of a value is

What's the value of this? In what scenarios will a decoder not know how long the data its decoding is?

But, why would we do PR #212 which adds encoding bytes so that we can do this PR, which removes some?

The byte savings isn't really the main motivation. It's mostly opcode savings. Not needing to extract/add len when working with bytes/strings and also just being able to concat to add to an array rather than concat + increment prefix

@jannotti
Copy link
Contributor

jannotti commented Jun 16, 2023

But the ABI was designed to allow decoding by walking along without knowing ahead of time where the end of a value is

What's the value of this? In what scenarios will a decoder not know how long the data its decoding is?

It's exactly the property you need so that PR #212 is not needed. You don't have to know how much of the input remains to be decoded, so you don't have to substring out the value to decode it.

@joe-p
Copy link
Contributor Author

joe-p commented Jun 16, 2023

It's exactly the property you need so that PR #212 is not needed. You don't have to know how much of the input remains to be decoded, so you don't have to substring out the value to decode it.

The use case #212 is trying to solve is extracting a value from a tuple without decoding the entire structure. I would think that's a much more common use-case than fully decoding the entire tuple every time you want to read one element.

@joe-p
Copy link
Contributor Author

joe-p commented Jun 23, 2023

In the public discord ARC meeting this seemed to be unanimously supported.

@jannotti
Copy link
Contributor

So this is only for top-level objects, right? The ARC says: The exception is if the array is encoded inside of a tuple. but also mean when encoding in a dynamic array, right? (since the encoding of a dynamic array itself encodes the tail as a tuple).

So we're talking the individual values in ApplicationArgs[0-15] only?

@joe-p
Copy link
Contributor Author

joe-p commented Jun 23, 2023

So this is only for top-level objects, right? The ARC says: The exception is if the array is encoded inside of a tuple. but also mean when encoding in a dynamic array, right? (since the encoding of a dynamic array itself encodes the tail as a tuple).

So we're talking the individual values in ApplicationArgs[0-15] only?

Exactly, I will clarify this in the ARC.

@joe-p joe-p mentioned this pull request Jun 23, 2023
@joe-p
Copy link
Contributor Author

joe-p commented Jun 24, 2023

I just realized that this introduces weirdness with bool[]. Given a top-level bool[] encoded as 0x00 there is no way to know how many boolean values are actually encoded.

Personally, I'd prefer to just change booleans to be encoded as 0x01 and 0x00 for reasons beyond this ARC, but the alternative is that booleans are always prefixed with their length

@joe-p joe-p closed this Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants