Farseen0/scar-pairs huggingface dataset:
HIGH severity: Overwriting storage slots corresponding to _implementation and _owner. Accidentally changing these variables can result in changing the implementation and changing the owner, potentially stealing funds or making them inaccessible.

Vulnerable code:
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract ProxyStorage {
    bytes32 private constant _SLOT_PROXY_STORAGE =
        keccak256(abi.encode("io.synthetix.core-contracts.Proxy"));

    struct ProxyStore {
        address implementation;
        bool simulatingUpgrade;
    }

    function _proxyStore() internal pure returns (ProxyStore storage store) {
        bytes32 s = _SLOT_PROXY_STORAGE;
        assembly {
            store.slot := s
        }
    }
}


Vulnerability type: CWE-284|CWE-282
MEDIUM severity: Risk of replay attacks across chains. Signed messages on one chain may be replayed on another chain if _chainId is not unique for different chains.

Vulnerable code:
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity =0.8.10;
pragma abicoder v1;

import "./ECDSA.sol";

/// @title Provides signer address recovery for EIP-712 signed messages
/// @notice https://github.com/ethereum/EIPs/pull/712
abstract contract EIP712SignerRecovery {
  /// @dev Recovers the signer address for an EIP-712 signed message
  /// @param dataHash Hash of the data included in the message
  /// @param signature An EIP-712 signature
  function _recoverSigner(bytes32 dataHash, bytes calldata signature) internal view returns (address) {
    // generate the hash for the signed message
    bytes32 messageHash = keccak256(abi.encodePacked(
      "\x19\x01",
      // hash the EIP712 domain separator
      keccak256(abi.encode(
        keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
        keccak256("BrinkAccount"),
        keccak256("1"),
        block.chainid,
        address(this)
      )),
      dataHash
    ));

    // recover the signer address from the signed messageHash and return
    return ECDSA.recover(messageHash, signature);
  }
}


Vulnerability type: CWE-435|CWE-436|CWE-115
MEDIUM severity: CDPToken is not protected for the ERC20 approval race condition. The CDPToken contract is not protected against ERC20 approval race conditions.

Vulnerable code:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";

/**
 * @title CDP Token for the Carpe Diem Pension system
 * @author Carpe Diem
 * @notice Basic burnable token with permit
 * @dev Part of a system of three contracts. The other two are called Pension and Auction
 */
contract CDPToken is
    ERC20,
    ERC20Permit
{
    /** @notice Address of the Pension contract */
    address public immutable minterAddress;
    /** @notice Tracks the total amount of destroyed tokens */
    uint256 public totalBurned;

    /**
     * @notice Construct the contract and mint the initial supply
     * @param pensionAddress Address of the Pension contract
     */
    constructor(
        address pensionAddress
    )
        ERC20("Carpe Diem Pension", "CDP")
        ERC20Permit("Carpe Diem Pension")
    {
        minterAddress = pensionAddress;
        _mint(msg.sender, 543391647*1e18);
    }

    /**
     * @notice Create new tokens
     * @param to Address of the recipient
     * @param amount Amount of tokens to create
     * @dev Restriced to the Pension contract
     */
    function mint(
        address to,
        uint256 amount
    ) public {
        require(
            msg.sender == minterAddress,
            "No permission"
        );
        _mint(to, amount);
    }

    /**
     * @notice Destroys tokens from existence
     * @param amount Amount to destroy
     * @dev Keeps track of destroyed tokens 
     */
    function burn(
        uint256 amount
    ) public {
        totalBurned += amount;
        _burn(_msgSender(), amount);
    }

    /**
     * @notice Destroys tokens from existence for someone else, if the caller has sufficient allowance
     * @param account Account to destroy tokens from
     * @param amount Amount to destroy
     * @dev Keeps track of destroyed tokens 
     */
    function burnFrom(
        address account, 
        uint256 amount
    ) public {
        totalBurned += amount;
        _spendAllowance(account, _msgSender(), amount);
        _burn(account, amount);
    }
}

Vulnerability type: CWE-693
HIGH severity: Data Consistency. Insecure modification of `yieldSourceVault` variable.

Vulnerable code:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

/**
 * @title GeneralYieldSourceAdapter
 * @dev sub-contract of Revenue Share Vault, serving as the Yield Source Adapter template
 */
