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

Skip to content

Add OwnedCounter app#25

Merged
janmasrovira merged 9 commits intomainfrom
owned-counter
Jul 8, 2025
Merged

Add OwnedCounter app#25
janmasrovira merged 9 commits intomainfrom
owned-counter

Conversation

@janmasrovira
Copy link
Contributor

@janmasrovira janmasrovira commented Jul 6, 2025

This pr adds an example app with ownership (OwnedCounter) and the machinery needed to implement it.

The owned counter is the same as the universal counter with two differences:

  1. Only the owner of the counter can increment it.
  2. The counter ownership can be transferred with the Transfer method.

@janmasrovira janmasrovira self-assigned this Jul 6, 2025
@janmasrovira janmasrovira marked this pull request as ready for review July 7, 2025 07:49
@janmasrovira janmasrovira requested a review from lukaszcz July 7, 2025 10:24
/-- Extra method logic. The method invariant is combined with auto-generated
method body constraints to create the method logic. -/
invariant : (self : Object lab) → methodId.Args.type Bool
invariant : (self : Object lab) → methodId.Args.type -> Bool
Copy link
Contributor

Choose a reason for hiding this comment

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

We should revert this change, and agree on one style of arrows. I've been using unicode arrows for functions (->) and monad assignment (<-).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

invariant : (self : Object lab) → methodId.Args.type -> Bool
/-- Objects created in the method call. -/
created : (self : Object lab) → methodId.Args.type List SomeObject
created : (self : Object lab) → methodId.Args.type -> List SomeObject
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

/-- Not a secret. Use this instance when ownership is not relevant -/
instance NullifierKeyCommitment.instInhabited : Inhabited NullifierKeyCommitment where
default := NullifierKeyCommitment.privateMk
deriving instance Inhabited for NullifierKeyCommitment
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we just add Inhabited to the deriving clause in the NullifierKeyCommitment definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added an explicit instance

methods := fun
| Methods.Incr => counterIncr
| Methods.Transfer => counterTransfer
invariant _ _ := True
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's more readable to not write the invariants explicitly when they're the default ones (always true). Then there is essentially no invariant, and we're only adding visual clutter, imo.

Copy link
Contributor

@lukaszcz lukaszcz Jul 8, 2025

Choose a reason for hiding this comment

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

Besides, we should be using true and false instead of True and False. The first ones are booleans, the second ones are in Prop. There seems to be some weird coercion going on, but this is potentially confusing - let's just use the constants in Bool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed the invariants.

I'll use true and false for Bool from now on.

PublicFields := ⟨Unit⟩
MethodId := Methods
MethodArgs := fun
| Methods.Incr => {type := Nat}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's decide on a uniform way of promoting Type to SomeType. The convention I've been following is to write e.g. \<Nat\> (as above for PrivateFields and PublicFields).

Copy link
Contributor Author

@janmasrovira janmasrovira Jul 8, 2025

Choose a reason for hiding this comment

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

I've changed it to <Nat>

@janmasrovira janmasrovira requested a review from lukaszcz July 8, 2025 13:54
@janmasrovira janmasrovira merged commit 908661f into main Jul 8, 2025
2 checks passed
@janmasrovira janmasrovira deleted the owned-counter branch July 8, 2025 16:04
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.

2 participants

Comments