1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-11 08:25:46 +03:00

Enable Anoma compilation resource machine builtin tests (#3208)

This PR:

* Updates the anomalib nock stdlib to the latest head of
`artem/juvix-node-integration-v0.28` containing the latest testnet
fixes.
* Re-enables the Anoma resource machine builtins tests
This commit is contained in:
Paul Cadman 2024-12-02 14:09:55 +01:00 committed by GitHub
parent fcd59c9664
commit 9210e39dc7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 196 additions and 102 deletions

View File

@ -26,7 +26,7 @@ env:
SKIP: ormolu,format-juvix-files,typecheck-juvix-examples SKIP: ormolu,format-juvix-files,typecheck-juvix-examples
CAIRO_VM_VERSION: 06e8ddbfa14eef85f56c4d7b7631c17c9b0a248e CAIRO_VM_VERSION: 06e8ddbfa14eef85f56c4d7b7631c17c9b0a248e
RISC0_VM_VERSION: v1.0.1 RISC0_VM_VERSION: v1.0.1
ANOMA_VERSION: f52cd44235f35a907c22c428ce1fdf3237c97927 ANOMA_VERSION: 44dbbd0376ef15731c8f69988905af23a65fceff
JUST_ARGS: runtimeCcArg=$CC runtimeLibtoolArg=$LIBTOOL JUST_ARGS: runtimeCcArg=$CC runtimeLibtoolArg=$LIBTOOL
STACK_BUILD_ARGS: --pedantic -j4 --ghc-options=-j STACK_BUILD_ARGS: --pedantic -j4 --ghc-options=-j

File diff suppressed because one or more lines are too long

View File

@ -250,7 +250,7 @@ classify AnomaTest {..} = case _anomaTestNum of
82 -> ClassWorking 82 -> ClassWorking
83 -> ClassWorking 83 -> ClassWorking
84 -> ClassWorking 84 -> ClassWorking
85 -> ClassNodeError 85 -> ClassWorking
86 -> ClassExpectedFail 86 -> ClassExpectedFail
_ -> error "non-exhaustive test classification" _ -> error "non-exhaustive test classification"
@ -1039,14 +1039,13 @@ allTests =
85 85
AnomaTestModeNodeOnly AnomaTestModeNodeOnly
"Anoma Resource Machine builtins" "Anoma Resource Machine builtins"
$(mkRelDir ".") $(mkRelDir "test085")
$(mkRelFile "test085.juvix") $(mkRelFile "delta.juvix")
[] []
$ checkOutput $ checkOutput
[ [nock| [[[11 22] 110] 0] |], [ [nock| 0 |],
[nock| [10 11] |], [nock| 0 |],
[nock| 478793196187462788804451 |], [nock| 0 |],
[nock| 418565088612 |],
[nock| 0 |] [nock| 0 |]
], ],
mkAnomaTest mkAnomaTest

View File

@ -4,5 +4,5 @@ import PackageDescription.V2 open;
package : Package := package : Package :=
defaultPackage@?{ defaultPackage@?{
name := "positive" name := "positive";
}; };

View File

@ -1,92 +0,0 @@
module test085;
import Stdlib.Prelude open;
import Stdlib.Debug.Trace open;
-- This definition does not match the spec. For testing purposes only
builtin anoma-resource
type Resource :=
mkResource@{
label : Nat;
logic : Nat;
ephemeral : Bool;
quantity : Nat;
data : Pair Nat Nat;
nullifier-key : Nat;
nonce : Nat;
rseed : Nat
};
mkResource' (label logic : Nat) {quantity : Nat := 0} : Resource :=
mkResource@{
label;
logic;
ephemeral := false;
quantity;
data := 0, 0;
nullifier-key := 0;
nonce := 0;
rseed := 0
};
-- This definition does not match the spec. For testing purposes only
builtin anoma-action
type Action := mkAction Nat;
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 resourceDelta : Resource -> Delta;
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;
main : Delta :=
trace
(resourceDelta
mkResource'@{
label := 11;
logic := 22;
quantity := 55
})
>-> trace (commitment (mkResource' 0 0))
>-> trace (nullifier (mkResource' 0 0))
>-> trace (actionDelta (mkAction 0))
>-> trace (actionsDelta [mkAction 0])
>-> trace (addDelta zeroDelta zeroDelta)
>-> trace (subDelta zeroDelta zeroDelta)
>-> trace (kind (mkResource' 10 11))
>-> trace (proveAction (mkAction 0))
>-> trace (proveDelta zeroDelta)
>-> zeroDelta;

View File

@ -0,0 +1,9 @@
module Package;
import PackageDescription.V2 open;
package : Package :=
defaultPackage@?{
name := "test085";
dependencies := [defaultStdlib; path "client/"];
};

View File

@ -0,0 +1,8 @@
module Package;
import PackageDescription.V2 open;
package : Package :=
defaultPackage@?{
name := "addtransaction";
};

View File

@ -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;
};

View File

@ -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];