Skip to content

Daanvdplas/ink-_vs_barebonerust

Repository files navigation

Bare Rust vs ink! Smart Contract Benchmark

A side-by-side comparison of two approaches to building Polkadot smart contracts:

  • Bare Rust: Low-level PolkaVM contract with manual ABI encoding and storage management
  • ink!: High-level framework with automatic code generation

Both implementations use the same contract: Mixocracy, a decentralized DJ voting platform with 25 public functions. Obtained from here: https://github.com/lovelaced/mixocracy

Results

See BENCHMARK_REPORT.md for detailed analysis including:

  • Code metrics and binary sizes
  • Gas costs per operation
  • Build times and dependencies
  • When to use each approach

Project Structure

.
├── benchmark_gas.ts              # Gas benchmark script
├── deploy_ink_paseo.ts           # ink! deployment script
├── BENCHMARK_REPORT.md           # Detailed results
└── mixocracy/
    ├── mixocracy-contract/       # Bare Rust implementation
    └── mixocracy-contract-ink/   # ink! implementation

Prerequisites

  • Node.js 18+
  • Rust nightly (for bare rust contract)
  • Pop CLI (for ink! contract)
  • Foundry (for wallet creation)

Running the Benchmark

1. Create and Fund a Wallet

Create a new Ethereum-compatible wallet:

cast wallet new

Save the private key. Convert the address to Polkadot format:

pop convert address <your-ethereum-address>

Fund the converted address on Paseo Asset Hub using the Paseo Faucet or transfer from another account.

2. Install Dependencies

# Root directory
npm install

# Bare rust contract
cd mixocracy/mixocracy-contract
npm install
cd ../..

3. Build the Contracts

Bare Rust: Don't build, the binary has to be used that is provided (couldn't get it to work with rebuilding)

ink!:

cd mixocracy/mixocracy-contract-ink
pop build --release --metadata solidity
cd ../..

4. Deploy Both Contracts

Set your private key:

export PRIVATE_KEY=0x_your_private_key_here

Deploy Bare Rust:

cd mixocracy/mixocracy-contract
npm run deploy:paseo
cd ../..

Deploy ink!:

npx ts-node deploy_ink_paseo.ts

5. Run the Benchmark

PRIVATE_KEY=0x_your_private_key_here npx ts-node benchmark_gas.ts

Results are saved to benchmark_results.json and printed to console.

Network

All benchmarks run on Paseo Asset Hub (testnet):

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages