Skip to content

Evm encoding #93

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

Merged
merged 27 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ jobs:
steps:
- name: checkout code
uses: actions/checkout@v3

- name: Download the Juvix binary
uses: jaxxstorm/action-install-gh-release@v1.10.0
with:
repo: anoma/juvix-nightly-builds
cache: enable

- name: Clean
run: juvix clean --global && juvix dependencies update
run: juvix clean --global && juvix dependencies update

- name: Type Check
run: juvix typecheck

- name: Format Check
run: juvix format

- name: Run tests
run: cd Test && juvix eval Main.juvix
19 changes: 19 additions & 0 deletions Anoma/Builtin/ByteArray.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Stdlib.Prelude open;
import BaseLayer.AnomaAtom open;
import Stdlib.Trait.Ord.Eq open using {fromOrdToEq};
import Anoma.Data.Json open;
import Mtl open;

module ByteArray;
builtin bytearray
Expand All @@ -12,6 +13,18 @@ module ByteArray;
builtin bytearray-from-list-byte
axiom mk : List Byte -> ByteArray;

fromList : List Byte -> ByteArray := mk;

empty : ByteArray := fromList [];

toList (b : ByteArray) : List Byte :=
let
go (acc : List Byte) (payload : Nat) : (len : Nat) -> List Byte
| zero := reverse acc
-- Note `fromNat` takes the modulo
| (suc ibyte) := go (fromNat payload :: acc) (div payload 256) ibyte;
in go [] (rawToAnomaContents b) (size b);

zero (length : Nat) : ByteArray := mk (replicate length 0x0);

--- The number of bytes in the ;ByteArray;
Expand All @@ -33,6 +46,12 @@ module ByteArray;
contents := AnomaAtom.toNat contents;
};

instance
ByteArray-Show : Show ByteArray :=
Show.mk@{
show : ByteArray -> String := toList >> Show.show;
};

instance
ByteArray-ToJson : ToJson ByteArray :=
ToJson.mk@{
Expand Down
Loading