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

[LSP2] Adding 2 bytes as length of the compact bytes array #145

Open
YamenMerhi opened this issue Nov 29, 2022 · 7 comments
Open

[LSP2] Adding 2 bytes as length of the compact bytes array #145

YamenMerhi opened this issue Nov 29, 2022 · 7 comments

Comments

@YamenMerhi
Copy link
Member

What this issue is about ?

Problem

  • Currently there is no way to know the number of elements of a compacted bytes array

Solution

  • Adding 2 bytes as length of the compact bytes array at the start
@CJ42
Copy link
Member

CJ42 commented Dec 5, 2022

This is a good suggestion as so far, the only way to do this is by looping through the bytes, which can be expensive if there are a lot of elements.
This might be a good to have.

What do you think @frozeman @skimaharvey @b00ste ?

@skimaharvey
Copy link
Member

skimaharvey commented Dec 10, 2022

Definitely could be useful to have an easy way to know the number of elements without having to loop over all the elements. The only thing I am not sure about is that it will kind of force us to verify the validity of the length value in comparison to each length element (length value = the total number of length elements) so we will need to loop over the entire compact byte array when storing.
In the LSP6 context, I am not sure we want to do that but at the same time, I don't think we want to store a length value that does not make sense.
I am just wondering what real value we will get from it since it is not trustable

@JeneaVranceanu
Copy link
Member

I'm currently in the process of opening a lengthy issue on CBAs and decided to look if there's anything open related to CBAs. Found this issue and I'd like to join the "brainstorming" 🙂


The only thing I am not sure about is that it will kind of force us to verify the validity of the length value

@skimaharvey Why will it force you to validate the length? Are we forced to validate the length on Solidity's arrays?

I'll put the question differently: if we are calling setData with key whose valueType is some_type[] (the emphasis is on the [] part) we do not validate it on the smart contract side? I do not expect it to be validated on the smart contract side.

If that's true we can receive some ABI from getData for type some_type[] which will not be valid as well and the decoding attempt will fail.

It all results in the following question: if we do not validate ABI in setData then is anything from getData really trustable?

@CJ42
Copy link
Member

CJ42 commented Oct 17, 2023

Is this implemented already I think?

@CJ42
Copy link
Member

CJ42 commented Nov 9, 2023

Is this implemented already I think?

It's actually not. It's an extra 2 byte at the beginning to return the CompactBytesArray.length

@CJ42
Copy link
Member

CJ42 commented Nov 9, 2023

I'll put the question differently: if we are calling setData with key whose valueType is some_type[]

In the case of setData, the type for the data key will always be bytes32

@JeneaVranceanu
Copy link
Member

I think you are talking about key and I was talking about value for setData(key, value).
To keep it short: we need to add array length support for CompactBytesArray.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants