본문 바로가기
Hack/Cryptocurrency

EOSIO 기반 Mainnet의 Smart Cotract WASM(Web Assembly) 보는 방법

by Becoming a Hacker 2023. 9. 4.
반응형

EOSIO 기반의 Mainnet은 Smart Contract의 코드를 비공개하고 있어, ERC-20과 같이 코드를 쉽게 볼 수 없는데요. ㅠㅠ

 

사실 완전히 못보는 것은 아니고 WASM(Web Assembly)까지는 볼 수 있습니다. 그래서 오늘 포스팅할 내용은 EOSIO 기반의 Mainnet에서 Smart Contract의 WASM를 보는 방법을 포스팅하려고 합니다.


EOSIO CLI 설치 방법

MAC

$ brew tap eosio/eosio
$ brew install eosio

Ubuntu (Ubuntu 20.04 기준)

$ wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb
$ sudo dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb
$ wget https://github.com/eosio/eos/releases/download/v2.1.0/eosio_2.1.0-1-ubuntu-20.04_amd64.deb
$ sudo apt install ./eosio_2.1.0-1-ubuntu-20.04_amd64.deb

 

EOSIO 기반 Mainnet의 Smart Contract WASM 보는 방법

EOSIO 기반의 Mainnet은 Smart Contract가 cpp로 작성되어 있고, Compile 과정에서 WASM로 변환이 됩니다.

 

이러한 WASM 파일은 위에서 설치한 EOSIO CLI인 cleos를 통해 다운로드 받을 수 있습니다.

 

cleos를 통해 Smart Contract의 정보를 획득하기 위해서는 한 개 이상의 Node의 도메인을 알고 있어야 합니다.

참고 : EOS의 경우 아래의 사이트에서 확인할 수 있음

 

Antelope Tools network monitor real-time infrastructure data for multiple Antelope and EOSIO chains.

Antelope Tools Dashboard is a network monitor featuring real-time data on block producer nodes and blockchain infrastructure for multiple Antelope and EOSIO chains.

eos.antelope.tools

 

아래와 같이 cleos와 Node 도메인을 활용하여 Smart Contract 관련 데이터(Code Hash, ABI, WASM)를 확인할 수 있습니다.

Smart Contract의 Code Hash 확인 방법

$ cleos -u https://eos.genereos.io get code eosio.token
code hash: f6a2939074d69fc194d4b7b5a4d2c24e2766046ddeaa58b63ddfd579a0193623

 

Smart Contract의 ABI 다운로드 방법

$ cleos -u https://eos.genereos.io get code eosio.token -a eosio.token.abi
code hash: f6a2939074d69fc194d4b7b5a4d2c24e2766046ddeaa58b63ddfd579a0193623
saving abi to eosio.token.abi

