Move adds on total earlier to enable the use of unchecked (#3527)
Co-authored-by: Francisco <frangio.1@gmail.com>
This commit is contained in:
@ -149,8 +149,12 @@ contract PaymentSplitter is Context {
|
||||
|
||||
require(payment != 0, "PaymentSplitter: account is not due payment");
|
||||
|
||||
_released[account] += payment;
|
||||
// _totalReleased is the sum of all values in _released.
|
||||
// If "_totalReleased += payment" does not overflow, then "_released[account] += payment" cannot overflow.
|
||||
_totalReleased += payment;
|
||||
unchecked {
|
||||
_released[account] += payment;
|
||||
}
|
||||
|
||||
Address.sendValue(account, payment);
|
||||
emit PaymentReleased(account, payment);
|
||||
@ -168,8 +172,13 @@ contract PaymentSplitter is Context {
|
||||
|
||||
require(payment != 0, "PaymentSplitter: account is not due payment");
|
||||
|
||||
_erc20Released[token][account] += payment;
|
||||
// _erc20TotalReleased[token] is the sum of all values in _erc20Released[token].
|
||||
// If "_erc20TotalReleased[token] += payment" does not overflow, then "_erc20Released[token][account] += payment"
|
||||
// cannot overflow.
|
||||
_erc20TotalReleased[token] += payment;
|
||||
unchecked {
|
||||
_erc20Released[token][account] += payment;
|
||||
}
|
||||
|
||||
SafeERC20.safeTransfer(token, account, payment);
|
||||
emit ERC20PaymentReleased(token, account, payment);
|
||||
|
||||
Reference in New Issue
Block a user