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

Add anoma-bytearray-{to, from}-anoma-contents builtins #2960

Merged
merged 1 commit into from
Aug 19, 2024

Conversation

paulcadman
Copy link
Collaborator

The anoma-bytearray-{to, from}-anoma-contents are intended to be used to convert to/from atoms representing ByteArrays. These builtins are required temporarily until Anoma Node makes ByteArray representation uniform across all of its APIs.

We represent ByteArrays in nock as a cell:

[size contents]

Where size is the size of the ByteArray and contents is an Atom representing the bytes in LSB ordering.

The size is required in general because the encoding of ByteArrays to Atoms is ambiguous. For example the ByteArrays [0x01; 0x00] and [0x01] are represented by 1.

Some Anoma ByteArrays like keys and signatures are represented using on the contents atom because the size is constant.

Users of Anoma APIs have to strip / add size information from ByteArrays depending on where the data is used. The new builtins provide this facility.

These builtins are temporary because it's been agreed with Anoma engineering team to change the Anoma APIs to make the ByteArray representation uniform, i.e always represent ByteArrays using [size content]. When this is implemented in Anoma Node we can remove these builtins.

builtin anoma-bytearray-to-anoma-contents
axiom toAnomaContents : ByteArray -> Nat;

builtin anoma-bytearray-from-anoma-contents
axiom fromAnomaContents :
  -- | The size of the ByteArray
  Nat
  -- | The contents of the ByteArray
  -> Nat
  -- | The resulting ByteArray
  -> ByteArray;

@paulcadman paulcadman self-assigned this Aug 16, 2024
@paulcadman paulcadman added this to the 0.6.6 milestone Aug 16, 2024
The anoma-bytearray-{to, from}-anoma-contents are intended to be used
temporarily to convert to/from atoms representing ByteArrays.

We represent ByteArrays in nock as a cell:

```
[size contents]
```

Where `size` is the size of the ByteArray and `contents` is an Atom
representing the bytes in LSB ordering.

The `size` is required in general because the encoding of ByteArrays to
Atoms is ambiguous. For example the ByteArrays [0x01; 0x00] and [0x01]
are represente by `1`.

Some Anoma ByteArrays like keys and signatures are represented using on
the `contents` atom because the size is constant.

Users of Anoma APIs have to strip / add size information from ByteArrays
depending on where the data is used. The new builtins provide this facility.

These builtins are temporary because it's been agreed with Anoma
engineering team to change the Anoma APIs to make the ByteArray
representation uniform, i.e always represent ByteArrays using `[size
content]`. When this is implemented in Anoma Node we can remove these builtins.

```
builtin anoma-bytearray-to-anoma-contents
axiom toAnomaContents : ByteArray -> Nat;

builtin anoma-bytearray-from-anoma-contents
axiom fromAnomaContents :
  -- | The size of the ByteArray
  Nat
  -- | The contents of the ByteArray
  -> Nat
  -- | The resulting ByteArray
  -> ByteArray;
```
@paulcadman paulcadman force-pushed the anoma-bytearray-content-builtins branch from 7dc3199 to 96b7236 Compare August 16, 2024 18:25
@lukaszcz lukaszcz merged commit 8d03ac2 into main Aug 19, 2024
4 checks passed
@lukaszcz lukaszcz deleted the anoma-bytearray-content-builtins branch August 19, 2024 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants