koba (工場)
Generate deployment transaction data for Stylus contracts.
[!WARNING] This project is still in a very early and experimental phase. It has never been audited nor thoroughly reviewed for security vulnerabilities. Do not use in production.
This project is meant to be temporary. The problem it solves should be fixed by either
cargo-stylusitself or in the Stylus VM. As such, we maintain this on a best-effort basis.
Why?
Deployment transactions in Ethereum are composed of three sections:
- A
prelude- The bytecode prefix whose execution gets triggered by the deployment transaction. - A
runtime- The bytecode of the smart contract stored on-chain. - Constructor arguments - ABI-encoded arguments received by the constructor.
Deployment transactions with an input of only compressed wasm are not yet
supported in Stylus. That is, only the runtime is actual webassembly.
Moreover, the prelude of deployment transactions using cargo-stylus is
hard-coded.
koba allows using a Solidity constructor alongside Stylus contracts, enabling
users to deploy their code in a familiar way.
koba can be used both as a CLI tool or as a library in Rust projects. For a
usage example beyond the section below, check out
OpenZeppelin Contracts for Stylus.
Installation
To install koba on your machine, just run:
cargo install koba
Compiling Solidity code with koba requires solc to be installed and
available through the command line.
You can also use koba as a library by adding it to your project using
cargo add koba.
Usage
You can use the command-line interface in two ways: the generate and the
deploy commands.
koba generate
For a contract like this:
sol_storage!
With a constructor like this:
contract Counter {
uint256 private _number;
constructor() {
_number = 5;
}
}
the following command outputs the transaction data you would need to send to deploy the contract.
You can then use cast for example to deploy and activate the contract, like
this:
# Deploy the contract.
# Activate the contract.
# Interact with the contract
koba deploy
For the same code in the above section, you can instead just run koba deploy
with the appropriate arguments to deploy and activate your Stylus contract in
one go:
Limitations
immutablevariables -kobacurrently does not support Solidity'simmutablevariables, since there is no equivalent mechanism for Stylus.MCOPY- Version0.8.24of Solidity introduced theMCOPYopcode fromEIP-5656. As of 2024-05-28,nitro-testnodedoes not support this opcode.
Why koba
koba means factory in Japanese
-- the factory where a stylus gets assembled.