-
Notifications
You must be signed in to change notification settings - Fork 20
Add monetary and treasury expansion to PParams (old)
#707
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
Add monetary and treasury expansion to PParams (old)
#707
Conversation
|
One problem introduced by the definition However, this is a symptom of an underlying problem: The We could try to avoid (While working with agda2hs, I found that such invariants typically require irrelevance @WhatisRT — thoughts? |
They are not needed, these macros are convenient to derive the Haskell datatypes but it could be done "by hand".
This problem already occurs in some places in the codebase. For example see
In a nutshell, the current approach is to define a nondependent version of the type, which can be compiled to Haskell, and define conversion functions from and to the dependent version.
|
|
Thanks @carlostome !
Sounds good, I can try to do that — but I think that I will get a problem with the Actually, I think that there are two issues:
The first issue is a general issue with Unfortunately, I think that the underlying problem remains the same: The statement "the dependent type EDIT: In this particular case, there is a workaround: I can define The second issues adds boilerplate, but seems otherwise benign to me. |
|
In these cases, we've usually just embraced that the FFI part is unsafe anyway, see e.g. here. This would work just fine in that case as well. That way, the code is neatly split into a safe part that has the required invariants and an unsafe part that will just crash if you actually do anything bad. If we want the caller to be able to handle that error we'd have to restructure We even have some occurances of |
Thanks! I will try it this way, then. I agree that restructuring |
carlostome
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, here are some comments:
-
I think the name
UnitIntervalis a bit misleading since it is using rationals and not reals. The best alternative I can come up atm is to use the symbol ℚ withing the name:UnitIntervalℚorℚUnitInterval. -
Regarding the module structure, I suggest to add another level in the hierarchy,
Ledger.Types.Numeric.UnitInterval, since in the future we might want to use a similar approach for positive naturals etc.
src/Ledger/Types/Numeric.agda
Outdated
| prop-inUnitInterval-* | ||
| : ∀ (x y : ℚ) | ||
| → inUnitInterval x | ||
| → inUnitInterval y | ||
| → inUnitInterval (x ℚ.* y) | ||
| -- | ||
| prop-inUnitInterval-* x y ux (0≤y , y≤1) = | ||
| ( prop-inUnitInterval-*-0≤ x y ux 0≤y , x*y≤1) | ||
| where | ||
| x*y≤1 = ℚ.≤-trans (prop-inUnitInterval-*-≤y x y ux 0≤y) y≤1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised this property exists without defining multiplication of UnitInterval numbers.
If its not going to be used I suggest not to include it (and the lemmas it depends on)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will probably need this lemma when proving that the rewards update is nonnegative and bounded by the available rewards, that's why I have added it in advance.
src/Ledger/Types/Numeric.agda
Outdated
| -- Multiplying with a number from the unit interval stays positive. | ||
| prop-inUnitInterval-*-0≤ | ||
| : ∀ (x y : ℚ) | ||
| → inUnitInterval x | ||
| → 0ℚ ≤ y | ||
| → 0ℚ ≤ x ℚ.* y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this prop is just plumbing and thus should be inlined or placed in a where clause within prop-inUnitInterval-*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will need this property when proving that the reward pot is nonnegative. I can try to inline it at the proof site, but the proof of this property is slightly too complicated for inlining for my taste.
src/Ledger/Types/Numeric.agda
Outdated
| with isInUnitInterval x | ||
| ... | yes p = x , [ p ] | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get an Agda warning in this line:
Incomplete pattern matching for Ledger.Types.Numeric.with-.
Missing cases:
mkUnitInterval x evidence | .false because ofⁿ ¬a
when checking the definition of Ledger.Types.Numeric.with-
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember seeing this warning before — it's probably due to the change of definition of isInUnitInterval? 🤔 But I can discharge the proof obligation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I should have double checked I didn't introduce the warning
src/ScriptVerification/Lib.agda
Outdated
| ; tau = mkUnitInterval (+ 2 / 10) refl | ||
| ; rho = mkUnitInterval (+ 3 / 1000) refl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if we can make mkUnitInterval deduce (or use a tactic) for the refl part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to think of refl as a tactic that proves equality ≡ by computation. From that viewpoint, refl is the tactic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can give mkUnitInterval a tactic argument:
open import Tactic.Defaults
open import Tactic.Constrs
mkUnitInterval : ∀ (x : ℚ) → {@(tactic tryConstrs 10) : does (isInUnitInterval x) ≡ true} → UnitInterval
Then you can write mkUnitInterval (+ 3 / 1000) and it'll find refl automatically. And in case refl doesn't work, you can still supply the proof manually: mkUnitInterval x {myProof}.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want me to add this implicit tactic argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tryConst tactic does not quite work — the argument to the tactic annotation must be of type Term → TC ⊤. I'll stick to refl for now.
|
Thanks for the review, @carlostome ! 😊
Ok, done.
I can do that if you really want me to, but I'm not sure if that's a good idea:
|
|
@HeinrichApfelmus this looks good overall. Nice work! I'm just going to push some style mods to your branch. I hope you don't mind. (Just some things to make the code more consistent with the existing code.) If you don't agree with any of the changes, feel free to comment and/or revert them. |
src/Class/DecEq/Instances/Extra.agda
Outdated
|
|
||
| -- Equality for a Refinement type is decide if the equality | ||
| -- for the type to be refined is decidable. | ||
| DeqEq-Refinement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be fantastic to upstream this to https://github.com/agda/agda-stdlib-classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but not in the present pull request in order to keep the scope limited.
I have created an issue agda/agda-stdlib-classes#17
src/ScriptVerification/Lib.agda
Outdated
| ; tau = mkUnitInterval (+ 2 / 10) refl | ||
| ; rho = mkUnitInterval (+ 3 / 1000) refl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can give mkUnitInterval a tactic argument:
open import Tactic.Defaults
open import Tactic.Constrs
mkUnitInterval : ∀ (x : ℚ) → {@(tactic tryConstrs 10) : does (isInUnitInterval x) ≡ true} → UnitInterval
Then you can write mkUnitInterval (+ 3 / 1000) and it'll find refl automatically. And in case refl doesn't work, you can still supply the proof manually: mkUnitInterval x {myProof}.
src/Ledger/PParams.lagda
Outdated
| tau : UnitInterval -- treasury expansion | ||
| rho : UnitInterval -- monetary expansion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be best to change those to the more approachable names. People are already complaining about short meaningless names.
| tau : UnitInterval -- treasury expansion | |
| rho : UnitInterval -- monetary expansion | |
| treasuryCut : UnitInterval | |
| monetaryExpansion : UnitInterval |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I can do that — the only trouble is that this would be incompatible with the existing nomenclature in the Shelley genesis file, though, so people will have to be instructed to use the new names.
|
Thanks @williamdemeo and @WhatisRT !
Thanks! I am only going to change
As for the |
PParamsPParams (old)
|
For technical reasons (CI step "MAlonzo"), I'm closing this pull request and I'm opening a new one with the code after review at #732. |
Description
This pull request adds the monetary expansion
rhoand treasury expansiontauprotocol parameters to thePParamstype.In order to be able to prove that the treasury and reserves are not negative, it is necessary to constrain these parameters need to the unit interval
[0, 1]. These conditions need to be stored somewhere — I have chosen to make them part of thePParamstype by refining the parameters to a new typeUnitInterval. (This is similar to how the previous specification of the Shelley ledger encodes these parameters.)Context: #706
Checklist
CHANGELOG.md