$ cat eosio.token.abi
{
  "version": "eosio::abi/1.1",
  "types": [],
  "structs": [{
      "name": "account",
      "base": "",
      "fields": [{
          "name": "balance",
          "type": "asset"
        }
      ]
    },{
      "name": "close",
      "base": "",
      "fields": [{
          "name": "owner",
          "type": "name"
        },{
          "name": "symbol",
          "type": "symbol"
        }
      ]
    },{
      "name": "create",
      "base": "",
      "fields": [{
          "name": "issuer",
          "type": "name"
        },{
          "name": "maximum_supply",
          "type": "asset"
        }
      ]
    },{
      "name": "currency_stats",
      "base": "",
      "fields": [{
          "name": "supply",
          "type": "asset"
        },{
          "name": "max_supply",
          "type": "asset"
        },{
          "name": "issuer",
          "type": "name"
        }
      ]
    },{
      "name": "issue",
      "base": "",
      "fields": [{
          "name": "to",
          "type": "name"
        },{
          "name": "quantity",
          "type": "asset"
        },{
          "name": "memo",
          "type": "string"
        }
      ]
    },{
      "name": "open",
      "base": "",
      "fields": [{
          "name": "owner",
          "type": "name"
        },{
          "name": "symbol",
          "type": "symbol"
        },{
          "name": "ram_payer",
          "type": "name"
        }
      ]
    },{
      "name": "retire",
      "base": "",
      "fields": [{
          "name": "quantity",
          "type": "asset"
        },{
          "name": "memo",
          "type": "string"
        }
      ]
    },{
      "name": "transfer",
      "base": "",
      "fields": [{
          "name": "from",
          "type": "name"
        },{
          "name": "to",
          "type": "name"
        },{
          "name": "quantity",
          "type": "asset"
        },{
          "name": "memo",
          "type": "string"
        }
      ]
    }
  ],
  "actions": [{
      "name": "close",
      "type": "close",
      "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Close Token Balance\nsummary: 'Close {{nowrap owner}}’s zero quantity balance'\nicon: https://raw.githubusercontent.com/cryptokylin/eosio.contracts/v1.7.0/contracts/icons/token.png#207ff68b0406eaa56618b08bda81d6a0954543f36adc328ab3065f31a5c5d654\n---\n\n{{owner}} agrees to close their zero quantity balance for the {{symbol_to_symbol_code symbol}} token.\n\nRAM will be refunded to the RAM payer of the {{symbol_to_symbol_code symbol}} token balance for {{owner}}."
    },{
      "name": "create",
      "type": "create",
      "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Create New Token\nsummary: 'Create a new token'\nicon: https://raw.githubusercontent.com/cryptokylin/eosio.contracts/v1.7.0/contracts/icons/token.png#207ff68b0406eaa56618b08bda81d6a0954543f36adc328ab3065f31a5c5d654\n---\n\n{{$action.account}} agrees to create a new token with symbol {{asset_to_symbol_code maximum_supply}} to be managed by {{issuer}}.\n\nThis action will not result any any tokens being issued into circulation.\n\n{{issuer}} will be allowed to issue tokens into circulation, up to a maximum supply of {{maximum_supply}}.\n\nRAM will deducted from {{$action.account}}’s resources to create the necessary records."
    },{
      "name": "issue",
      "type": "issue",
      "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Issue Tokens into Circulation\nsummary: 'Issue {{nowrap quantity}} into circulation and transfer into {{nowrap to}}’s account'\nicon: https://raw.githubusercontent.com/cryptokylin/eosio.contracts/v1.7.0/contracts/icons/token.png#207ff68b0406eaa56618b08bda81d6a0954543f36adc328ab3065f31a5c5d654\n---\n\nThe token manager agrees to issue {{quantity}} into circulation, and transfer it into {{to}}’s account.\n\n{{#if memo}}There is a memo attached to the transfer stating:\n{{memo}}\n{{/if}}\n\nIf {{to}} does not have a balance for {{asset_to_symbol_code quantity}}, or the token manager does not have a balance for {{asset_to_symbol_code quantity}}, the token manager will be designated as the RAM payer of the {{asset_to_symbol_code quantity}} token balance for {{to}}. As a result, RAM will be deducted from the token manager’s resources to create the necessary records.\n\nThis action does not allow the total quantity to exceed the max allowed supply of the token."
    },{
      "name": "open",
      "type": "open",
      "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Open Token Balance\nsummary: 'Open a zero quantity balance for {{nowrap owner}}'\nicon: https://raw.githubusercontent.com/cryptokylin/eosio.contracts/v1.7.0/contracts/icons/token.png#207ff68b0406eaa56618b08bda81d6a0954543f36adc328ab3065f31a5c5d654\n---\n\n{{ram_payer}} agrees to establish a zero quantity balance for {{owner}} for the {{symbol_to_symbol_code symbol}} token.\n\nIf {{owner}} does not have a balance for {{symbol_to_symbol_code symbol}}, {{ram_payer}} will be designated as the RAM payer of the {{symbol_to_symbol_code symbol}} token balance for {{owner}}. As a result, RAM will be deducted from {{ram_payer}}’s resources to create the necessary records."
    },{
      "name": "retire",
      "type": "retire",
      "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Remove Tokens from Circulation\nsummary: 'Remove {{nowrap quantity}} from circulation'\nicon: https://raw.githubusercontent.com/cryptokylin/eosio.contracts/v1.7.0/contracts/icons/token.png#207ff68b0406eaa56618b08bda81d6a0954543f36adc328ab3065f31a5c5d654\n---\n\nThe token manager agrees to remove {{quantity}} from circulation, taken from their own account.\n\n{{#if memo}} There is a memo attached to the action stating:\n{{memo}}\n{{/if}}"
    },{
      "name": "transfer",
      "type": "transfer",
      "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Transfer Tokens\nsummary: 'Send {{nowrap quantity}} from {{nowrap from}} to {{nowrap to}}'\nicon: https://raw.githubusercontent.com/cryptokylin/eosio.contracts/v1.7.0/contracts/icons/transfer.png#5dfad0df72772ee1ccc155e670c1d124f5c5122f1d5027565df38b418042d1dd\n---\n\n{{from}} agrees to send {{quantity}} to {{to}}.\n\n{{#if memo}}There is a memo attached to the transfer stating:\n{{memo}}\n{{/if}}\n\nIf {{from}} is not already the RAM payer of their {{asset_to_symbol_code quantity}} token balance, {{from}} will be designated as such. As a result, RAM will be deducted from {{from}}’s resources to refund the original RAM payer.\n\nIf {{to}} does not have a balance for {{asset_to_symbol_code quantity}}, {{from}} will be designated as the RAM payer of the {{asset_to_symbol_code quantity}} token balance for {{to}}. As a result, RAM will be deducted from {{from}}’s resources to create the necessary records."
    }
  ],
  "tables": [{
      "name": "accounts",
      "index_type": "i64",
      "key_names": [],
      "key_types": [],
      "type": "account"
    },{
      "name": "stat",
      "index_type": "i64",
      "key_names": [],
      "key_types": [],
      "type": "currency_stats"
    }
  ],
  "ricardian_clauses": [],
  "error_messages": [],
  "abi_extensions": [],
  "variants": [],
  "action_results": [],
  "kv_tables": {}

 

Smart Contract의 WASM 다운로드 방법

$ cleos -u https://eos.genereos.io get code eosio.token -c eosio.token.wast --wasm
code hash: f6a2939074d69fc194d4b7b5a4d2c24e2766046ddeaa58b63ddfd579a0193623
saving wasm to eosio.token.wast

$ ls -l
total 20
-rw-rw-r-- 1 codeql codeql 17637 Sep  4 19:47 eosio.token.wast

 

EOSIO 기반의 Mainnet의 경우 Node 도메인만 변경하여 명령어 사용 시 동일하게 WASM 및 ABI를 다운로드 받을 수 있을 겁니다. 예를 들면 Proton 같이요.

(물론 일부 Mainnet의 작동하지 않을 수 있음)

$ cleos -u https://api.protonnz.com get code proton.wrap
code hash: 576bdf492cd6d9b86d439b6e7ea0b6ea78faacb1fa2e84cc5c7baaf2b3d0021

 

물론 WASM 파일을 어떻게 분석해야 되는 가는 또 다른 문제인 것 같습니다. ㅎㅎ

 

아직은 저도 많이 접해보지 않아서... 기회가 된다면 나중에 포스팅을 이어서 해보도록 하겠습니다,

반응형

댓글