sintaro0221
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ## [H-02] currentLoanOwner can manipulate loanInfo when any lenders try to buyout / ローンが買収される際、現在の所有者がローンの情報を操作しうる ### ■ カテゴリー - re-entrancy ### ■ 条件 - 攻撃者(悪意を持ったローン所有者)がローンをcreateした - 攻撃者のローンを任意のユーザーが買収しようとしている ### ■ ハッキングの詳細 ハッキングは以下の流れで行われる。 - ユーザーが攻撃者のローンを`lend()`をcallすることで融資する - `lend()`が実行された時、関数内で`ERC20(loanAssetContractAdress).safeTransfer`が実行される - ERC777コントラクトが`_callTokensRecieved`を実行する。この時、攻撃者がre-entrancyによって`lend()`をcallし、引数の`interestRate`, `durationSeconds`, を悪意のある値に設定する - `loanInfo`が悪意ある値に変更されたローンをユーザーは取得し、かつこのtxを取り消すことができない ### ■ 修正方法 `lend()`関数に`nonReentrant`modifierを使用する ```solidity! //before function lend( uint256 loanId, uint16 interestRate, uint128 amount, uint32 durationSeconds, address sendLendTicketTo ) external override notClosed(loanId); //after function lend( uint256 loanId, uint16 interestRate, uint128 amount, uint32 durationSeconds, address sendLendTicketTo ) external override notClosed(loanId) nonReentrant; ``` --- ## [H-03] Borrower can be their own lender and steal funds from buyout due to reentrancy / ローンを組んだユーザーが自身に対して融資することでre-entrancyによってローンが買収される際に買収資金を盗むことができる ### ■ カテゴリー - CEI - re-entrancy ### ■ 条件 - 悪意あるユーザーがローンを組む - `loanAssetContractAddress`トークンがtx処理のコントロールをreceiverに譲渡するようになっている ### ■ ハッキングの詳細 ローンの貸付と買収はどちらも`lend()`をcallする。ここで、問題の原因となるCEIパターンの欠如が発生している箇所は`lend()`内の以下の部分(コントラクトの214行目付近) ```solidity } else { ERC20(loan.loanAssetContractAddress).safeTransferFrom( msg.sender, currentLoanOwner, accumulatedInterest + previousLoanAmount ); } ILendTicket(lendTicketContract).loanFacilitatorTransfer(currentLoanOwner, sendLendTicketTo, loanId); ``` - 悪意あるユーザーがローンを組む(call `createLoan()`) - 先のユーザーが自身にNFTを`lend()`、融資する。この時、lending ticketと融資金は自身に送信される - 新たなユーザーがローンを買収する。この時、元のローンの価格と利息がNFTを悪意あるユーザーに送信される - 買収が完了する前に、悪意あるユーザーがローンを買収したユーザーに`lend ticket`が送信される前に`repayAndCloseLoan()`を実行し、買収資金を入手したうえで担保のNFTを引き続き所有できる - 買収しようとしたユーザーは価値のない(クローズされたローンの)lending ticketを受け取る `repayAndCloseLoan()`のコードは次の通り ```solidity function repayAndCloseLoan(uint256 loanId) external override notClosed(loanId) { Loan storage loan = loanInfo[loanId]; uint256 interest = _interestOwed( loan.loanAmount, loan.lastAccumulatedTimestamp, loan.perAnumInterestRate, loan.accumulatedInterest ); address lender = IERC721(lendTicketContract).ownerOf(loanId); loan.closed = true; ERC20(loan.loanAssetContractAddress).safeTransferFrom(msg.sender, lender, interest + loan.loanAmount); IERC721(loan.collateralContractAddress).safeTransferFrom( address(this), IERC721(borrowTicketContract).ownerOf(loanId), loan.collateralTokenId ); emit Repay(loanId, msg.sender, lender, interest, loan.loanAmount); emit Close(loanId); } ``` ### ■ 修正方法 - `lend()`内部でローンの買収資金が移転される前にlend ticketの所有権を移転する。 ```solidity // before } else { ERC20(loan.loanAssetContractAddress).safeTransferFrom( msg.sender, currentLoanOwner, accumulatedInterest + previousLoanAmount ); } ILendTicket(lendTicketContract).loanFacilitatorTransfer(currentLoanOwner, sendLendTicketTo, loanId); //after ILendTicket(lendTicketContract).loanFacilitatorTransfer(currentLoanOwner, sendLendTicketTo, loanId); if (/*...*/){ //... } else { ERC20(loan.loanAssetContractAddress).safeTransferFrom( msg.sender, currentLoanOwner, accumulatedInterest + previousLoanAmount ); } ``` - `nonReentrancy`modifierを使用する ```solidity //before function lend( uint256 loanId, uint16 interestRate, uint128 amount, uint32 durationSeconds, address sendLendTicketTo ) external override notClosed(loanId); //after function lend( uint256 loanId, uint16 interestRate, uint128 amount, uint32 durationSeconds, address sendLendTicketTo ) external override notClosed(loanId) nonReentrant; ``` - ローンを作成したアカウントが自分自身に貸し付けられないようにする --- ## [M-01] lend loanをする際に、dos攻撃で買わせないようにできる ### ■ カテゴリー dos ### ■ 条件 lend loanをする ### ■ ハッキングの詳細 reserveFactorが変更した際にsetReserveFactorが実行されてないので、価格が再生成されない ### ■ 修正方法 reserveFactorのupdate後に `_regenerate(true); _regenerate(false);`を呼び出す ただ、事情によりそのままにすることに --- ## [M-02] Solmateの`safetransfer`, `safetransferfrom` 関数による脆弱性 ### ■ カテゴリー solmate ### ■ 条件 solmateのsafetransferfrom,safetransferを使っていた場合 ### ■ ハッキングの詳細 Contractを持たないtokenに呼ばれた場合でも、これらの関数はsuccessをreturnするのでreturnチェックはパスし、transferされたとして計算されるが実際はされていない ### ■ 修正方法 `safeERC20`を使う、transferされたか確認チェックをする --- ## [M-03] 価格がwallの上限、下限を超え一定時間を超えるとRBSは自動的に資金を供給する ### ■ カテゴリー CEI ### ■ 条件 - 価格が、上限下限のレンジを超えconfig_.regenWaitを経過する - config_regenThresholdが下記を満たす ``` config_.regenThreshold <= _config.regenObserve - config_.regenWait / frequency ``` ### ■ ハッキングの詳細 status.high.countを config.regenThresholdより大きくし、treasureyからのfundを投入させる ### ■ 修正方法 - 1.価格を再生成する際にwall price内であることをチェックする - 2.config_.regenThesholdが下記を満たすようにする ``` config_.regenThreshold > _config.regenObserve - config_.regenWait / frequency ``` --- ## [M-05] 預金者が`closeLoan`でなく`repayAndCloseLoan`を使うと預金がなくなる ### ■ カテゴリー require ### ■ 条件 貸し手がいない場合 repayAndCloseLoan関数はrevertを返さない ### ■ ハッキングの詳細 上記条件で、repayAndCloseLoan関数を叩いた場合 `ERC20(loan.loanAssetContractAddress).safeTransferFrom(msg.sender, lender, interest + loan.loanAmount)` が実行されユーザーは預金を失くす ### ■ 修正方法 repayAndCloseLoanにチェックを加える [repayAndCloseLoan関数](https://github.com/code-423n4/2022-04-backed/blob/e8015d7c4b295af131f017e646ba1b99c8f608f0/contracts/NFTLoanFacilitator.sol#L230)でrequireを追加する ``` solidity # After require(loan.lastAccumulatedTimestamp > 0, "loan was never matched by a lender. use closeLoan instead"); ``` --- ## [M-07] mintBorrowTicketTo関数は、onERC721Receivedが実装されていないのでユーザーの資金、BorrowTicket NFTの凍結のリスクがある ### ■ カテゴリー safeMint ### ■ 条件 safeMintを使っていない ### ■ ハッキングの詳細 mintBorrowTicketToがonERC721Receivedを実装していないContractでもcreateLoanが実行できる mintBorrowTicketToはERC721を正しくハンドリングできない場合、問題となる。 ### ■ 修正方法 safeMintを使う ``` solidity # Before function mint(address to, uint256 tokenId) external override loanFacilitatorOnly { _mint(to, tokenId); } # After function mint(address to, uint256 tokenId) external override loanFacilitatorOnly { _safeMint(to, tokenId); } ``` ---

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully