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

Claim task part 1 - Solidity with minimal tests #20

Merged
merged 42 commits into from
May 29, 2024
Merged

Conversation

zguesmi
Copy link
Member

@zguesmi zguesmi commented May 24, 2024

VoucherHub contract needs to check that the "refund" request is legit:

  1. Option1: check that msg.sender is a voucher created by the hub and put all deal/task verification in Voucher contract.
    a. Compute voucher address and check it contains code => Not valid as users can mint vouchers themselves.
    b. Store a mapping of vouchers created by VoucherHub.

  2. Option2: check that the deal was sponsored by a valid voucher.
    a. Store a mapping of all sponsored deals of each voucher ins VoucherHub. => This requires duplicating voucher logic in the hub (check deal exists, check task status, ...).

=> Approach 1.a is the chosen option.

Tests & coverage:

image

@zguesmi zguesmi changed the title Claim task - part1 Claim task part 1 - Solidity with minimal tests May 24, 2024
@zguesmi zguesmi self-assigned this May 27, 2024
@zguesmi zguesmi marked this pull request as ready for review May 27, 2024 07:06
contracts/beacon/Voucher.sol Outdated Show resolved Hide resolved
contracts/beacon/Voucher.sol Outdated Show resolved Hide resolved
mapping(bytes32 dealId => VoucherMatchedDeal) _voucherMatchedDeals;
// Save refunded tasks to disable replay attacks.
mapping(bytes32 taskId => bool) _claimedTasks;
}
Copy link
Member

Choose a reason for hiding this comment

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

I propose to move mapping(bytes32 taskId => bool) _refundedTasks; to VoucherHub (for example in order to protect against double refund)

Copy link
Member Author

Choose a reason for hiding this comment

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

That way we need to move deal/task checking logic to the VoucherHub.

Copy link
Member

Choose a reason for hiding this comment

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

Yes exactly!

Copy link
Member Author

Choose a reason for hiding this comment

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

I tend to not prefer this option, because:

  • if we do that we need to put all the claim logic in the Hub (otherwise would not work) so there is not much left in the Voucher. Also since the sponsored amount is saved in the Voucher, we will
    • either be bouncing back and forth between the voucher and the hub (voucher.claim, hub.claimOnPoco, voucher.computeSponsoredAmount, hub.refund
    • or duplicate things (reading PoCo state)
  • I am not sure we don't risk cheating the Hub if we don't store voucher addresses.
  • The top up feature would probably benefit from the voucher list to make sure the voucher exists (not a very strong argument but it goes in the same direction).
  • Design wise, I find it cleaner to not include PoCo logic in the Hub.

test/VoucherHub.test.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@gfournieriExec gfournieriExec left a comment

Choose a reason for hiding this comment

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

Well done

contracts/VoucherHub.sol Outdated Show resolved Hide resolved
contracts/beacon/Voucher.sol Show resolved Hide resolved
Copy link
Member

@jeremyjams jeremyjams left a comment

Choose a reason for hiding this comment

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

Good thanks!

test/VoucherHub.test.ts Outdated Show resolved Hide resolved
@zguesmi zguesmi merged commit d137dfc into develop May 29, 2024
2 checks passed
@zguesmi zguesmi deleted the feature/task-claim branch May 29, 2024 17:10
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