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 frontend support for Anoma stdlib sha256 #3109

Merged
merged 4 commits into from
Oct 17, 2024
Merged

Conversation

paulcadman
Copy link
Collaborator

@paulcadman paulcadman commented Oct 17, 2024

This PR adds frontend support for Anoma stdlib sha256 function (aka shax in Nock).

The new builtin can be declared as follows:

builtin anoma-sha256
axiom anomaSha256 : Nat -> ByteArray;

The intention is that it wraps a call to anomaEncode as follows:

sha256 {A} (a : A) : ByteArray := anomaSha256 (anomaEncode a);

Fix for atom to ByteString

This PR also includes a commit 6205dc9 to fix an issue with functions like integerToByteArray when called with negative integers (the solution is to change the argument types to Natural, as this is all we need for Anoma).

Functions like integerToByteString did not terminate when called with
negative integers. For Nockma we only need to encode Natural numbers so
this commit restricts the integer encoding functions to work only with
natural numbers.
The new builtin can be declared as follows:

```
builtin anoma-sha256
axiom anomaSha256 : Nat -> ByteArray;
```

The intention is that it wraps a call to anomaEncode as follows:

sha256 {A} (a : A) : ByteArray := anomaSha256 (anomaEncode a);
@paulcadman paulcadman added this to the 0.6.7 milestone Oct 17, 2024
@paulcadman paulcadman self-assigned this Oct 17, 2024
@paulcadman paulcadman requested a review from lukaszcz October 17, 2024 16:14
@lukaszcz lukaszcz merged commit 0a9ec8f into main Oct 17, 2024
4 checks passed
@lukaszcz lukaszcz deleted the nockma-support-sha256 branch October 17, 2024 17:11
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.

Add SHA-256 hash builtin
2 participants