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

Internal review - Voucher #30

Draft
wants to merge 637 commits into
base: feature/internal-review-base
Choose a base branch
from

Conversation

jeremyjams
Copy link
Member

Reminder: PR is for comments only, it won't be merged.

jeremyjams and others added 28 commits June 11, 2024 08:46
Co-authored-by: Zied Guesmi <[email protected]>
@jeremyjams jeremyjams requested a review from Amxx June 11, 2024 17:20
Copy link
Member

@Amxx Amxx left a comment

Choose a reason for hiding this comment

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

Not much to say. Looks mostly good.

Comment on lines +174 to +177
_mint(voucherAddress, value); // VCHR
$._isVoucher[voucherAddress] = true;
emit VoucherCreated(voucherAddress, owner, voucherType, expiration, value);
_transferFundsToVoucherOnPoco(voucherAddress, value); // SRLC
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_mint(voucherAddress, value); // VCHR
$._isVoucher[voucherAddress] = true;
emit VoucherCreated(voucherAddress, owner, voucherType, expiration, value);
_transferFundsToVoucherOnPoco(voucherAddress, value); // SRLC
if (value > 0) {
_mint(voucherAddress, value); // VCHR
_transferFundsToVoucherOnPoco(voucherAddress, value); // SRLC
}
$._isVoucher[voucherAddress] = true;
emit VoucherCreated(voucherAddress, owner, voucherType, expiration, value);

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes,

  1. Either add if (value > 0)
  2. Or maybe require(value > 0) (like top up)

sponsoredAmount -= sponsoredAmount % volume;
if (sponsoredAmount > 0) {
_burn(msg.sender, sponsoredAmount);
emit VoucherDebited(msg.sender, sponsoredAmount);
Copy link
Member

Choose a reason for hiding this comment

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

These is already a burn event (transfer to 0). Is that not enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was just here to save a bit of gas to avoid updating balance to 0 and firing event.
Maybe it is a quite not good idea to do so 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok your comment was about the relevance of the event itself!

Copy link
Member

Choose a reason for hiding this comment

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

The idea is to add a feature-specific event as the burn event occurs on different occasions (drain feature for example).

* on PoCo from voucher to voucherHub and burn all credits.
* @param voucher address of the expired voucher to drain
*/
function drainVoucher(address voucher) external {
Copy link
Member

Choose a reason for hiding this comment

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

there is no access control here. Is that normal? Doesn't feel right

Copy link
Member

Choose a reason for hiding this comment

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

After check, its ok because Voucher(voucher).drain(amount) checks expiry, and the msg.sender is not used.


function _getVoucherHubStorage() private pure returns (VoucherHubStorage storage $) {
//slither-disable-start assembly
assembly {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assembly {
assembly ("memory-safe") {

/// @custom:storage-location erc7201:iexec.voucher.storage.Voucher
struct VoucherStorage {
address _owner;
address _voucherHub;
Copy link
Member

Choose a reason for hiding this comment

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

This izs the same for all instances. Maybe it should be an immutable variable

Copy link
Member Author

Choose a reason for hiding this comment

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

If it becomes immutable, how to update storage slot if someday VoucherHub address changes? Should we consider we are safe since VoucherHub is UUPSUpgradeable

* @param dealId id of the task's deal
* @param taskIndex task's index in the deal
*/
function claimBoost(bytes32 dealId, uint256 taskIndex) external {
Copy link
Member

Choose a reason for hiding this comment

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

why does this use dealId and taskIndex instead of taskId (like claim) ?

Copy link
Member

Choose a reason for hiding this comment

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

Because in Boost mode, there is not initialize() so there is not task definition before pushing the result of compute.
Check Boost delegate on PoCo https://github.com/iExecBlockchainComputing/PoCo/blob/develop/contracts/modules/delegates/IexecPocoBoostDelegate.sol#L371

* Funds are sent to the VoucherHub contract.
* @param amount amount to be drained
*/
function drain(uint256 amount) external onlyVoucherHub onlyExpired {
Copy link
Member

Choose a reason for hiding this comment

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

maybe this function should be replaced by:

  • doing ERC20(IVoucherHub(voucherHub).getIexecPoco()).approve(voucherHub, type(uint256).max) at initialization
  • doing a transferFrom in VoucherHub (instead of calling this)

Copy link
Member

Choose a reason for hiding this comment

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

The issue with this (if I understand your suggestion correctly) is that anyone could do a transferFrom(voucher => voucherHub) before the expiration date.

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 agree with you Hadrien, it looks cleaner (At the time I did not say anything because it could raise gas costs but did not check how much)

Comment on lines +386 to +388
uint256 dealPrice = datasetOrder.dataset != address(0)
? (appPrice + datasetPrice + workerpoolPrice) * volume
: (appPrice + workerpoolPrice) * volume;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
uint256 dealPrice = datasetOrder.dataset != address(0)
? (appPrice + datasetPrice + workerpoolPrice) * volume
: (appPrice + workerpoolPrice) * volume;
uint256 dealPrice = (
appPrice +
workerpoolPrice +
(datasetOrder.dataset != address(0) ? datasetPrice : 0)
) * volume;

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.

4 participants