Skip to content

renegade-fi/renegade-contracts

Repository files navigation

Renegade Logo Renegade Logo

This repository contains the Arbitrum Stylus code for Renegade's settlement layer. This includes managing the system-global state, verifying Plonk proofs, and emitting events that are consumed by the p2p network.

Please refer to our whitepaper and docs for an introduction the Renegade protocol as a whole, and see here for a high-level specification of the contracts' functionality.

Contract Development Setup

Given we are using Stylus, our contracts are written in Rust, and as such we use a combination of the Rust toolchain and a local Arbitrum Nitro devnet for development.

To set up your machine for Renegade contract development:

Clone the repo

git clone https://github.com/renegade-fi/renegade-contracts

Install Rust toolchain

Make sure you have Rust toolchain installed, using e.g. rustup.

You'll also need to have the nightly toolchain, the Rust standard library source, and the wasm32-unknown-unknown target (since Stylus contracts are compiled to WASM):

rustup toolchain install nightly
rustup component add rust-src --toolchain nightly
rustup target add wasm32-unknown-unknown

Install the Stylus CLI

You'll need the Stylus CLI to deploy the Renegade contracts for the integrationt tests:

RUSTFLAGS="-C link-args=-rdynamic" cargo install --force cargo-stylus

Install wasm-opt

We use wasm-opt to optimize the compiled WASM binaries of our contracts. Install it by running:

cargo install wasm-opt --locked

Set up the Arbitrum Nitro devnet

Our integration tests require a Stylus-compatible network to be accessible. The simplest way to do this is to run a devnet locally.

Follow the instructions here to set up a local Arbitrum Nitro devnet capable of supporting Stylus contracts.

Running unit tests

Some of our functionality, for example the Plonk verifier, is defined agnostically of running in the Stylus VM (this is not the case for other functionality, e.g. the Merkle tree, which depends on accessing VM state). For such functionality, we have pure-Rust unit tests, which can be invoked using cargo:

# Unit-tests common utilities used both in the Stylus contracts and auxiliary tooling
cargo test -p contracts-common

# Unit-tests core contract logic defined agnostically of the Stylus VM
cargo test -p contracts-core

Note: since the contracts-stylus crate is intended only to be compiled to WASM that runs in the Stylus VM, running a simple cargo test at the workspace root will error when it attempts to compile the contracts-stylus crate (by default targeting the native maching architecture)

Running integration tests

Running the devnet

Our integration tests run against deployed Stylus contracts. You'll first need to run a local Arbitrum Nitro devnet, you can follow the instructions here to do so.

Note: It may take some time for the devnet to finish its setup if it's being initialized.

Deploying the contracts

Next, you'll need to deploy our contracts to it. This can be done by running the scripts defined in our scripts crate.

You can get an overview of the scripts CLI functionality by running:

cargo run -p scripts -- -h

For interacting with the devnet, you can define the following shell variables:

# The private key of the predeployed, prefunded dev account on the devnet
PRIV_KEY=0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659

# The URL at which the devnet RPC endpoint is accessible by default
RPC_URL=http://localhost:8547

# The path at which deployed contract addresses will be saved.
# This can really be whatever you want, but `deployments.*.json` is conveniently git-ignored
DEPLOYMENTS_PATH=deployments.devnet.json

Then, you can deploy all of the contracts used in the integration tests by running:

cargo run -p scripts -- \
  -p $PRIV_KEY \
  -r $RPC_URL \
  -d $DEPLOYMENTS_PATH \
  deploy-test-contracts \
  -o 0x3f1Eae7D46d88F08fc2F8ed27FCb2AB183EB2d0E \
  -v contracts-stylus/vkeys/test

Note: The address 0x3f1Eae7D46d88F08fc2F8ed27FCb2AB183EB2d0E is the address associated with the predeployed dev account, whose private key we've been using.

Be sure to use contracts-stylus/vkeys/test as the argument for the -v flag, indicating where the verification keys should be stored, as the verification keys contract expects to find them at this path.

Running the tests

You can get an overview of the integration testing suite by running:

cargo run -p integration -- -h

You can run the entire integration testing suite using:

cargo run -p integration -- -d $DEPLOYMENTS_PATH