Skip to content

Commit

Permalink
audit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
barrasso committed Oct 27, 2021
1 parent 795f1c7 commit 20ba45e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
10 changes: 8 additions & 2 deletions contracts/BaseDebtCache.sol
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,19 @@ contract BaseDebtCache is Owned, MixinSystemSettings, IDebtCache {
return _excludedIssuedDebts(currencyKeys);
}

// Returns the total sUSD debt backed by non-SNX collateral, excluding debts recorded with _excludedIssuedDebt
// Returns the total sUSD debt backed by non-SNX collateral.
function totalNonSnxBackedDebt() external view returns (uint excludedDebt, bool isInvalid) {
bytes32[] memory currencyKeys = issuer().availableCurrencyKeys();
(uint[] memory rates, bool ratesAreInvalid) = exchangeRates().ratesAndInvalidForCurrencies(currencyKeys);

return _totalNonSnxBackedDebt(currencyKeys, rates, ratesAreInvalid);
}

function _totalNonSnxBackedDebt(bytes32[] memory currencyKeys, uint[] memory rates, bool ratesAreInvalid) internal view returns (uint excludedDebt, bool isInvalid) {
function _totalNonSnxBackedDebt(
bytes32[] memory currencyKeys,
uint[] memory rates,
bool ratesAreInvalid
) internal view returns (uint excludedDebt, bool isInvalid) {
// Calculate excluded debt.
// 1. MultiCollateral long debt + short debt.
(uint longValue, bool anyTotalLongRateIsInvalid) = collateralManager().totalLong();
Expand All @@ -226,6 +230,8 @@ contract BaseDebtCache is Owned, MixinSystemSettings, IDebtCache {
// Subtract sETH and sUSD issued by EtherWrapper.
excludedDebt = excludedDebt.add(etherWrapper().totalIssuedSynths());

// 3. WrapperFactory.
// Get the debt issued by the Wrappers.
for (uint i = 0; i < currencyKeys.length; i++) {
excludedDebt = excludedDebt.add(_excludedIssuedDebt[currencyKeys[i]].multiplyDecimalRound(rates[i]));
}
Expand Down
40 changes: 24 additions & 16 deletions contracts/Wrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ contract Wrapper is Owned, Pausable, MixinResolver, MixinSystemSettings, IWrappe
currencyKey = _currencyKey;
synthContractName = _synthContractName;
targetSynthIssued = 0;
token.approve(address(this), uint256(-1));
}

/* ========== VIEWS ========== */
Expand Down Expand Up @@ -273,7 +274,12 @@ contract Wrapper is Owned, Pausable, MixinResolver, MixinSystemSettings, IWrappe
targetSynthIssued = _targetSynthIssued;
}

function _safeTransferFrom(address _tokenAddress, address _from, address _to, uint256 _value) internal returns (bool success) {
function _safeTransferFrom(
address _tokenAddress,
address _from,
address _to,
uint256 _value
) internal returns (bool success) {
// note: both of these could be replaced with manual mstore's to reduce cost if desired
bytes memory msgData = abi.encodeWithSignature("transferFrom(address,address,uint256)", _from, _to, _value);
uint msgSize = msgData.length;
Expand All @@ -283,23 +289,25 @@ contract Wrapper is Owned, Pausable, MixinResolver, MixinSystemSettings, IWrappe
mstore(0x00, 0xff)

// note: this requires tangerine whistle compatible EVM
if iszero(call(gas(), _tokenAddress, 0, add(msgData, 0x20), msgSize, 0x00, 0x20)) { revert(0, 0) }

switch mload(0x00)
case 0xff {
// token is not fully ERC20 compatible, didn't return anything, assume it was successful
success := 1
}
case 0x01 {
success := 1
}
case 0x00 {
success := 0
}
default {
// unexpected value, what could this be?
if iszero(call(gas(), _tokenAddress, 0, add(msgData, 0x20), msgSize, 0x00, 0x20)) {
revert(0, 0)
}

switch mload(0x00)
case 0xff {
// token is not fully ERC20 compatible, didn't return anything, assume it was successful
success := 1
}
case 0x01 {
success := 1
}
case 0x00 {
success := 0
}
default {
// unexpected value, what could this be?
revert(0, 0)
}
}
}

Expand Down

0 comments on commit 20ba45e

Please sign in to comment.