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

Enable Anoma compilation resource machine builtin tests #3208

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ env:
SKIP: ormolu,format-juvix-files,typecheck-juvix-examples
CAIRO_VM_VERSION: 06e8ddbfa14eef85f56c4d7b7631c17c9b0a248e
RISC0_VM_VERSION: v1.0.1
ANOMA_VERSION: f52cd44235f35a907c22c428ce1fdf3237c97927
ANOMA_VERSION: 44dbbd0376ef15731c8f69988905af23a65fceff
JUST_ARGS: runtimeCcArg=$CC runtimeLibtoolArg=$LIBTOOL
STACK_BUILD_ARGS: --pedantic -j4 --ghc-options=-j

Expand Down
2 changes: 1 addition & 1 deletion runtime/nockma/anomalib.nockma

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions test/Anoma/Compilation/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ classify AnomaTest {..} = case _anomaTestNum of
82 -> ClassWorking
83 -> ClassWorking
84 -> ClassWorking
85 -> ClassNodeError
85 -> ClassWorking
86 -> ClassExpectedFail
_ -> error "non-exhaustive test classification"

Expand Down Expand Up @@ -1039,14 +1039,13 @@ allTests =
85
AnomaTestModeNodeOnly
"Anoma Resource Machine builtins"
$(mkRelDir ".")
$(mkRelFile "test085.juvix")
$(mkRelDir "test085")
$(mkRelFile "delta.juvix")
[]
$ checkOutput
[ [nock| [[[11 22] 110] 0] |],
[nock| [10 11] |],
[nock| 478793196187462788804451 |],
[nock| 418565088612 |],
[ [nock| 0 |],
[nock| 0 |],
[nock| 0 |],
[nock| 0 |]
],
mkAnomaTest
Expand Down
2 changes: 1 addition & 1 deletion tests/Anoma/Compilation/positive/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import PackageDescription.V2 open;

package : Package :=
defaultPackage@?{
name := "positive"
name := "positive";
};
92 changes: 0 additions & 92 deletions tests/Anoma/Compilation/positive/test085.juvix

This file was deleted.

9 changes: 9 additions & 0 deletions tests/Anoma/Compilation/positive/test085/Package.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Package;

import PackageDescription.V2 open;

package : Package :=
defaultPackage@?{
name := "test085";
dependencies := [defaultStdlib; path "client/"];
};
8 changes: 8 additions & 0 deletions tests/Anoma/Compilation/positive/test085/client/Package.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Package;

import PackageDescription.V2 open;

package : Package :=
defaultPackage@?{
name := "addtransaction";
};
130 changes: 130 additions & 0 deletions tests/Anoma/Compilation/positive/test085/client/ResourceMachine.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
--- A rendering of https://github.com/anoma/anoma/blob/f52cd44235f35a907c22c428ce1fdf3237c97927/hoon/resource-machine.hoon
module ResourceMachine;

import Stdlib.Prelude open;

module Resource;

Resource-Logic : Type := Public-Inputs -> Private-Inputs -> Bool;

builtin anoma-resource
type Resource :=
mkResource@{
label : Nat;
logic : Resource-Logic;
ephemeral : Bool;
quantity : Nat;
data : Pair Nat Nat;
--- 256 bits
nullifier-key : Nat;
--- nonce for commitments 256 bits
nonce : Nat;
rseed : Nat;
};

positive
type Public-Inputs :=
mkPublic-Inputs@{
commitments : List Nat;
nullifiers : List Nat;
--- exactly one commitment or nullifier
self-tag : Nat;
other-public : Nat;
};

positive
type Private-Inputs :=
mkPrivate-Inputs@{
committed-resources : List Resource;
nullified-resources : List Resource;
other-private : Nat;
};

end;

open Resource using {
Resource;
mkResource;
Resource-Logic;
Public-Inputs;
mkPublic-Inputs;
Private-Inputs;
mkPrivate-Inputs;
} public;

builtin anoma-delta
axiom Delta : Type;

builtin anoma-kind
axiom Kind : Type;

builtin anoma-resource-commitment
axiom commitment : Resource -> Nat;

builtin anoma-resource-nullifier
axiom nullifier : Resource -> Nat;

builtin anoma-resource-kind
axiom kind : Resource -> Kind;

builtin anoma-resource-delta
axiom resource-delta : Resource -> Delta;

type Logic-Proof : Type :=
mkLogicProof@{
resource : Resource;
inputs : Pair Public-Inputs Private-Inputs;
};

Compliance-Proof : Type := Nat;

type Proof :=
| proofCompliance
| proofLogic Resource (Pair Public-Inputs Private-Inputs);

mkProofCompliance (_ : Compliance-Proof) : Proof := proofCompliance;

mkProofLogic
(resource : Resource) (inputs : Pair Public-Inputs Private-Inputs) : Proof :=
proofLogic resource inputs;

builtin anoma-action
type Action :=
mkAction@{
commitments : List Nat;
nullifiers : List Nat;
proofs : List Proof;
app-data : Nat;
};

builtin anoma-action-delta
axiom actionDelta : Action -> Delta;

builtin anoma-actions-delta
axiom actionsDelta : List Action -> Delta;

builtin anoma-prove-action
axiom proveAction : Action -> Nat;

builtin anoma-prove-delta
axiom proveDelta : Delta -> Nat;

builtin anoma-zero-delta
axiom zeroDelta : Delta;

builtin anoma-add-delta
axiom addDelta : Delta -> Delta -> Delta;

builtin anoma-sub-delta
axiom subDelta : Delta -> Delta -> Delta;

Commitment-Root : Type := Nat;

type Transaction :=
mkTransaction@{
--- root set for spent resources
roots : List Commitment-Root;
actions : List Action;
delta : Delta;
delta-proof : Nat;
};
40 changes: 40 additions & 0 deletions tests/Anoma/Compilation/positive/test085/delta.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module delta;

import Stdlib.Prelude open;
import Stdlib.Debug.Trace open;
import ResourceMachine open;

main : Delta :=
let
resource : Resource :=
mkResource@{
label := 11;
logic := \{_ _ := true};
ephemeral := true;
quantity := 55;
data := 0, 0;
nullifier-key := 0;
nonce := 0;
rseed := 0;
};
action : Action :=
mkAction@{
commitments := [];
nullifiers := [];
proofs := [];
app-data := 1;
};
in -- Most of these call return large nouns that are not appropritate for testing.
-- This test checks that these functions do not crash.
commitment
resource
>-> nullifier resource
>-> kind resource
>-> addDelta (resource-delta resource) (resource-delta resource)
>-> addDelta (resource-delta resource) (resource-delta resource)
>-> proveDelta zeroDelta
>-> trace (subDelta zeroDelta zeroDelta)
>-> trace (addDelta zeroDelta zeroDelta)
>-> proveAction action
>-> trace (actionDelta action)
>-> actionsDelta [action];
Loading