Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lukaszcz
Copy link
Collaborator

@lukaszcz lukaszcz commented Jun 17, 2025

This prototype implements a basic initial version of a compilation pipeline for the model Lukasz and Jan sketched during HH Q2.2025.

This PR does not include:

  • proper computation of nonces, nullifier key commitments, delta proofs,
  • surface (front-end) syntax,
  • intents,
  • non-method functions.

All extensions will be added as separate PRs.

GOOSE first prototype sketch (HH Q2.2025 version).

The HH Q2.2025 sketch by Jan follows. As mentioned, not everything from it is implemented in this PR.

Simple Counter with juvix + objects

module ObjectCounter;

object Counter := mk@{
  count : Nat;
};

constructor create := 
  new Counter.mk@{
     count := 0
   };

method incrementBy (self: Counter) (n : Nat) := 
  out self@{count := self.count + n};
 
mutualIncrement (c1 : Counter) (c2 : Counter) : TransactionBuilder := 
  c1.incrementBy(value c2);
  c2.incrementBy(value c1);

Kudos

object Kudos := mk@{
  originator : ExternalIdentity;
  owner      : ExternalIdentity;
  quantity    : Nat;
  public authorizationData : AuthorizationData;
}
logic : Bool := _ -- Here we will express the shared logic logic among all the methods.
                  -- We have a general idea but some of the details still need to be worked out.


 constructor create (originator : ExternalIdentity) (quantity : Nat) :=
   new Kudos.mk@{
         originator;
         quantity;
         owner := originator;
         authData := AuthorizationAppData.mk originator;
     };
   };
   onlyIf : Bool := _ -- extra logic specific to creation.

  method transfer (self : Kudos) (receiver : ExternalIdentity) := 
       out self{owner := receiver;
                authData := mkAuthData receiver
            };
   onlyIf : Bool := _ -- extra logic specific to transfer.

  method swap (self : Kudos) (wantOriginator : ExternalIdentity) (wantQuantity : Nat) := 
        out Kudos.mk@{
            originator := wantOriginator;
            quantity : wantQuantity;
            owner := self.owner;
            authData := mkAuthData self.owner
          };
     onlyIf : Bool := _ -- extra logic specific to swap.

  method split (self : Kudos) (partition : List (Pair ExternalIdentity Nat)) :=
     for (receiver, quantity in partition) {
        out self@{owner := receiver;
                  quantity;
                  authData := mkAuthData receiver;
      }
     };

  intent SwapIntent (wantOriginator : ExternalIdentity) (wantQuantity : Nat)
   intentLogic 
      in (give : Kudos)  -- List of resources that we consume
      want (createdKudos : Set Kudo) (unused : Set OtherObject) : Bool := 
          let kudosToGet : Nat := 
               createdKudos
              |> select \{x => owner x == owner give && originator x == wantOriginator }
              |> map quantity
              |> sum
          in kudosToGet >= wantQuantity;

Summary of compilation of Juvix objects to the resource machine

  1. Objects are juvix types that are stored in the Resource Machine.
  2. Objects can have methods. A method is a special function with these properties:
  • Marked with the method keyword.
  • The first argument is self : Object.
  • It can call other methods.
  • It can output objects with the out keyword.
  • The result of running a method is a transaction that consumes self and
    creates all objects marked with out.
  • The constructor is a special method that is used to create a new object.
    The result is transaction that creates the object marked with new and
    consumes an auxiliary ephemeral resource.
  1. Intents are specified with these parameters:
  • Regular non-object arguments. Nat, Bool, etc.
  • List of objects that will be consumed by the intent.
  • A boolean function that takes sets of objects as arguments. This function
    decides whether the intent is satisfied.

@lukaszcz lukaszcz self-assigned this Jun 17, 2025
@lukaszcz lukaszcz marked this pull request as ready for review June 25, 2025 08:18
@lukaszcz lukaszcz requested a review from janmasrovira June 25, 2025 08:18
@lukaszcz lukaszcz requested a review from janmasrovira June 25, 2025 10:05
@lukaszcz lukaszcz requested a review from janmasrovira June 25, 2025 14:26
Copy link
Collaborator

@janmasrovira janmasrovira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@lukaszcz lukaszcz merged commit c293f16 into main Jun 25, 2025
2 checks passed
@lukaszcz lukaszcz deleted the goose-prototype-v1 branch June 25, 2025 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants