logo

OpenZeppelin Contracts for Stylus

腐ってやがる。早すぎたんだ。
profile photo
TaniguchiAkira
この記事は Arbitrum Stylusのすゝめ の続きとなります

はじめに

私、言いましたよね。
solidity
OpenZeppelinのRust版とかが出てくるまでは、みんなERC20独自実装になるのかな、COMSAを思い出す。 それまでは品質の担保はお預けかな。でもまぁCairo用のOpenZeppelinもぱっと作ってたし、 いずれRust用のやつも誰かが作るやろ、多分。
というわけで、誰かが早くも作ってました。RustでERC20とか作る時に使うライブラリ。
まだまだ出たばっかりですが、これで品質は担保されていくと思われる。(されるとは言ってない)

今北産業

  • OpenZeppelinのRust版ができた
  • 単体testもできる
  • なんかデプロイできないのでまだ触らなくていい!!

使い方

Arbitrum Stylusのすゝめ で作ったプロジェクトの続きの体で説明する

1. Cargo.tomlの修正

toml
[dependencies] openzeppelin-stylus = "0.1.0" // バージョンは固定化することを推奨 // 最新のものを利用したい場合はこうすることもできる // openzeppelin-stylus = { git = "https://github.com/OpenZeppelin/rust-contracts-stylus" }

2. コントラクト記述

rust
// Allow `cargo stylus export-abi` to generate a main function. #![cfg_attr(not(feature = "export-abi"), no_main)] extern crate alloc; /// Import items from the SDK. The prelude contains common traits and macros. use stylus_sdk::prelude::*; // これが重要 use openzeppelin_stylus::token::erc20::Erc20; sol_storage! { #[entrypoint] struct Erc20Example { #[borrow] Erc20 erc20; } } #[public] #[inherit(Erc20)] impl Erc20Example {}

3. チェック

試しにチェックを走らせると、エラーが出た。
toml
// チェックコマンド cargo stylus check
環境にもよると思うが、コンパイル前のチェックは必須だと思う。
今回はこのチェックでエラーになった。解決策としては
  • wasm32-unknown-unknown の追加
    • なぜか足りなかったらしい
  • openzeppelin-stylusのコード修正
    • Stylus SDK側のグローバルアロケータと重複するからコメントアウトしなきゃダメっぽい
    • panic_handlerも削除する必要あり
  • Cargo.tomlの修正
    • default-featuresをfalseにしたり、、、
でcheckは通った。
version 0.1.0 を舐めてはいけない。ライブラリの修正が必要。
もっといいやり方あるかもしれないけど。
「rustup target add wasm32-unknown-unknown」で解決した手順
openzeppelin-stylusのコード修正(大変)
Cargo.tomlの修正点

3. デプロイ

前回と同様、下記コマンドでデプロイできる、
toml
cargo stylus deploy \ --endpoint='http://localhost:8547' \ --private-key="0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659"
と思いきや、エラーが出た。
toml
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested Building project with Cargo.toml version: 0.1.9 Updating crates.io index error: failed to select a version for `stylus-sdk`. ... required by package `stylus-hello-world v0.1.9 (/source)` versions that meet the requirements `^0.6.0` (locked to 0.6.0) are: 0.6.0 the package `stylus-hello-world` depends on `stylus-sdk`, with features: `no_std` but `stylus-sdk` does not have these features. failed to select a version for `stylus-sdk` which could resolve this conflict cargo build command failed akira@taniguchieinoMacBook-Pro-2 horobi_gengar %
はい、この瞬間に心が折れました。

所感

結論から言うと様子見、まだプロダクトには組み込める品質ではないと判断。
ライブラリの修正が不必要になったらまた教えてくれ。
特に触れなかったが、コンストラクタには「koba(工場)」というライブラリが、testツールには「Motsu(持つ)」と言うライブラリが利用されている。
微妙に発音が間違っている、しかしなぜこんなに日本贔屓なのか。
以前、RPC URLを提供するInfuraの開発者に話を聞いた時、Infuraの元ネタも日本語の「インフラ」で、理由は「響きがいいから」だと言われた。
「かわいい」と同じノリで最先端のライブラリの名前は決められていく。

参考リンク

GitHub - OpenZeppelin/rust-contracts-stylus: A library for secure smart contract development written in Rust
A library for secure smart contract development written in Rust - OpenZeppelin/rust-contracts-stylus
GitHub - OpenZeppelin/rust-contracts-stylus: A library for secure smart contract development written in Rust
rust-contracts-stylus/lib/motsu at main · OpenZeppelin/rust-contracts-stylus
A library for secure smart contract development written in Rust - OpenZeppelin/rust-contracts-stylus
rust-contracts-stylus/lib/motsu at main · OpenZeppelin/rust-contracts-stylus
github.com/OpenZeppelin/koba
rust-contracts-stylus/lib/motsu at main · OpenZeppelin/rust-contracts-stylus
A library for secure smart contract development written in Rust - OpenZeppelin/rust-contracts-stylus
rust-contracts-stylus/lib/motsu at main · OpenZeppelin/rust-contracts-stylus
Related posts
post image
Arbitrum
Rust
contract
WASM
Arbitrum Stylusのすゝめ
〜SolidityHouseの名前はどうなるの?〜
post image
Layer2
zk-Rollup
INTMAX
Mining
INTMAXのマイニングやってみた
人の夢と書いてトークンと読む
post image
Solidityも早く1.0.0出て欲しい
Powered by Notaku