Move adds on total earlier to enable the use of unchecked (#3527)

Co-authored-by: Francisco <frangio.1@gmail.com>
pull/3534/head^2
Linhai Song 3 years ago committed by GitHub
parent e7397844f8
commit 8b778fa20d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      contracts/finance/PaymentSplitter.sol

@ -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);

Loading…
Cancel
Save