Back to Blog

Solanaエコシステムを確保する(1)— Hello Solana

March 9, 2022
5 min read

1. はじめに

Solanaは、Rust、C++、Cなどのさまざまな言語でプログラム(スマートコントラクト)を開発できる、高性能なパーミッションレスなレイヤー1ブロックチェーンシステムです。Tower BFT(Byzantine Fault Tolerant)の助けを借りて、毎秒数千トランザクションを処理できます。Solanaのコアイノベーションの1つはProof of History(PoH)であり、これはネットワーク内でコンセンサスより前に機能する、グローバルに利用可能でパーミッションレスな時間のソースです。PoHについては、今後さらに詳しく説明します。

2. 私たちのミッション

BlockSecは、「DAppエコシステムの保護」をミッションとするブロックチェーンセキュリティ企業です。そのため、コントラクト監査サービスを提供するだけでなく、コミュニティ全体が安全なスマートコントラクトを作成するための提案も行っています。Solanaの人気、高性能、優れた設計を考慮し、このシリーズではSolana上のRustによるスマートコントラクトのセキュリティに焦点を当てます。

3. Hello Solana

セキュリティの観点からSolanaスマートコントラクトを議論する前に、まずSolanaスマートコントラクトの作成、コンパイル、デプロイ方法を知る必要があります。ここでは、Hello Worldを例として説明します。

3.1 コードレビュー

Solanaでは、スマートコントラクトはプログラムと呼ばれます。Hello Worldプログラムは、クライアントによって呼び出される(プログラムが所有する)ターゲットアカウントの呼び出し回数を記録するカウンタを維持し、その数を出力として表示することを目的としています。

それでは、コントラクト全体を見ていきましょう。

1行目から9行目までは、useキーワードを使用して多くのライブラリをスコープに明示的に取り込みます。

12行目の[derive(BorshSerialize, BorshDeserialize, Debug)]は、13行目から16行目で定義された構造体GreetingAccountに渡されるパラメータのシリアライズとデシリアライズに使用されます。この構造体は、u32型の公開メンバーcounterを含みます。その後、コメントにあるように、19行目がプログラムのエントリーポイントであるprocess_instruction関数をエクスポートします。

process_instruction関数は、3つのパラメータ(program_idaccounts_instruction_data)を受け取ります。program_idはデプロイされたプログラムの公開鍵(アドレス)であり、accountsには挨拶するアカウントが含まれます。_instruction_dataは空であり、使用されません。

Solanaのプログラムとアカウントについてさらに詳しく知りたい場合は、Solanaドキュメントを参照してください。

27行目では、挨拶メッセージが出力されます。30行目から33行目では、アカウントが反復処理され、挨拶する特定のアカウントが抽出されます。その後、アカウントの所有者がチェックされ、プログラムがアカウントに書き込めるようにprogram_idと一致する必要があります。最後に、greeting_accounttry_from_sliceで抽出され、カウンタが1つ増加します。

3.2 プログラムのコンパイル

プログラムをコンパイルするには、以下のコマンドでSolana CLIをインストールする必要があります。

sh -c "$(curl -sSfL https://release.solana.com/v1.9.9/install)"

Solana CLIが正常にインストールされたことを確認するには、以下のコマンドでバージョンを確認します。

solana --version

RustNodeJSも必要であることに注意してください。

プログラムをコンパイルするには、以下のコマンドを使用します。

cargo build-bpf --manifest-path=./src/program-rust/Cargo.toml --bpf-out-dir=dist/program

コンパイルされたプログラムは、--bpf-out-dirで指定されたディレクトリの下に、helloworld.soという名前で生成されます。

3.3 コントラクトのデプロイ

Solanaにコンパイルされたプログラムをデプロイするには、まずクラスタを選択する必要があります。Solanaには、mainnet、testnet、devnet、localnetの4つの異なるクラスタがあります。この投稿では、デモンストレーションのためにdevnetにのみコンパイルされたプログラムをデプロイします。

以下のコマンドを使用してクラスタを指定します。

solana config set --url https://api.devnet.solana.com

その後、デプロイ用のウォレットを生成する必要があります。solana-keygen new --forceはウォレットの生成に役立ちます。詳細については、Solana Docを確認してください。

新しく作成されたアカウントはトランザクション手数料を支払うための残高がないため、以下のコマンドで1 SOLをエアドロップします。

solana airdrop 1 <YourPublicKey> --url https://api.devnet.solana.com

これで、コントラクトをデプロイする準備が整いました。

solana program deploy dist/program/helloworld.so

ユーザーは、Devnet Explorerでプログラムやトランザクションを確認できます。このデモでは、このリンクでデプロイされたプログラムを見つけることができます。

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

Solanaでは、トランザクションを送信するためにスクリプト(クライアントと呼ばれる)を作成することが推奨されます。幸いなことに、Solanaはサンプルコードを提供しています。クライアントを実行するには、まずクライアントの依存関係をインストールする必要があります。

npm install

インストールが完了したら、main.tsファイル内のmain関数を以下のコマンドで実行します。

npm run start

main関数では、クライアントはまずestablishConnection()関数を使用して指定されたクラスタ(Devnet)への接続を確立し、establishPayer関数を使用してトランザクション手数料を支払うペイヤーを確認し、checkProgram関数を使用してプログラムと挨拶するアカウントの存在を検証します。必要なアカウントが存在しない場合は、トランザクションを送信して作成されることに注意してください。私たちのデモンストレーションでは、アカウントはこのトランザクションで作成されました。

すべてが準備完了すると、sayHello関数が呼び出されてターゲットアカウントに挨拶します。トランザクションは1つの命令で構成されます。この命令は、1つのアカウントを含むkeysを受け取ります。アカウントの公開鍵(greetedPubkey)は、挨拶するターゲットアカウントです。このアカウントはストレージに使用され、署名者ではないことに注意してください。この場合、isSigner属性はfalseであり、isWritabletrueです。programIdgreetedPubkeyの所有者であり、デプロイされたコントラクトのアドレスでもあります。dataは空であり、このトランザクションでは使用されないことに注意してください。208行目では、sendAndConfirmTransaction関数が呼び出され、トランザクションがクラスタに送信されます。

詳細なトランザクションは**こちら**で表示できます。

4. 結論

この記事では、Solanaの背景を簡単に紹介し、サンプルプロジェクト(Hello World)を説明しました。Solanaでプログラムをデプロイする方法、およびクライアントを使用してオンチェーンプログラムと対話する方法を学びました。このシリーズでは、今後も一貫してさらに多くの記事を公開していきますので、ぜひブログをフォローしてください。

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

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.