Back to Blog

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

April 29, 2022

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アカウントを渡した場合、すべてのチェックをバイパスすることができます。その理由は、プログラムがアカウントの型をチェックしないためです。プログラムはバイトの配列を受け取り、プログラムで定義されたさまざまな型の構造体に直接デシリアライズします。

さらなるテストのためにテストプログラムをデプロイしました。リンクはこちらで確認できます:https://explorer.solana.com/address/HW3fX9yUKV4zBRuBPotggG7MURscAXSRE5fDMdaia64m?cluster=testnet

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

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

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

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

トランザクションを送信し、そのトランザクションはこちらで確認できます:https://explorer.solana.com/tx/46e9uR4SoPZemkcwZxMFy3nKsBagjPUgA2zob68fiLJnD7oyHpcdDVoeXHEszqG2KAZxReKbQGFdz3oiRePgMjob?cluster=testnet。プログラムは成功を返しました。これは、チェックされていないアカウント型でチェックを正常にバイパスできたことを意味します。

4. まとめ

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

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


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
Tether Freezes $6.76M USDT Linked to Iran's IRGC & Houthi Forces: Why On-Chain Compliance is Now a Geopolitical Battlefield
Security Insights

Tether Freezes $6.76M USDT Linked to Iran's IRGC & Houthi Forces: Why On-Chain Compliance is Now a Geopolitical Battlefield

Looking ahead, targeted freezing events like this $6.76M USDT action will only become more common. On-chain data analysis is improving. Stablecoin issuers are also working closely with regulators. As a result, hidden illicit financial networks will be exposed.

Weekly Web3 Security Incident Roundup | Mar 2 – Mar 8, 2026
Security Insights

Weekly Web3 Security Incident Roundup | Mar 2 – Mar 8, 2026

During the week of March 2 to March 8, 2026, seven blockchain security incidents were reported with total losses of ~$3.25M. The incidents occurred across Base, BNB Chain, and Ethereum, exposing critical vulnerabilities in smart contract business logic, token deflationary mechanics, and asset price manipulation. The primary causes included a double-minting logic flaw during full token deposits that allowed an attacker to exponentially inflate their balances through repeated burn-and-mint cycles, a price manipulation vulnerability in an AMM-based lending market where artificially inflated vault shares created divergent price anchors to incorrectly force healthy positions into liquidation, and a flawed access control implementation relying on trivially spoofed contract interfaces that enabled attackers to bypass authorization to batch-mint and dump arbitrary tokens.

Weekly Web3 Security Incident Roundup | Feb 23 – Mar 1, 2026
Security Insights

Weekly Web3 Security Incident Roundup | Feb 23 – Mar 1, 2026

During the week of February 23 to March 1, 2026, seven blockchain security incidents were reported with total losses of ~$13M. The incidents affected multiple protocols, exposing critical weaknesses in oracle design/configuration, cryptographic verification, and core business logic. The primary drivers included oracle manipulation/misconfiguration that led to the largest loss at YieldBloxDAO (~$10M), a crypto-proof verification flaw that enabled the FOOMCASH (~$2.26M) exploit, and additional token design and logic errors impacting Ploutos, LAXO, STO, HedgePay, and an unknown contract, underscoring the need for rigorous audits and continuous monitoring across all protocol layers.