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

Enforce a certain number of tokens on redemption #102

Merged
merged 4 commits into from
Sep 14, 2021

Conversation

exarkun
Copy link
Collaborator

@exarkun exarkun commented Sep 1, 2021

Fixes #99

Also reduce duplication in the test implementation a bit
And add some more error case tests
And remove the old, no-longer used redemption parameter globals
Some Integers becomes Ints for intra-module consistency
@exarkun exarkun marked this pull request as ready for review September 1, 2021 17:04
@exarkun exarkun requested review from hacklschorsch and a team and removed request for hacklschorsch September 1, 2021 17:05
Copy link
Member

@hacklschorsch hacklschorsch left a comment

Choose a reason for hiding this comment

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

Thanks for asking for a Review @exarkun. All I can say so far is I [✓] Viewed all files, and haven't found any errors obvious to me. That doesn't mean a whole lot currently I am afraid though, so beware :)

@exarkun
Copy link
Collaborator Author

exarkun commented Sep 14, 2021

Thanks for asking for a Review @exarkun. All I can say so far is I [✓] Viewed all files, and haven't found any errors obvious to me. That doesn't mean a whole lot currently I am afraid though, so beware :)

Thanks @hacklschorsch !

@exarkun exarkun merged commit 99e2189 into main Sep 14, 2021
@exarkun exarkun deleted the 99.enforce-token-count branch September 14, 2021 12:47
Copy link
Contributor

@tomprince tomprince left a comment

Choose a reason for hiding this comment

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

This looks good.

| otherwise = Just $ groupSize + groupSizeAdjustment
where
(groupSize, remainder) = totalTokens `divMod` numGroups
groupSizeAdjustment = if groupNumber < remainder then 1 else 0
Copy link
Contributor

Choose a reason for hiding this comment

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

This could probably use a comment, it took me a little time to understand what was going on. Maybe something like: "if the number of groups doesn't evenly divide the total tokens, the extra tokens are allocated evenly to the lower numbered groups"?

On the other hand, we could consider requiring that they divide exactly, and so have tokenCountForGroup part of RedemptionConfig

Copy link
Contributor

Choose a reason for hiding this comment

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

(For the second point, it looks like the current configuration does meet this requirement)

src/PaymentServer/Redemption.hs Show resolved Hide resolved
src/PaymentServer/Redemption.hs Show resolved Hide resolved
throwError $ jsonErr err500 $ OtherFailure "invalid redemption counter"
Just allowedTokenCount ->
if allowedTokenCount /= length tokens
then throwError $ jsonErr err400 $ OtherFailure "wrong number of tokens"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this have a structured error message, with the expected number of tokens?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe. I guess that would be easier to answer if we had a UX for handling any of these failure conditions. Right now what happens is ZKAPAuthorizer notes the error and usually tries exactly the same thing again a little later and no software exists to surface these error conditions to the user.

Comment on lines 106 to +110
= Unpaid -- ^ A voucher has not been paid for.
| DoubleSpend -- ^ A voucher has already been redeemed.
| OtherFailure Text -- ^ Some other unrecognized failure mode.
-- | Given counter was not in the expected range
| CounterOutOfBounds Integer Integer Integer
| CounterOutOfBounds Int Int Int
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really related to this PR, but I noticed it while trying to understand it:

I don't think any of these values need to be a part of Result, as we never return them as values of type Result (but rather encode them as part of ServerError). I'm not sure how it should be structured, though this has some discussion of various possibilities, including some packages that help with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Verify that the number of tokens provided in a redemption request matches expectations.
3 participants