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

CENT-631 - No way to decrement an allowance without reconfiguring minter #249

Merged
merged 12 commits into from
Jan 17, 2019

Conversation

mgrissa
Copy link
Contributor

@mgrissa mgrissa commented Jan 10, 2019

No description provided.

@0xj0hnny
Copy link
Contributor

tests bt057, bt060, bt062, on minting3/MintP0_BasicTests.js failed. Please fixed those test

* transaction to a minter and not worry about it being used to undo a removeMinter()
* transaction.
*/
function decrementMinterAllowance(uint256 allowanceDecrement) onlyController public returns (bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please use solidity convention for input _allowanceDecrement

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

* transaction to a minter and not worry about it being used to undo a removeMinter()
* transaction.
*/
function decrementMinterAllowance(uint256 allowanceDecrement) onlyController public returns (bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add require check for _allowanceDecrement must be greater than 0

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

Copy link
Contributor

@mirathewhite mirathewhite left a comment

Choose a reason for hiding this comment

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

Replace all expectRevert with expectError. USDC unit tests do not have error messages in require/revert statements, so we use expectRevert. We added error messages to MINT contracts, so these unit tests can use expectError. The only exception is when the OpenZeppelin SafeMath library throws an error - in this case we expectJump. I pointed out a few place, but you need to go through and double-check.

Regarding newBigNumber vs new BigNumber, unit tests will fail until you make the change.


uint256 currentAllowance = minterManager.minterAllowance(minter);
uint256 newAllowance = currentAllowance.sub(allowanceDecrement);

Copy link
Contributor

Choose a reason for hiding this comment

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

If the currentAllowance is less than the allowanceDecrement, the contract should set the allowance to 0. Issuers are going to have pre-signed incrementMinterAllowance and decrementMinterAllowance transactions. They need a way to drive the allowance down to 0 regardless of the current allowance value. The sub() function throws if allowanceDecrement>currentAllowance.

We can use the OpenZeppelin Math library:
uint256 newAllowance = max(currentAllowance, allowanceDecrement).sub(allowanceDecrement)

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

Copy link
Contributor

Choose a reason for hiding this comment

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

If we're going with the "set to 0 rather than throw" approach, we should make sure _allowanceDecrement in the event accurately reflects how much was actually decremented - right now we are just reporting what we tried to decrement, but the actual amount decremented can be less if the new allowance is 0.

Also, we should rename the event MinterAllowanceDecremented and that parameter to amountDecremented. (All the other events in these new contracts are in past tense except IncrementAllowance, which I think should be also changed to past tense for consistency - normally it doesn't matter, but in this case it clarifies the behavior.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, you're right. The event is now firing the actual decremented amount

expectedTokenState.push(
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true },
{ 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) }
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Use newBigNumber(amount) instead of new BigNumber(amount) to create a bn. Unlike the BigNumber library, the bn constructor takes as input only hex/binary. The newBigNumber is a wrapper function that takes decimal input and returns a bn.

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!

expectedTokenState.push(
{ 'variable': 'isAccountMinter.minterAccount', 'expectedValue': true },
{ 'variable': 'minterAllowance.minterAccount', 'expectedValue': new BigNumber(amount) },
);
Copy link
Contributor

Choose a reason for hiding this comment

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

use newBigNumber(amount)

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!


it('only controller decrements allowance', async function () {
await expectRevert(mintController.decrementMinterAllowance(0, {from: Accounts.controller1Account}));
});
Copy link
Contributor

Choose a reason for hiding this comment

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

use expectError to check for the correct error message.

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


// decrement minter allowance
await expectRevert(mintController.decrementMinterAllowance(amount, {from: Accounts.controller1Account}));
});
Copy link
Contributor

Choose a reason for hiding this comment

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

use expectError instead of expectRevert

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

@eztierney
Copy link
Contributor

#268

function decrementMinterAllowance(
uint256 _allowanceDecrement
)
public
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor - lines 153–155 (public through returns (bool)) should be indented 4 spaces

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!

@mirathewhite mirathewhite merged commit 1a62713 into circlefin:multi-issuer Jan 17, 2019
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.

5 participants