anoma / juvix

A language for intent-centric and declarative decentralised applications
https://docs.juvix.org
GNU General Public License v3.0
449 stars 54 forks source link

Add SHA-256 hash builtin #2901

Open paulcadman opened 2 months ago

paulcadman commented 2 months ago

Depends on:

This issue proposes adding a builtin SHA-256 function.

--- SHA-256 hash ;Bytes; into a digest ;Bytes; (32 bytes).
builtin
axiom sha256hash : Bytes -> Bytes

This is required because several fields in an Anoma resource (logic function, commitments etc.) will be hashes rather than the original plaintext.

Backend Representation

Core

We can use a Haskell library, e.g cryptohash-sha256 to implement the builtin.

Nockma

We can use the same implementation as Core in the Juvix Nockma evaluator.

We will need an SHA-256 hash implementation in the Anoma Hoon stdlib in order to run programs containing this builtin in the Anoma Nock VM.

Native, Cairo, Risc0

The implementation of sha256hash for the native, Cairo and Risc0 backends is deferred.