abstract contract GeneralYieldSourceAdapter is Initializable {
    /// @dev Yield source vault address
    address public yieldSourceVault;

    /// @dev Emitted when the yieldSourceVault address is updated.
    event YieldSourceVaultUpdated(address yieldSourceVault_);

    /**
     * @dev to be used for calculating the revenue share ratio
     * @dev virtual, expected to be overridden with specific yield source vault
     * @return yieldSourceTotalShares total yield source shares supply
     */
    function getYieldSourceVaultTotalShares() external view virtual returns (uint256);

    /**
     * @param account target account address
     * @dev virtual, expected to be overridden with specific yield source vault
     * @return shares yield source share balance of this vault
     */
    function shareBalanceAtYieldSourceOf(address account) public view virtual returns (uint256);

    /**
     * @notice GeneralYieldSourceAdapter initializer
     * @param yieldSourceVault_ vault address of yield source
     */
    function __GeneralYieldSourceAdapter_init(address yieldSourceVault_) internal onlyInitializing {
        __GeneralYieldSourceAdapter_init_unchained(yieldSourceVault_);
    }

    function __GeneralYieldSourceAdapter_init_unchained(address yieldSourceVault_) internal onlyInitializing {
        yieldSourceVault = yieldSourceVault_;
        emit YieldSourceVaultUpdated(yieldSourceVault_);
    }

    /**
     * @dev Deposit assets to yield source vault
     * @dev virtual, expected to be overridden with specific yield source vault
     * @param asset_ The address of the ERC20 asset contract
     * @param amount_ The amount of assets to deposit
     * @return shares amount of shares received
     */
    function _depositToYieldSourceVault(address asset_, uint256 amount_) internal virtual returns (uint256);

    /**
     * @dev Redeem assets with vault shares from yield source vault
     * @dev virtual, expected to be overridden with specific yield source vault
     * @param shares amount of shares to burn and redeem assets
     * @return assets amount of assets received
     */
    function _redeemFromYieldSourceVault(uint256 shares) internal virtual returns (uint256);

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[19] private __gap;
}


Vulnerability type: CWE-284|CWE-285|CWE-732
HIGH severity: OrderBook Denial of Service leveraging blacklistable tokens like USDC. An attacker can block the main functionality of the OrderBook by creating a broken order, leading to a denial-of-service attack.

Vulnerable code:
// SPDX-License-Identifier: MIT

pragma solidity =0.8.3;

import "./interfaces/IOrderBook.sol";
import "./libraries/Orders.sol";

contract OrderBook is IOrderBook {
    using Orders for Orders.Ask;

    mapping(bytes32 => Orders.Ask) public override orders;

    function submitOrder(
        address nft,
        uint256 tokenId,
        uint256 amount,
        address strategy,
        address currency,
        address recipient,
        uint256 deadline,
        bytes memory params
    ) external override returns (bytes32 hash) {
        Orders.Ask memory order =
            Orders.Ask(
                msg.sender,
                nft,
                tokenId,
                amount,
                strategy,
                currency,
                recipient,
                deadline,
                params,
                0,
                bytes32(0),
                bytes32(0)
            );
        hash = order.hash();
        orders[hash] = order;
    }
}


Vulnerability type: CWE-691|CWE-799
HIGH severity: A transaction doesn't have the sequence information. In case of multiple transactions, any owner is able to choose the sequence of transactions.

Vulnerable code:
//SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

import "./IMultiSigWalletEvents.sol";

interface IMultiSigWallet is IMultiSigWalletEvents {}


Vulnerability type: CWE-284|CWE-285|CWE-863
MEDIUM severity: PriceFeedWrapper rate return value not checked. The data retrieval from the rate conversion wrapper does not check the retrieved price and success condition, which could lead to invalid data being used.

Vulnerable code:
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.17;

import { FixedPointMathLib } from "solmate/src/utils/FixedPointMathLib.sol";
import { IPriceFeed } from "./utils/IPriceFeed.sol";

contract PriceFeedWrapper is IPriceFeed {
  using FixedPointMathLib for uint256;

  /// @notice Main price feed where the price is fetched from.
  IPriceFeed public immutable mainPriceFeed;
  /// @notice Number of decimals that the answer of this price feed has.
  uint8 public immutable decimals;
  /// @notice Address of the wrapper contract where the asset rate is fetched from.
  address public immutable wrapper;
  /// @notice Function selector of the wrapper contract where the asset rate is fetched from.
  bytes4 public immutable conversionSelector;
  /// @notice Base units that are sent to the conversion function to get the asset rate.
  uint256 public immutable baseUnit;

  constructor(IPriceFeed mainPriceFeed_, address wrapper_, bytes4 conversionSelector_, uint256 baseUnit_) {
    mainPriceFeed = mainPriceFeed_;
    decimals = mainPriceFeed_.decimals();
    wrapper = wrapper_;
    conversionSelector = conversionSelector_;
    baseUnit = baseUnit_;
  }

  /// @notice Returns the price feed's latest value considering the wrapped asset's rate.
  function latestAnswer() external view returns (int256) {
    int256 mainPrice = mainPriceFeed.latestAnswer();

    (, bytes memory data) = address(wrapper).staticcall(abi.encodeWithSelector(conversionSelector, baseUnit));
    uint256 rate = abi.decode(data, (uint256));

    return int256(uint256(mainPrice).mulDivDown(rate, baseUnit));
  }
}


Vulnerability type: CWE-703|CWE-754|CWE-252
MEDIUM severity: Transferring tokens without tainting. An attacker can do deposit/withdraw in small amounts, exploiting `_minimumTaintedTransferAmount`.

Vulnerable code:
pragma solidity ^0.5.11;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol";
import "@openzeppelin/contracts/ownership/Ownable.sol";

contract LPToken is ERC20, ERC20Detailed, ERC20Burnable, Ownable {
    constructor (string memory name_, string memory symbol_, uint8 decimals_
    ) public ERC20Detailed(name_, symbol_, decimals_) {}

    function mint(address recipient, uint256 amount) external onlyOwner {
        _mint(recipient, amount);
    }
}


Vulnerability type: CWE-284|CWE-285|CWE-863
MEDIUM severity: `CurveLPOracle` is not working. `CurveLPOracle` will never be used due to the existing `crvUSD` oracle on mainnet.

Vulnerable code:
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.17;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

import "../../libraries/ScaledMath.sol";
import "../../interfaces/IGenericOracle.sol";

contract GenericOracle is IGenericOracle, Ownable {
    using ScaledMath for uint256;

    event CustomOracleAdded(address token, address oracle);

    mapping(address => IOracle) public customOracles;

    IOracle internal _chainlinkOracle;
    IOracle internal _curveLpOracle;

    function initialize(address curveLpOracle, address chainlinkOracle) external {
        require(address(_curveLpOracle) == address(0), "already initialized");
        _chainlinkOracle = IOracle(chainlinkOracle);
        _curveLpOracle = IOracle(curveLpOracle);
    }

    function isTokenSupported(address token) external view override returns (bool) {
        return
            address(customOracles[token]) != address(0) ||
            _chainlinkOracle.isTokenSupported(token) ||
            _curveLpOracle.isTokenSupported(token);
    }

    function getUSDPrice(address token) public view virtual returns (uint256) {
        if (_chainlinkOracle.isTokenSupported(token)) {
            return _chainlinkOracle.getUSDPrice(token);
        }
        if (address(customOracles[token]) != address(0)) {
            return customOracles[token].getUSDPrice(token);
        }
        return _curveLpOracle.getUSDPrice(token);
    }

    function setCustomOracle(address token, address oracle) external onlyOwner {
        customOracles[token] = IOracle(oracle);
        emit CustomOracleAdded(token, oracle);
    }

    function curveLpToUnderlying(
        address curveLpToken,
        address underlying,
        uint256 curveLpAmount
    ) external view returns (uint256) {
        return
            curveLpToUnderlying(curveLpToken, underlying, curveLpAmount, getUSDPrice(underlying));
    }

    function curveLpToUnderlying(
        address curveLpToken,
        address underlying,
        uint256 curveLpAmount,
        uint256 underlyingPrice
    ) public view returns (uint256) {
        return
            curveLpAmount.mulDown(getUSDPrice(curveLpToken)).divDown(underlyingPrice).convertScale(
                18,
                IERC20Metadata(underlying).decimals()
            );
    }

    function underlyingToCurveLp(
        address underlying,
        address curveLpToken,
        uint256 underlyingAmount
    ) external view returns (uint256) {
        return
            underlyingAmount
                .mulDown(getUSDPrice(address(underlying)))
                .divDown(getUSDPrice(curveLpToken))
                .convertScale(IERC20Metadata(underlying).decimals(), 18);
    }
}


Vulnerability type: CWE-435
HIGH severity: Malicious call data can DOS execute. An attacker can DOS the executor contract by giving infinite allowance to normal users.

Vulnerable code:
pragma solidity >=0.5.0 <0.7.0;

/*
    Gnosis Safe Executor - library wrapping low level calls
    https://github.com/gnosis/safe-contracts/blob/development/contracts/base/Executor.sol

    Ability to execute delegateCall has been removed for security
*/

/// @title Executor - A contract that can execute transactions
/// @author Richard Meissner - <richard@gnosis.pm>

contract Executor {
    function execute(
        address to,
        uint256 value,
        bytes memory data,
        uint256 txGas
    ) internal returns (bool success) {
        success = executeCall(to, value, data, txGas);
    }

    function executeCall(
        address to,
        uint256 value,
        bytes memory data,
        uint256 txGas
    ) internal returns (bool success) {
        // solium-disable-next-line security/no-inline-assembly
        assembly {
            success := call(
                txGas,
                to,
                value,
                add(data, 0x20),
                mload(data),
                0,
                0
            )
        }
    }
}


Vulnerability type: CWE-284|CWE-285|CWE-862
HIGH severity: Cross-chain messaging via Multichain protocol will fail. Cross-chain messaging using Multichain within Connext will not work due to a lack of gas fee consideration.

Vulnerable code:
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.15;

import {Multichain} from "../../interfaces/ambs/Multichain.sol";

abstract contract BaseMultichain {
  // ============ Internal Storage ============
  address internal immutable EXECUTOR; // Is != amb, used only to retrieve sender context

  // Mirror chain id
  uint256 internal immutable MIRROR_CHAIN_ID;

  // ============ Constructor ============
  constructor(address _amb, uint256 _mirrorChainId) {
    // sanity checks
    require(_mirrorChainId != 0, "!mirrorChainId");

    // set immutable propertioes
    EXECUTOR = Multichain(_amb).executor();
    require(EXECUTOR != address(0), "!executor");
    MIRROR_CHAIN_ID = _mirrorChainId;
  }

  // ============ Public Fns ============
  function anyExecute(bytes memory _data) external returns (bool success, bytes memory result) {
    _processMessage(_data);
  }

  // ============ Private fns ============
  /**
   * @notice This function is used by the AMBs to handle incoming messages. Should store the latest
   * root generated on the l2 domain.
   */
  function _processMessage(bytes memory _data) internal virtual;

  /**
   * @dev Sends `outboundRoot` to root manager on the mirror chain
   */
  function _sendMessage(address _amb, bytes memory _data) internal {
    Multichain(_amb).anyCall(
      _amb, // Same address on every chain, using AMB as it is immutable
      _data,
      address(0), // fallback address on origin chain
      MIRROR_CHAIN_ID,
      0 // fee paid on origin chain
    );
  }

  function _verifySender(address _amb, address _expected) internal view returns (bool) {
    require(msg.sender == _amb, "!bridge");

    (address from, uint256 fromChainId, ) = Multichain(EXECUTOR).context();
    return from == _expected && fromChainId == MIRROR_CHAIN_ID;
  }
}


Vulnerability type: CWE-682
MEDIUM severity: WatcherManager is not set correctly. SetWatcherManager function does not update the watcherManager.

Vulnerable code:
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.15;

import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";

import {ProposedOwnable} from "../shared/ProposedOwnable.sol";
import {WatcherManager} from "./WatcherManager.sol";

/**
 * @notice This contract abstracts the functionality of the watcher manager.
 * Contracts can inherit this contract to be able to use the watcher manager's shared watcher set.
 */

contract WatcherClient is ProposedOwnable, Pausable {
  // ============ Events ============
  event WatcherManagerChanged(address watcherManager);

  // ============ Properties ============
  WatcherManager watcherManager;

  // ============ Constructor ============
  constructor(address _watcherManager) {
    watcherManager = WatcherManager(_watcherManager);
  }

  // ============ Modifiers ============
  modifier onlyWatcher() {
    require(watcherManager.isWatcher(msg.sender), "!watcher");
    _;
  }

  // ============ Admin fns ============
  /**
   * @dev Owner can enroll a watcher (abilities are defined by inheriting contracts)
   */
  function setWatcherManager(address _watcherManager) external onlyOwner {
    require(_watcherManager != address(watcherManager), "already watcher manager");
    emit WatcherManagerChanged(_watcherManager);
  }

  function unpause() external onlyOwner whenPaused {
    _unpause();
  }

  // ============ Watcher fns ============
  function pause() external onlyWatcher whenNotPaused {
    _pause();
  }
}


Vulnerability type: CWE-664|CWE-665|CWE-909
MEDIUM severity: Extra checks in _verifySender() of GnosisBase. Lack of check for messageSourceChainId() in _verifySender(), allowing malicious actors to spoof function calls and asset transfers.

Vulnerable code:
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.15;

import {GnosisAmb} from "../../interfaces/ambs/GnosisAmb.sol";

import {Connector} from "../Connector.sol";

abstract contract GnosisBase {
  // ============ Constructor ============
  constructor() {}

  // ============ Private fns ============
  /**
   * @dev Asserts the sender of a cross domain message
   */
  function _verifySender(address _amb, address _expected) internal view returns (bool) {
    require(msg.sender == _amb, "!bridge");
    return GnosisAmb(_amb).messageSender() == _expected;
  }
}


Vulnerability type: CWE-284|CWE-346
MEDIUM severity: No Slippage Protection in Curve Pools Swap. The `.exchange` functions have no slippage protection, making them vulnerable to frontrunning and sandwich attacks.

Vulnerable code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { AbstractHarvester } from "./AbstractHarvester.sol";

contract Harvester is AbstractHarvester {
    constructor(address _vault, address _usdtAddress)
        AbstractHarvester(_vault, _usdtAddress)
    {}
}


Vulnerability type: CWE-693
HIGH severity: Missing proposeClaim() function in Insurance contract. No implementation for proposing claims in insurance cases.

Vulnerable code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.12;

import "./RewardsAndPenalties.sol";


contract Insurance is RewardsAndPenalties {
    uint private constant BASE_INSURANCE_FOR_BP = 3500; // trigger insurance with contract balance fall below 35%
    uint private constant OPT_IN_INSURANCE_FEE_BP = 1000; // 10%
    uint private constant OPT_IN_INSURANCE_FOR_BP = 10000; // 100%

    bool public isInInsuranceState = false; // if contract is only allowing insured money this becomes true;

    function _checkForBaseInsuranceTrigger() internal {
        if (fourRXToken.balanceOf(address(this)) <= _calcPercentage(maxContractBalance, BASE_INSURANCE_FOR_BP)) {
            isInInsuranceState = true;
        } else {
            isInInsuranceState = false;
        }
    }

    function _getInsuredAvailableAmount(Stake memory stake, uint withdrawalAmount) internal pure returns (uint)
    {
        uint availableAmount = withdrawalAmount;
        // Calc correct insured value by checking which insurance should be applied
        uint insuredFor = BASE_INSURANCE_FOR_BP;
        if (stake.optInInsured) {
            insuredFor = OPT_IN_INSURANCE_FOR_BP;
        }

        uint maxWithdrawalAllowed = _calcPercentage(stake.deposit, insuredFor);

        require(maxWithdrawalAllowed >= stake.withdrawn.add(stake.penalty)); // if contract is in insurance trigger, do not allow withdrawals for the users who already have withdrawn more then 35%

        if (stake.withdrawn.add(availableAmount).add(stake.penalty) > maxWithdrawalAllowed) {
            availableAmount = maxWithdrawalAllowed.sub(stake.withdrawn).sub(stake.penalty);
        }

        return availableAmount;
    }

    function _insureStake(address user, Stake storage stake) internal {
        require(!stake.optInInsured && stake.active);
        require(fourRXToken.transferFrom(user, address(this), _calcPercentage(stake.deposit, OPT_IN_INSURANCE_FEE_BP)));

        stake.optInInsured = true;
    }
}


Vulnerability type: CWE-710|CWE-1068