Warp Your Way To StarkNet

Greg Vardy
Nethermind.eth
4 min readAug 17, 2021

--

by Greg Vardy (0xGreg_)

Thanks to Eli Ben-Sasson, Uri Kolodny, Tomasz Stanczak and Antonio Sabado for reviewing.

Warp Your Way To StarkNet

A little over a month ago, the Nubia team at Nethermind began work on Warp, an EVM to Cairo transpiler. We’ve just released a demo of transpiling an ERC20 Solidity contract to Cairo and deploying it to StarkNet. In this blog, I’ll explain what StarkNet & Warp are and why they’re essential ingredients in helping Ethereum scale. I’ll also discuss our roadmap and plans for the Warp transpiler.

Warp & StarkNet

StarkNet is a decentralized, permissionless STARK-powered L2 ZK-Rollup that supports general computation over Ethereum. This combination of features is unique. You might call it the ‘Holy Trinity’ of L2 Rollup features. Having smart contracts with arbitrary logic and composability is no small feat for a ZK-Rollup, and Cairo is crucial to this magic. Cairo is StarkNet’s native smart contract language, and I’ve described what makes it unique here. Cairo is great, but we also understand that many protocols and developers have invested a lot of time/money into auditing/developing their current Solidity/Vyper codebases. Warp exists to bulldoze the wall standing between you and having your DApp/protocol deployed on an L2 that would provide your users with a low fee, fast finality, and far superior experience.

Although still in early development, Warp will allow you to take your battle-tested, audited Ethereum smart contracts, transpile them to Cairo, and deploy them on StarkNet seamlessly. Currently, Warp works by taking your smart contract, compiling it to EVM bytecode with whatever compiler you’re using, and translates that bytecode to Cairo. This allows us to safely preserve the semantics of the original smart contract. Security is arguably the most vital feature of any smart contract. Having this in mind, we’re about to begin work on formally verifying this transpilation process.

Deploying a Solidity ERC20 contract to StarkNet

If you’ve gone ahead and read the ERC20 code already, you may notice that it looks a little different from a regular ERC20. Expressions like msg.sender and msg.value do not have analogous counterparts on StarkNet yet, so we've left out those and other operations that rely on Ethereum L1 state. You won't have to worry about doing this in the future. The purpose of this demo is to show you how easy it is to transpile, deploy and interact with a contract written in Solidity on StarkNet, so let's just run with the oddities of the ERC20 contract.

Let’s set up our environment, clone the main Warp GitHub repo. In the repo’s root directory run:

MacOS:

brew install python@3.7
brew install gmp
python3.7 -m venv ~/warp_demo
source ~/warp_demo/bin/activate
pip install wheel
pip install ecdsa fastecdsa sympy
pip install cairo-lang==0.3.1
make warp

Linux:

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install -y python3.7
sudo apt install -y python3.7-dev
sudo apt install -y libgmp3-dev
python3.7 -m venv ~/warp_demo
source ~/warp_demo/bin/activate
pip install wheel
pip install ecdsa fastecdsa sympy
pip install cairo-lang==0.3.1
make warp

Voila, we’re ready to use Warp.

Head into the examples/ERC20 directory. You’ll see a contract called ERC20.sol. You don't need to worry about installing the correct version of the Solidity compiler; Warp takes care of that by detecting the compiler version from the contract file and installing it if you don't have it. Run:

warp transpile ERC20.sol

You’ll see a Cairo contract has been created with the same name as the solidity one (with the .cairo extension of course). You may notice that the generated Cairo file is large. This won’t be the case for very long, as we are currently working on reducing the size of the generated Cairo file to be only slightly larger than the original contract. To deploy the Cairo contract on StarkNet, run:

warp deploy ERC20.cairo

This will compile the Cairo contract (which takes a minute because of its size) and deploy it to StarkNet. You’ll see some info about the deployment transaction and the contract’s address, which is also written to a file. You can check the status of the deployment transaction on StarkNet with:

warp status TX_ID

Where TX_ID is the number that was printed to stdout during deployment. When status returns PENDING, the transaction has passed the validation stage and is waiting to be sent on-chain. Now let's call a function from the contract!

As you can see in ERC20.cairo, the Cairo functions are named segmentX, where X is a number. This is how we handle EVM JUMP instructions, and X is the value of the Program Counter at the jump destination. "But wait!" you say, "How am I meant to call the Cairo contract with all these ugly function names?!", don't worry, Warp takes care of that too! If we look at the Solidity contract, we'll see a function called deposit, let's call it on the StarkNet contract:

warp invoke --contract ERC20.cairo  --address ADDRESS --function deposit  --inputs "0x47304e88314e9eb56F99e37cE2D5Dbc28F8B3FEF 10000"

Behind the scenes, Warp figures out which segmentX Cairo function should be called. The ADDRESS argument to —input can be found in ERC20 _ADDRESS.txt. We've just deposited some imaginary form of value into our Warped Ether token on StarkNet!

Warp Roadmap

Our next milestone is Warping an AMM, like Uniswap for example, to StarkNet! Another item on the roadmap is formally verifying Warp, and we’ve recently hired a software verification expert to that end. On that note, we’re hiring! Here’s my pitch. If you join the Nubia team, you’ll get to work with some of the most talented people in the Ethereum ecosystem (StarkWare), work at the bleeding edge of L2 technology, help solve one of Ethereum’s most significant problems (scaling), all while learning things you probably wouldn’t learn anywhere else. If this sounds interesting, drop us an email with your CV to Antonio at antonio@nethermind.io or send me a DM on Twitter!

--

--