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

Bytes implementation #135

Open
3 of 6 tasks
virgil-serbanuta opened this issue Oct 2, 2024 · 0 comments
Open
3 of 6 tasks

Bytes implementation #135

virgil-serbanuta opened this issue Oct 2, 2024 · 0 comments
Labels

Comments

@virgil-serbanuta
Copy link
Member

virgil-serbanuta commented Oct 2, 2024

Bytes values should be held in a configuration cell, and we should provide hooks to access them. The Rust code should see only the IDs of these values. These hooks should be callable as normal Rust functions, but their implementation should work with the bytes cell.

We need hooks for:

  • creating an empty bytes value
  • bytes length
  • concatenating bytes
  • extracting substrings
  • testing equality
  • converting to/from Rust values (ints, Int256, Strings)

The Bytes struct will hold the bytes ID (u32).

We will add a Bytes trait that has: Empty(), FromId(u32), len(self), substr(self, start, end), appendTo(self, Bytes), equalTo(self, Bytes). Perhaps also toU8(self), toU16(self), ... and fromU8(u8), fromU16(u16), ...

We will also need the following:

syntax Expression ::= bytesStructFromKBytes(Expression)  [strict]
rule bytesStructFromKBytes(wrapped(B:Bytes)) => newStruct(bytesType, addBytesAndReturnId(B) , .CallParamsList)

syntax Expression ::= addBytesAndReturnId(Bytes)

rule <k> addBytesAndReturnId(B:Bytes) => ptrValue(null, u32(NextId)) ... <k>
     <buffers> Bs => Bs[NextId <- B] </buffers>
     <next-buffer-id> NextId => NextId +Int 1 </...>

and something similar for

syntax Expression ::= kBytesStructFromStructBytes(Expression)  [strict]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant