Skip to content

Commit

Permalink
Merge pull request #22 from lombard-finance/feat/audit-2
Browse files Browse the repository at this point in the history
update contracts
  • Loading branch information
hashxtree authored Oct 10, 2024
2 parents 6e5e9cd + f44febd commit 438ddbf
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 43 deletions.
2 changes: 0 additions & 2 deletions contracts/LBTC/ILBTC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ interface ILBTC {
error BadDestination();
error KnownDestination();
error UnknownDestination();
error BadCommission();
error ScriptPubkeyUnsupported();
error AmountTooSmallToPayRelativeFee();
error AmountLessThanCommission(uint256 fee);
error AmountBelowDustLimit(uint256 dustLimit);
error InvalidDustFeeRate();
Expand Down
14 changes: 6 additions & 8 deletions contracts/LBTC/LBTC.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {ERC20Upgradeable, IERC20} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {ERC20PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";
import {ERC20PermitUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol";
Expand All @@ -11,10 +9,10 @@ import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/ut
import { BitcoinUtils, OutputType } from "../libs/BitcoinUtils.sol";
import { IBascule } from "../bascule/interfaces/IBascule.sol";
import { FeeUtils } from "../libs/FeeUtils.sol";
import "./ILBTC.sol";
import "../libs/OutputCodec.sol";
import "../libs/BridgeDepositCodec.sol";
import "../libs/EIP1271SignatureUtils.sol";
import {ILBTC} from "./ILBTC.sol";
import {OutputCodec, OutputWithPayload} from "../libs/OutputCodec.sol";
import {BridgeDepositCodec, BridgeDepositPayload} from "../libs/BridgeDepositCodec.sol";
import {EIP1271SignatureUtils} from "../libs/EIP1271SignatureUtils.sol";

/**
* @title ERC20 representation of Lombard Staked Bitcoin
Expand Down Expand Up @@ -83,11 +81,11 @@ contract LBTC is ILBTC, ERC20PausableUpgradeable, Ownable2StepUpgradeable, Reent
_changeBurnCommission(burnCommission_);
}

function initialize(address consortium_, uint64 burnCommission_, address owner) external initializer {
function initialize(address consortium_, uint64 burnCommission_, address owner_) external initializer {
__ERC20_init("LBTC", "LBTC");
__ERC20Pausable_init();

__Ownable_init(owner);
__Ownable_init(owner_);
__Ownable2Step_init();

__ReentrancyGuard_init();
Expand Down
9 changes: 4 additions & 5 deletions contracts/bascule/Bascule.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.24;
pragma solidity 0.8.24;

import "@openzeppelin/contracts/utils/Pausable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/access/extensions/AccessControlDefaultAdminRules.sol";
import "./interfaces/IBascule.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
import {AccessControlDefaultAdminRules} from "@openzeppelin/contracts/access/extensions/AccessControlDefaultAdminRules.sol";
import {IBascule} from "./interfaces/IBascule.sol";

/// Bascule contract for preventing bridge hacks from hitting the chain.
/// This is the on-chain component of an off-chain/on-chain system.
Expand Down
2 changes: 1 addition & 1 deletion contracts/bascule/interfaces/IBascule.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.24;
pragma solidity 0.8.24;

/// Interface of the Bascule contract as used by on-chain contracts.
/// @custom:security-contact [email protected]
Expand Down
8 changes: 4 additions & 4 deletions contracts/consortium/LombardConsortium.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/interfaces/IERC1271.sol";
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import "../libs/EIP1271SignatureUtils.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import {EIP1271SignatureUtils} from "../libs/EIP1271SignatureUtils.sol";

/**
* @title The contract utilize consortium governance functions
Expand Down
2 changes: 1 addition & 1 deletion contracts/consortium/LombardTimeLock.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "@openzeppelin/contracts/governance/TimelockController.sol";
import {TimelockController} from "@openzeppelin/contracts/governance/TimelockController.sol";

/**
* @title Use for Consortium
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
pragma solidity 0.8.24;

import {CREATE3} from "solmate/src/utils/CREATE3.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
Expand Down
5 changes: 2 additions & 3 deletions contracts/libs/EIP1271SignatureUtils.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "@openzeppelin/contracts/interfaces/IERC1271.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

/**
* @title Library of utilities for making EIP1271-compliant signature checks.
Expand Down
3 changes: 0 additions & 3 deletions contracts/libs/OutputCodec.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;



struct OutputWithPayload {
uint256 chainId;
address to;
Expand All @@ -11,7 +9,6 @@ struct OutputWithPayload {
uint32 index;
}


library OutputCodec {
error WrongDataLength();
error WrongChainIdEncoding();
Expand Down
5 changes: 0 additions & 5 deletions contracts/mock/BasculeMock.sol

This file was deleted.

3 changes: 1 addition & 2 deletions contracts/mock/WBTCMock.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { ERC20Upgradeable, IERC20 } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";

/**
* @title Mock implementation of WBTC token
Expand Down
14 changes: 6 additions & 8 deletions contracts/pmm/BTCB/BTCB.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/Pau
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {FeeUtils} from "../../../contracts/libs/FeeUtils.sol";

interface ILBTC {
interface ILBTC is IERC20Metadata {
function mint(address to, uint256 amount) external;
function transfer(address to, uint256 amount) external;
function decimals() external view returns (uint256);
}

contract BTCBPMM is PausableUpgradeable, AccessControlUpgradeable {
using SafeERC20 for IERC20Metadata;
using SafeERC20 for ILBTC;

struct PMMStorage {
IERC20Metadata btcb;
Expand All @@ -28,7 +26,7 @@ contract BTCBPMM is PausableUpgradeable, AccessControlUpgradeable {
address withdrawAddress;
uint16 relativeFee;
}

bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

// keccak256(abi.encode(uint256(keccak256("lombardfinance.storage.BTCBPMM")) - 1)) & ~bytes32(uint256(0xff))
Expand All @@ -53,7 +51,7 @@ contract BTCBPMM is PausableUpgradeable, AccessControlUpgradeable {
PMMStorage storage $ = _getPMMStorage();
$.stakeLimit = _stakeLimit;
$.withdrawAddress = withdrawAddress;

$.lbtc = ILBTC(_lbtc);
$.btcb = IERC20Metadata(_btcb);
$.relativeFee = _relativeFee;
Expand Down Expand Up @@ -100,12 +98,12 @@ contract BTCBPMM is PausableUpgradeable, AccessControlUpgradeable {

function withdrawBTCB(uint256 amount) external whenNotPaused onlyRole(DEFAULT_ADMIN_ROLE) {
PMMStorage storage $ = _getPMMStorage();
$.btcb.transfer($.withdrawAddress, amount);
$.btcb.safeTransfer($.withdrawAddress, amount);
}

function withdrawLBTC(uint256 amount) external whenNotPaused onlyRole(DEFAULT_ADMIN_ROLE) {
PMMStorage storage $ = _getPMMStorage();
$.lbtc.transfer($.withdrawAddress, amount);
$.lbtc.safeTransfer($.withdrawAddress, amount);
}

function setWithdrawalAddress(address newWithdrawAddress) external onlyRole(DEFAULT_ADMIN_ROLE) {
Expand Down

0 comments on commit 438ddbf

Please sign in to comment.