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

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

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
Weekly Web3 Security Incident Roundup | Feb 9 – Feb 15, 2026

Weekly Web3 Security Incident Roundup | Feb 9 – Feb 15, 2026

During the week of February 9 to February 15, 2026, three blockchain security incidents were reported with total losses of ~$657K. All incidents occurred on the BNB Smart Chain and involved flawed business logic in DeFi token contracts. The primary causes included an unchecked balance withdrawal from an intermediary contract that allowed donation-based inflation of a liquidity addition targeted by a sandwich attack, a post-swap deflationary clawback that returned sold tokens to the caller while draining pool reserves to create a repeatable price-manipulation primitive, and a token transfer override that burned tokens directly from a Uniswap V2 pair's balance and force-synced reserves within the same transaction to artificially inflate the token price.

Top 10 "Awesome" Security Incidents in 2025

Top 10 "Awesome" Security Incidents in 2025

To help the community learn from what happened, BlockSec selected ten incidents that stood out most this year. These cases were chosen not only for the scale of loss, but also for the distinct techniques involved, the unexpected twists in execution, and the new or underexplored attack surfaces they revealed.

#10 Panoptic Incident: XOR Linearity Breaks the Position Fingerprint Scheme

#10 Panoptic Incident: XOR Linearity Breaks the Position Fingerprint Scheme

On August 29, 2025, Panoptic disclosed a Cantina bounty finding and confirmed that, with support from Cantina and Seal911, it executed a rescue operation on August 25 to secure roughly $400K in funds. The issue stemmed from a flaw in Panoptic’s position fingerprint calculation algorithm, which could have enabled incorrect position identification and downstream fund risk.