コンパイラの使い方

コマンドラインコンパイラの使い方

注釈

このセクションは solcjs には適用されません。 たとえコマンドラインモードで使用してもです。

基本的な使い方

Solidityリポジトリのビルドターゲットの1つは、Solidityのコマンドラインコンパイラである solc です。 solc --help を実行すると、すべてのオプションの説明を見ることができます。 コンパイラは、抽象構文木(パースツリー)上の単純なバイナリやアセンブリから、ガス使用量の推定値まで、様々な出力を行うことができます。 単一のファイルをコンパイルしたいだけなら、 solc --bin sourceFile.sol として実行すれば、バイナリを出力します。 solc のより高度な出力を得たい場合は、 solc -o outputDirectory --bin --ast-compact-json --asm sourceFile.sol を使ってすべてを別々のファイルに出力するように指示したほうがよいでしょう。

オプティマイザオプション

コントラクトをデプロイする前に、 solc --optimize --bin sourceFile.sol を使ってコンパイルをする際にオプティマイザを有効にできます。 デフォルトでは、オプティマイザは、コントラクトがそのライフタイム全体で200回呼び出されると仮定して最適化します(より具体的には、各オペコードが約200回実行されると仮定します)。 最初のコントラクトデプロイを安価にし、後の関数実行を高価にしたい場合は、 --optimize-runs=1 を設定してください。 多くのトランザクションが予想され、デプロイコストや出力サイズが高くなっても気にしない場合は、 --optimize-runs を高い数値に設定してください。 このパラメータは以下に影響を与えます(将来変更される可能性があります)。

  • 関数ディスパッチのルーティンにおける二分検索のサイズ

  • 大きな数値や文字列などの定数の保存方法

ベースパスとインポートのリマッピング

コマンドラインコンパイラは、インポートされたファイルをファイルシステムから自動的に読み込みますが、以下のように prefix=path を使って パスのリダイレクト をすることも可能です。

solc github.com/ethereum/dapp-bin/=/usr/local/lib/dapp-bin/ file.sol

これは基本的に、 github.com/ethereum/dapp-bin/ で始まるものを /usr/local/lib/dapp-bin の下で検索するようにコンパイラに指示するものです。

インポートを検索するためにファイルシステムにアクセスする際、 ./または../で始まらないパス--base-path および --include-path オプションで指定されたディレクトリ(ベースパスが指定されていない場合はカレントワーキングディレクトリ)からの相対パスとして扱われます。 また、これらのオプションで追加されたパスの部分は、コントラクトのメタデータには表示されません。

セキュリティ上の理由から、コンパイラは アクセスできるディレクトリに制限 を設けています。 コマンドラインで指定されたソースファイルのディレクトリと、リマッピングのターゲットパスは、ファイルリーダーからのアクセスが自動的に許可されますが、それ以外はデフォルトで拒否されます。 --allow-paths /sample/path,/another/sample/path スイッチで追加のパス(およびそのサブディレクトリ)を許可できます。 --base-path で指定されたパスの中のものは常に許可されます。

上記は、コンパイラがインポートパスをどのように処理するかを簡単に説明したものです。 例を交えた詳細な説明やコーナーケースについては、 パスの解決 のセクションを参照してください。

ライブラリのリンク

コントラクトで ライブラリ を使用している場合、バイトコードに __$53aea86b7d70b31448b230b20ae141a537$__ のような部分文字列が含まれていることに気づくでしょう (このフォーマットは <v0.5.0 では異なっていました) 。 これは、実際のライブラリアドレスのプレースホルダーです。 プレースホルダーは、完全に修飾されたライブラリ名のkeccak256ハッシュの16進数エンコーディングの34文字のプレフィックスです。 また、バイトコードファイルには、プレースホルダーがどのライブラリを表しているかを識別するために、最後に // <placeholder> -> <fq library name> という形式の行が含まれます。 完全に修飾されたライブラリ名は、そのソースファイルのパスとライブラリ名を : で区切ったものであることに注意してください。 solc をリンカーとして使用すると、これらの箇所にライブラリのアドレスを挿入してくれます。

--libraries "file.sol:Math=0x1234567890123456789012345678901234567890 file.sol:Heap=0xabCD567890123456789012345678901234567890" をコマンドに追加して各ライブラリのアドレスを指定するか(セパレータにはカンマまたはスペースを使用)、文字列をファイルに保存して(1行に1ライブラリ)、 --libraries fileName を使って solc を実行するかの2つの方法があります。

注釈

Solidity 0.8.1から、ライブラリとアドレスの間のセパレータとして = を採用することになり、セパレータとしての : は非推奨となりました。 これは将来削除される予定ですが、現在は --libraries "file.sol:Math:0x1234567890123456789012345678901234567890 file.sol:Heap:0xabCD567890123456789012345678901234567890" でも動作します。

solc--standard-json オプション付きで呼び出された場合、標準入力に(以下に説明する)JSONの入力を受け取り、標準出力にJSONの出力を返します。 これは、より複雑な用途、特に自動化された用途に推奨されるインターフェースです。 プロセスは常に「成功」の状態で終了し、エラーがあればJSON出力で報告されます。 オプション --base-path もstandard-jsonモードで処理されます。

solc がオプション --link 付きで呼ばれた場合、すべての入力ファイルは、上記で与えられた __$53aea86b7d70b31448b230b20ae141a537$__ 形式のリンクされていないバイナリ(16進コード)と解釈され、その場でリンクされます(入力が標準入力から読み込まれた場合は、標準出力に書き込まれます)。 この場合、 --libraries 以外のオプションはすべて無視されます( -o も含む)。

警告

生成されたバイトコード上でライブラリを手動でリンクすることは、コントラクトのメタデータが更新されないため、推奨されません。 メタデータにはコンパイル時に指定されたライブラリのリストが含まれており、バイトコードにはメタデータのハッシュが含まれているため、リンクを実行するタイミングによって異なるバイナリが得られることになります。

コントラクトのコンパイル時にライブラリをリンクするようにコンパイラに依頼するには、 solc--libraries オプションを使用するか、コンパイラへの標準JSONインターフェースを使用する場合は libraries キーを使用する必要があります。

注釈

ライブラリのプレースホルダーは、以前はライブラリのハッシュではなく、ライブラリ自体の完全修飾名でした。 この形式は solc --link ではまだサポートされていますが、コンパイラでは出力されなくなりました。 この変更は、完全修飾ライブラリ名の最初の36文字しか使用できないため、ライブラリ間の衝突の可能性を減らすために行われました。

EVMのバージョンをターゲットに設定

コントラクトコードをコンパイルする際に、特定の機能や動作を避けるためにコンパイルするEthereum Virtual Machineのバージョンを指定できます。

警告

EVMのバージョンを間違えてコンパイルすると、間違った動作、おかしな動作、失敗することがあります。 特にプライベートチェーンを実行している場合は、一致するEVMバージョンを使用するようにしてください。

コマンドラインでは、以下のようにEVMのバージョンを選択できます。

solc --evm-version <VERSION> contract.sol

標準JSONインターフェース では、 "settings" フィールドに "evmVersion" キーを使用します。

{
  "sources": {/* ... */},
  "settings": {
    "optimizer": {/* ... */},
    "evmVersion": "<VERSION>"
  }
}

ターゲットオプション

