Back to Blog

Solanaエコシステムの保護 (7) — 型の混同

April 29, 2022
4 min read

0. レビュー

1. 概要

前回のブログでは、一般的なマルチシグの実装について紹介しました。本稿では、もう一つのセキュリティ問題である「型推論」について議論します。

2. デシリアライゼーション/シリアライゼーション

Solanaでは、プログラムの状態はアカウントに保存されます。型推論の問題は、アカウントのデシリアライゼーション/シリアライゼーション中に発生します。プログラムのロジックは通常、データ構造に依存します。しかし、プログラムはデシリアライゼーション/シリアライゼーションプロセス中にアカウントの型を適切にチェックしない場合があります。これは攻撃者によって悪用され、予期せぬ損失につながる可能性があります。

3. コードレビュー(型推論)

以下では、単純なプログラムで型推論の問題を説明します。テストコードはこちらで見つけることができます。

テストプログラムでは、UserMetadataという2つのデータ構造を実装しています。どちらも別のアカウントの公開鍵を記録しています。

プログラムには3つの異なる命令があります。InitializeUser命令は、Userアカウントを作成し、承認済みアカウント(authority)を設定するように設計されています。同様に、InitializeMeta命令は、MetaDataアカウントを作成し、通常のアカウント(account)を設定するために呼び出されます。Test命令は、攻撃者がプログラムの検証ロジックをバイパスし、制御されたMetaDataで攻撃を実行できることを示しています。

Test()命令を詳しく見てみましょう。プログラムは、渡されたUserアカウントの所有者がプログラム自体であることを保証します(86行目〜89行目)。デシリアライゼーション後(92行目)、プログラムは渡されたauthorityアカウントの公開鍵とUserアカウントに保存されている公開鍵を比較します。それらが等しくない場合、プログラムはロールバックします(93行目〜96行目)。最後のチェックは、authorityアカウントがトランザクションに署名したことを確認することです。しかし、攻撃者が制御されたMetadataアカウントを渡した場合、すべてのチェックはバイパスされる可能性があります。その理由は、プログラムがアカウントの型をチェックしないためです。プログラムはバイト配列を受け取り、プログラムに定義されたさまざまな型の構造体に直接デシリアライズします。

さらなるテストのためにテストプログラムをデプロイしました。リンクはこちらで見つけることができます。

3.1 トランザクションの送信

プログラムをデプロイした後、プログラムで提供されている3つの命令を順に呼び出すスクリプトを作成しました。

まず、InitializeUserInitializeMetaを呼び出します。Metadataアカウントに保存されているaccountアカウントとして、私たち自身の公開鍵を設定することに注意してください。

test()関数では、MetadataアカウントをUserアカウントとして、私たち自身の(検証済みの)アカウントをauthority_infoとして渡します(347行目〜348行目)。プログラムはMetadataUser構造体でデシリアライズし、すべてのチェックはバイパスされます。

トランザクションを送信した結果はこちらで見ることができます。プログラムは成功を返しました。これは、チェックされていないアカウント型でチェックを正常にバイパスできたことを意味します。

4. まとめ

本稿では、Solanaにおける型推論の問題を紹介しました。この問題を回避する方法は数多くあります。例えば、構造体にアカウントの型を記録する属性を追加し、プログラムは渡されたアカウントの読み書きを行う前に必ず型属性をチェックするようにすることができます。引き続き、今後の投稿でさらに共有していきます。

このシリーズの他の記事を読む:


BlockSecについて

BlockSecは、世界的に著名なセキュリティ専門家グループによって2021年に設立された、先駆的なブロックチェーンセキュリティ企業です。同社は、進化するWeb3の世界のセキュリティと使いやすさを向上させ、その大規模な採用を促進することに専念しています。この目的のために、BlockSecはスマートコントラクトおよびEVMチェーンのセキュリティ監査サービス、セキュリティ開発と脅威のプロアクティブなブロックのためのPhalconプラットフォーム、資金追跡と調査のためのMetaSleuthプラットフォーム、そしてWeb3ビルダーが仮想通貨の世界を効率的にサーフィンするためのMetaSuites拡張機能を提供しています。

現在までに、同社はMetaMask、Uniswap Foundation、Compound、Forta、PancakeSwapなど300社を超える著名なクライアントにサービスを提供しており、Matrix Partners、Vitalbridge Capital、Fenbushi Capitalなどの著名な投資家から2回の資金調達ラウンドで数千万米ドルを獲得しています。

公式ウェブサイト:https://blocksec.com/

公式Twitterアカウント:https://twitter.com/BlockSecTeam

Sign up for the latest updates
The Decentralization Dilemma: Cascading Risk and Emergency Power in the KelpDAO Crisis
Security Insights

The Decentralization Dilemma: Cascading Risk and Emergency Power in the KelpDAO Crisis

This BlockSec deep-dive analyzes the KelpDAO $290M rsETH cross-chain bridge exploit (April 18, 2026), attributed to the Lazarus Group, tracing a causal chain across three layers: how a single-point DVN dependency enabled the attack, how DeFi composability cascaded the damage through Aave V3 lending markets to freeze WETH liquidity exceeding $6.7B across Ethereum, Arbitrum, Base, Mantle, and Linea, and how the crisis forced decentralized governance to exercise centralized emergency powers. The article examines three parameters that shaped the cascade's severity (LTV, pool depth, and cross-chain deployment count) and provides an exclusive technical breakdown of Arbitrum Security Council's forced state transition, an atomic contract upgrade that moved 30,766 ETH without the holder's signature.

Weekly Web3 Security Incident Roundup | Apr 13 – Apr 19, 2026
Security Insights

Weekly Web3 Security Incident Roundup | Apr 13 – Apr 19, 2026

This BlockSec weekly security report covers four attack incidents detected between April 13 and April 19, 2026, across multiple chains such as Ethereum, Unichain, Arbitrum, and NEAR, with total estimated losses of approximately $310M. The highlighted incident is the $290M KelpDAO rsETH bridge exploit, where an attacker poisoned the RPC infrastructure of the sole LayerZero DVN to fabricate a cross-chain message, triggering a cascading WETH freeze across five chains and an Arbitrum Security Council forced state transition that raises questions about the actual trust boundaries of decentralized systems. Other incidents include a $242K MMR proof forgery on Hyperbridge, a $1.5M signed integer abuse on Dango, and an $18.4M circular swap path exploit on Rhea Finance's Burrowland protocol.

Weekly Web3 Security Incident Roundup | Apr 6 – Apr 12, 2026
Security Insights

Weekly Web3 Security Incident Roundup | Apr 6 – Apr 12, 2026

This BlockSec weekly security report covers four DeFi attack incidents detected between April 6 and April 12, 2026, across Linea, BNB Chain, Arbitrum, Optimism, Avalanche, and Base, with total estimated losses of approximately $928.6K. Notable incidents include a $517K approval-related exploit where a user mistakenly approved a permissionless SquidMulticall contract enabling arbitrary external calls, a $193K business logic flaw in the HB token's reward-settlement logic that allowed direct AMM reserve manipulation, a $165.6K exploit in Denaria's perpetual DEX caused by a rounding asymmetry compounded with an unsafe cast, and a $53K access control issue in XBITVault caused by an initialization-dependent check that failed open. The report provides detailed vulnerability analysis and attack transaction breakdowns for each incident.