以下は、対象となるEVMのバージョンと、各バージョンで導入されたコンパイラ関連の変更点の一覧です。 各バージョン間の下位互換性は保証されていません。

  • homestead (サポートは終了予定)

    • (最も古いバージョン)

  • tangerineWhistle (サポートは終了予定)

    • 他のアカウントへのアクセスのためのガスコストが増加しました。 ガスの推定とオプティマイザに関係します。

    • 外部からのコールに対しては、デフォルトですべてのガスが送信されますが、従来は一定量を保持する必要がありました。

  • spuriousDragon (サポートは終了予定)

    • exp オペコードのガスコストが増加しました。 ガスの推定とオプティマイザに関係します。

  • byzantium (サポートは終了予定)

    • オペコード returndatacopyreturndatasizestaticcall がアセンブリで利用可能になりました。

    • staticcall オペコードは、ライブラリではないview関数やpure関数を呼び出す際に使用され、関数がEVMレベルでステートを変更することを防ぎます。 つまり、無効な型変換を使用している場合でも適用されます。

    • 関数呼び出しから返された動的データにアクセスすることが可能になりました。

    • revert のオペコードが導入されたことで、 revert() がガスを無駄にしないようになりました。

  • constantinople

    • オペコード create2 , extcodehash , shl , shr , sar がアセンブリで使用可能になりました。

    • シフト演算子が、シフトオペコードを使用するため、より少ないガスで済みます。

  • petersburg

    • コンパイラの動作は constantinople の場合と同じです。

  • istanbul

    • オペコード chainidselfbalance がアセンブリで使用可能になりました。

  • berlin

    • SLOAD*CALLBALANCEEXT*SELFDESTRUCT のガス代が増加しました。 コンパイラーは、このような操作に対してcoldのガスコストを仮定します。 これは、ガスの推定とオプティマイザに関係します。

  • london

    • ブロックのベースフィー( EIP-3198 および EIP-1559 )は、グローバルな block.basefee またはインラインアセンブリで basefee() を介してアクセスできます。

  • paris

    • prevrandao()block.prevrandao を導入し、現在では非推奨となっている block.difficulty のセマンティクスを変更し、インラインアセンブリの difficulty() を禁止しました( EIP-4399 を参照してください)。

  • shanghai

    • push0 の導入により、コードサイズが小さくなり、ガスが節約できるようになりました( EIP-3855 を参照)。

  • cancun

    • ブロックの blob base fee( EIP-7516 および EIP-4844)には、 グローバル変数 block.blobbasefee またはインラインアセンブリの blobbasefee() を通じてアクセスできます。

    • インラインアセンブリにおいて blobhash() が導入されており、 トランザクションに関連付けられた blob の versioned hash を取得するための対応するグローバル関数も追加されています ( EIP-4844 参照)。

    • アセンブリにて mcopy オペコードが使用可能になっています( EIP-5656 参照)。

    • アセンブリにて tstore および tload オペコードが使用可能になっています( EIP-1153 参照)。

  • prague (default)

  • osaka (experimental)

    • このバージョンから、EOF への実験的なコンパイルが可能になりました( EIP-7692 参照)。

コンパイラの入出力JSONの説明

Solidityコンパイラとのインターフェースとして、特に複雑な自動化されたセットアップには、いわゆるJSON-input-outputインターフェースを使用することをお勧めします。 このインターフェースは、コンパイラのすべてのディストリビューションで提供されています。

フィールドは一般的に変更される可能性があり、いくつかの項目はオプションですが(前述のとおり)、後方互換性のある変更のみを行うようにしています。

コンパイラAPIは、JSON形式の入力を期待し、コンパイル結果をJSON形式の出力で出力します。 標準のエラー出力は使用されず、エラーがあった場合でも、常に「成功」の状態で処理が終了します。 エラーは常にJSON出力の一部として報告されます。

以下のサブセクションでは、例を挙げてフォーマットを説明します。 もちろん、コメントは許可されておらず、ここでは説明のためにのみ使用されています。

入力の説明

{
  // 必須: Source code language. Currently supported are "Solidity", "Yul", "SolidityAST" (experimental), "EVMAssembly" (experimental).
  "language": "Solidity",
  // 必須
  "sources":
  {
    // The keys here are the "global" names of the source files, imports can use other files via remappings (see below).
    "myFile.sol":
    {
      // オプション: keccak256 hash of the source file
      // It is used to verify the retrieved content if imported via URLs.
      "keccak256": "0x123...",
      // 必須(「content」が使用されている場合を除く): ソースファイルのURL。
      // URL(s) should be imported in this order and the result checked against the keccak256 hash (if available).
      // If the hash doesn't match or none of the URL(s) result in success, an error should be raised.
      // Using the commandline interface only filesystem paths are supported.
      // With the JavaScript interface the URL will be passed to the user-supplied read callback, so any URL supported by the callback can be used.
      "urls":
      [
        "bzzr://56ab...",
        "ipfs://Qma...",
        "/tmp/path/to/file.sol"
        // If files are used, their directories should be added to the command-line via
        // `--allow-paths <path>`.
      ]
    },
    "settable":
    {
      // Optional: keccak256 hash of the source file
      "keccak256": "0x234...",
      // Required (unless "urls" is used): literal contents of the source file
      "content": "contract settable is owned { uint256 private x = 0; function set(uint256 _x) public { if (msg.sender == owner) x = _x; } }"
    },
    "myFile.sol_json.ast":
    {
      // If language is set to "SolidityAST", an AST needs to be supplied under the "ast" key
      // and there can be only one source file present.
      // The format is the same as used by the `ast` output.
      // Note that importing ASTs is experimental and in particular that:
      // - importing invalid ASTs can produce undefined results and
      // - no proper error reporting is available on invalid ASTs.
      // Furthermore, note that the AST import only consumes the fields of the AST as
      // produced by the compiler in "stopAfter": "parsing" mode and then re-performs
      // analysis, so any analysis-based annotations of the AST are ignored upon import.
      "ast": { ... }
    },
    "myFile_evm.json":
    {
      // If language is set to "EVMAssembly", an EVM Assembly JSON object needs to be supplied
      // under the "assemblyJson" key and there can be only one source file present.
      // The format is the same as used by the `evm.legacyAssembly` output or `--asm-json`
      // output on the command line.
      // Note that importing EVM assembly is experimental.
      "assemblyJson":
      {
        ".code": [ ... ],
        ".data": { ... }, // optional
        "sourceList": [ ... ] // optional (if no `source` node was defined in any `.code` object)
      }
    }
  },
  // オプション
  "settings":
  {
    // オプション: Stop compilation after the given stage. Currently only "parsing" is valid here
    "stopAfter": "parsing",
    // オプション: List of remappings
    "remappings": [ ":g=/dir" ],
    // オプション: Optimizer settings
    "optimizer": {
      // Turn on the optimizer. Optional. Default: false.
      // NOTE: The state of the optimizer is fully determined by the 'details' dict and this setting
      // only affects its defaults - when enabled, all components default to being enabled.
      // The opposite is not true - there are several components that always default to being
      // enabled an can only be explicitly disabled via 'details'.
      // WARNING: Before version 0.8.6 omitting this setting was not equivalent to setting
      // it to false and would result in all components being disabled instead.
      // WARNING: Enabling optimizations for EVMAssembly input is allowed but not necessary under normal
      // circumstances. It forces the opcode-based optimizer to run again and can produce bytecode that
      // is not reproducible from metadata.
      "enabled": true,
      // Optimize for how many times you intend to run the code. Optional. Default: 200.
      // Lower values will optimize more for initial deployment cost, higher
      // values will optimize more for high-frequency usage.
      "runs": 200,
      // State of all optimizer components. Optional.
      // Default values are determined by whether the optimizer is enabled or not.
      // Note that the 'enabled' setting only affects the defaults here and has no effect when
      // all values are provided explicitly.
      "details": {
        // Peephole optimizer (opcode-based). Optional. Default: true.
        // Default for EVMAssembly input: false when optimization is not enabled.
        // NOTE: Always runs (even with optimization disabled) except for EVMAssembly input or when explicitly turned off here.
        "peephole": true,
        // Inliner (opcode-based). Optional. Default: true when optimization is enabled.
        "inliner": false,
        // Unused JUMPDEST remover (opcode-based). Optional. Default: true.
        // Default for EVMAssembly input: false when optimization is not enabled.
        // NOTE: Always runs (even with optimization disabled) except for EVMAssembly input or when explicitly turned off here.
        "jumpdestRemover": true,
        // Literal reordering (codegen-based). Optional. Default: true when optimization is enabled.
        // Moves literals to the right of commutative binary operators during code generation, helping exploit associativity.
        "orderLiterals": false,
        // Block deduplicator (opcode-based). Optional. Default: true when optimization is enabled.
        // Unifies assembly code blocks that share content.
        "deduplicate": false,
        // Common subexpression elimination (opcode-based). Optional. Default: true when optimization is enabled.
        // This is the most complicated step but can also provide the largest gain.
        "cse": false,
        // Constant optimizer (opcode-based). Optional. Default: true when optimization is enabled.
        // Tries to find better representations of literal numbers and strings, that satisfy the
        // size/cost trade-off determined by the 'runs' setting.
        "constantOptimizer": false,
        // Unchecked loop increment (codegen-based). Optional. Default: true.
        // Use unchecked arithmetic when incrementing the counter of 'for' loops under certain circumstances.
        // NOTE: Always runs (even with optimization disabled) unless explicitly turned off here.
        "simpleCounterForLoopUncheckedIncrement": true,
        // Yul optimizer. Optional. Default: true when optimization is enabled.
        // Used to optimize the IR produced by the Yul IR-based pipeline as well as inline assembly
        // and utility Yul code generated by the compiler.
        // NOTE: Before Solidity 0.6.0 the default was false.
        "yul": false,
        // Tuning options for the Yul optimizer. Optional.
        "yulDetails": {
          // Improve allocation of stack slots for variables, can free up stack slots early.
          // Optional. Default: true if Yul optimizer is enabled.
          "stackAllocation": true,
          // Optimization step sequence.
          // The general form of the value is "<main sequence>:<cleanup sequence>".
          // The setting is optional and when omitted, default values are used for both sequences.
          // If the value does not contain the ':' delimiter, it is interpreted as the main
          // sequence and the default is used for the cleanup sequence.
          // To make one of the sequences empty, the delimiter must be present at the first or last position.
          // In particular if the whole value consists only of the delimiter, both sequences are empty.
          // Note that there are several hard-coded steps that always run, even when both sequences are empty.
          // For more information see "The Optimizer > Selecting Optimizations".
          "optimizerSteps": "dhfoDgvulfnTUtnIf..."
        }
      }
    },
    // Version of the EVM to compile for (optional).
    // Affects type checking and code generation. Can be homestead,
    // tangerineWhistle, spuriousDragon, byzantium, constantinople,
    // petersburg, istanbul, berlin, london, paris, shanghai, cancun, prague (default) or osaka (experimental).
    "evmVersion": "prague",
    // EVM Object Format version to compile for (optional, experimental).
    // Currently the only valid value is 1. If not specified, legacy non-EOF bytecode will be generated.
    "eofVersion": null,
    // Optional: Change compilation pipeline to go through the Yul intermediate representation.
    // This is false by default.
    "viaIR": true,
    // オプション: Debugging settings
    "debug": {
      // How to treat revert (and require) reason strings. Settings are
      // "default", "strip", "debug" and "verboseDebug".
      // "default" does not inject compiler-generated revert strings and keeps user-supplied ones.
      // "strip" removes all revert strings (if possible, i.e. if literals are used) keeping side-effects
      // "debug" injects strings for compiler-generated internal reverts, implemented for ABI encoders V1 and V2 for now.
      // "verboseDebug" even appends further information to user-supplied revert strings (not yet implemented)
      "revertStrings": "default",
      // オプション: How much extra debug information to include in comments in the produced EVM
      // assembly and Yul code. Available components are:
      // - `location`: Annotations of the form `@src <index>:<start>:<end>` indicating the
      //    location of the corresponding element in the original Solidity file, where:
      //     - `<index>` is the file index matching the `@use-src` annotation,
      //     - `<start>` is the index of the first byte at that location,
      //     - `<end>` is the index of the first byte after that location.
      // - `snippet`: A single-line code snippet from the location indicated by `@src`.
      //     The snippet is quoted and follows the corresponding `@src` annotation.
      // - `*`: Wildcard value that can be used to request everything.
      "debugInfo": ["location", "snippet"]
    },
    // メタデータの設定(オプション)
    "metadata": {
      // The CBOR metadata is appended at the end of the bytecode by default.
      // Setting this to false omits the metadata from the runtime and deploy time code.
      "appendCBOR": true,
      // Use only literal content and not URLs (false by default)
      "useLiteralContent": true,
      // Use the given hash method for the metadata hash that is appended to the bytecode.
      // The metadata hash can be removed from the bytecode via option "none".
      // The other options are "ipfs" and "bzzr1".
      // If the option is omitted, "ipfs" is used by default.
      "bytecodeHash": "ipfs"
    },
    // Addresses of the libraries. If not all libraries are given here,
    // it can result in unlinked objects whose output data is different.
    "libraries": {
      // The top level key is the name of the source file where the library is used.
      // If remappings are used, this source file should match the global path
      // after remappings were applied.
      // If this key is an empty string, that refers to a global level.
      "myFile.sol": {
        "MyLib": "0x123123..."
      }
    },
    // The following can be used to select desired outputs based
    // on file and contract names.
    // If this field is omitted, then the compiler loads and does type checking,
    // but will not generate any outputs apart from errors.
    // The first level key is the file name and the second level key is the contract name.
    // An empty contract name is used for outputs that are not tied to a contract
    // but to the whole source file like the AST.
    // A star as contract name refers to all contracts in the file.
    // Similarly, a star as a file name matches all files.
    // To select all outputs the compiler can possibly generate, with the exclusion of
    // Yul intermediate representation outputs, use
    // "outputSelection: { "*": { "*": [ "*" ], "": [ "*" ] } }"
    // but note that this might slow down the compilation process needlessly.
    //
    // The available output types are as follows:
    //
    // File level (needs empty string as contract name):
    //   ast - AST of all source files
    //
    // Contract level (needs the contract name or "*"):
    //   abi - ABI
    //   devdoc - Developer documentation (natspec)
    //   userdoc - User documentation (natspec)
    //   metadata - Metadata
    //   ir - Yul intermediate representation of the code before optimization
    //   irAst - AST of Yul intermediate representation of the code before optimization
    //   irOptimized - Intermediate representation after optimization
    //   irOptimizedAst - AST of intermediate representation after optimization
    //   storageLayout - Slots, offsets and types of the contract's state variables in storage.
    //   transientStorageLayout - Slots, offsets and types of the contract's state variables in transient storage.
    //   evm.assembly - New assembly format
    //   evm.legacyAssembly - Old-style assembly format in JSON
    //   evm.bytecode.functionDebugData - Debugging information at function level
    //   evm.bytecode.object - Bytecode object
    //   evm.bytecode.opcodes - Opcodes list
    //   evm.bytecode.sourceMap - Source mapping (useful for debugging)
    //   evm.bytecode.linkReferences - Link references (if unlinked object)
    //   evm.bytecode.generatedSources - Sources generated by the compiler
    //   evm.deployedBytecode* - Deployed bytecode (has all the options that evm.bytecode has)
    //   evm.deployedBytecode.immutableReferences - Map from AST ids to bytecode ranges that reference immutables
    //   evm.methodIdentifiers - The list of function hashes
    //   evm.gasEstimates - Function gas estimates
    //
    // Note that using `evm`, `evm.bytecode`, etc. will select every
    // target part of that output. Additionally, `*` can be used as a wildcard to request everything.
    //
    "outputSelection": {
      "*": {
        "*": [
          "metadata", "evm.bytecode" // Enable the metadata and bytecode outputs of every single contract.
          , "evm.bytecode.sourceMap" // Enable the source map output of every single contract.
        ],
        "": [
          "ast" // Enable the AST output of every single file.
        ]
      },
      // Enable the abi and opcodes output of MyContract defined in file def.
      "def": {
        "MyContract": [ "abi", "evm.bytecode.opcodes" ]
      }
    },
    // The modelChecker object is experimental and subject to changes.
    "modelChecker":
    {
      // Chose which contracts should be analyzed as the deployed one.
      "contracts":
      {
        "source1.sol": ["contract1"],
        "source2.sol": ["contract2", "contract3"]
      },
      // Choose how division and modulo operations should be encoded.
      // When using `false` they are replaced by multiplication with slack
      // variables. This is the default.
      // Using `true` here is recommended if you are using the CHC engine
      // and not using Spacer as the Horn solver (using Eldarica, for example).
      // See the Formal Verification section for a more detailed explanation of this option.
      "divModNoSlacks": false,
      // Choose which model checker engine to use: all (default), bmc, chc, none.
      "engine": "chc",
      // Choose whether external calls should be considered trusted in case the
      // code of the called function is available at compile-time.
      // For details see the SMTChecker section.
      "extCalls": "trusted",
      // Choose which types of invariants should be reported to the user: contract, reentrancy.
      "invariants": ["contract", "reentrancy"],
      // Choose whether to output all proved targets. The default is `false`.
      "showProvedSafe": true,
      // Choose whether to output all unproved targets. The default is `false`.
      "showUnproved": true,
      // Choose whether to output all unsupported language features. The default is `false`.
      "showUnsupported": true,
      // Choose which solvers should be used, if available.
      // See the Formal Verification section for the solvers description.
      "solvers": ["cvc5", "smtlib2", "z3"],
      // Choose which targets should be checked: constantCondition,
      // underflow, overflow, divByZero, balance, assert, popEmptyArray, outOfBounds.
      // If the option is not given all targets are checked by default,
      // except underflow/overflow for Solidity >=0.8.7.
      // See the Formal Verification section for the targets description.
      "targets": ["underflow", "overflow", "assert"],
      // Timeout for each SMT query in milliseconds.
      // If this option is not given, the SMTChecker will use a deterministic
      // resource limit by default.
      // A given timeout of 0 means no resource/time restrictions for any query.
      "timeout": 20000
    }
  }
}

出力の説明

{
  // オプション: not present if no errors/warnings/infos were encountered
  "errors": [
    {
      // オプション: Location within the source file.
      "sourceLocation": {
        "file": "sourceFile.sol",
        "start": 0,
        "end": 100
      },
      // オプション: Further locations (e.g. places of conflicting declarations)
      "secondarySourceLocations": [
        {
          "file": "sourceFile.sol",
          "start": 64,
          "end": 92,
          "message": "Other declaration is here:"
        }
      ],
      // 必須: Error type, such as "TypeError", "InternalCompilerError", "Exception", etc.
      // See below for complete list of types.
      "type": "TypeError",
      // 必須: Component where the error originated, such as "general" etc.
      "component": "general",
      // Mandatory ("error", "warning" or "info", but please note that this may be extended in the future)
      "severity": "error",
      // オプション: unique code for the cause of the error
      "errorCode": "3141",
      // Mandatory
      "message": "Invalid keyword",
      // オプション: the message formatted with source location
      "formattedMessage": "sourceFile.sol:100: Invalid keyword"
    }
  ],
  // This contains the file-level outputs.
  // It can be limited/filtered by the outputSelection settings.
  "sources": {
    "sourceFile.sol": {
      // Identifier of the source (used in source maps)
      "id": 1,
      // The AST object
      "ast": {}
    }
  },
  // This contains the contract-level outputs.
  // It can be limited/filtered by the outputSelection settings.
  "contracts": {
    "sourceFile.sol": {
      // If the language used has no contract names, this field should equal to an empty string.
      "ContractName": {
        // The Ethereum Contract ABI. If empty, it is represented as an empty array.
        // See https://docs.soliditylang.org/en/develop/abi-spec.html
        "abi": [],
        // See the Metadata Output documentation (serialised JSON string)
        "metadata": "{/* ... */}",
        // User documentation (natspec)
        "userdoc": {},
        // Developer documentation (natspec)
        "devdoc": {},
        // Intermediate representation before optimization (string)
        "ir": "",
        // AST of intermediate representation before optimization
        "irAst":  {/* ... */},
        // Intermediate representation after optimization (string)
        "irOptimized": "",
        // AST of intermediate representation after optimization
        "irOptimizedAst": {/* ... */},
        // See the Storage Layout documentation.
        "storageLayout": {"storage": [/* ... */], "types": {/* ... */} },
        // See the Storage Layout documentation.
        "transientStorageLayout": {"storage": [/* ... */], "types": {/* ... */} },
        // EVM-related outputs
        "evm": {
          // Assembly (string)
          "assembly": "",
          // Old-style assembly (object)
          "legacyAssembly": {},
          // Bytecode and related details.
          "bytecode": {
            // Debugging data at the level of functions.
            "functionDebugData": {
              // Now follows a set of functions including compiler-internal and
              // user-defined function. The set does not have to be complete.
              "@mint_13": { // Internal name of the function
                "entryPoint": 128, // Byte offset into the bytecode where the function starts (optional)
                "id": 13, // AST ID of the function definition or null for compiler-internal functions (optional)
                "parameterSlots": 2, // Number of EVM stack slots for the function parameters (optional)
                "returnSlots": 1 // Number of EVM stack slots for the return values (optional)
              }
            },
            // The bytecode as a hex string.
            "object": "00fe",
            // Opcodes list (string)
            "opcodes": "",
            // The source mapping as a string. See the source mapping definition.
            "sourceMap": "",
            // Array of sources generated by the compiler. Currently only
            // contains a single Yul file.
            "generatedSources": [{
              // Yul AST
              "ast": {/* ... */},
              // Source file in its text form (may contain comments)
              "contents":"{ function abi_decode(start, end) -> data { data := calldataload(start) } }",
              // Source file ID, used for source references, same "namespace" as the Solidity source files
              "id": 2,
              "language": "Yul",
              "name": "#utility.yul"
            }],
            // If given, this is an unlinked object.
            "linkReferences": {
              "libraryFile.sol": {
                // Byte offsets into the bytecode.
                // Linking replaces the 20 bytes located there.
                "Library1": [
                  { "start": 0, "length": 20 },
                  { "start": 200, "length": 20 }
                ]
              }
            }
          },
          "deployedBytecode": {
            /* ..., */ // The same layout as above.
            "immutableReferences": {
              // There are two references to the immutable with AST ID 3, both 32 bytes long. One is
              // at bytecode offset 42, the other at bytecode offset 80.
              "3": [{ "start": 42, "length": 32 }, { "start": 80, "length": 32 }]
            }
          },
          // The list of function hashes
          "methodIdentifiers": {
            "delegate(address)": "5c19a95c"
          },
          // Function gas estimates
          "gasEstimates": {
            "creation": {
              "codeDepositCost": "420000",
              "executionCost": "infinite",
              "totalCost": "infinite"
            },
            "external": {
              "delegate(address)": "25000"
            },
            "internal": {
              "heavyLifting()": "infinite"
            }
          }
        }
      }
    }
  }
}

エラータイプ

  1. JSONError: JSON入力が要求されたフォーマットに適合していません。 例: 入力がJSONオブジェクトでない、言語がサポートされていない、など。

  1. IOError: 解決できないURLや提供されたソースのハッシュの不一致など、IOおよびインポート処理のエラーです。

  1. ParserError: ソースコードが言語ルールに準拠していません。

  1. DocstringParsingError: コメントブロック内のNatSpecタグが解析できません。

  1. SyntaxError: for ループの外で continue が使われているなど、構文上のエラーです。

  1. DeclarationError: 無効な、解決不可能な、または衝突した識別子名があります。 例: Identifier not found

  1. TypeError: 無効な型変換、無効な代入など、型システム内のエラーです。

  1. UnimplementedFeatureError: この機能はコンパイラではサポートされていませんが、将来のバージョンではサポートされる予定です。

  1. InternalCompilerError: コンパイラの内部バグが発生しました。

  1. Exception: コンパイル時に不明な障害が発生しました - これはイシューとして報告すべきです。

  1. CompilerError: コンパイラースタックの無効な使用 - これはイシューとして報告すべきです。

  1. FatalError: 致命的なエラーが正しく処理されていない - これはイシューとして報告すべきです。

  1. YulException: Yulコード生成時のエラー - これはイシューとして報告すべきです。

  1. Warning: 警告。コンパイルは停止しなかったが、できれば対処すべきです。

  1. Info: コンパイラが、ユーザーが役に立つかもしれないと考えている情報です。 しかし、危険ではないので、必ず対処する必要はありません。