Giter VIP home page Giter VIP logo

bestxeosx-gm / warp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nethermindeth/warp

0.0 0.0 0.0 214.16 MB

Warp - Bringing Solidity to StarkNet at warp speed. Warp is a Solidity to Cairo Compiler, this allows teams to write/migrate Solidity to Cairo for easy onboarding into the StarkNet ecosystem.

Home Page: https://nethermind.io/warp/

License: Apache License 2.0

Shell 0.07% JavaScript 0.01% Python 0.50% TypeScript 88.30% Makefile 0.01% Dockerfile 0.01% Solidity 7.52% PEG.js 0.25% Cairo 3.34%

warp's Introduction

Warp

Warp brings Solidity to StarkNet, making it possible to transpile Ethereum smart contracts to StarkNet Cairo Contracts.

Quickstart

Docker compose provides a ready to use environment featuring warp and devnet.

Note: Execute Warp using Docker works only for x86 architecture, x64 architectures will be supported soon.

Build and run containers

docker-compose up

Transpile

docker-compose exec warp warp transpile example_contracts/ERC20.sol

It's best to copy the contract/repo to the warp directory so it is available in container via volume. Use contract's paths relative to warp root. For example, assuming you've copied your project to warp/projects/myproject you can replace example_contracts/ERC20.sol with projects/myproject/mycontract.sol in the above command.

Deploy to devnet

docker-compose exec warp warp compile warp_output/example__contracts/ERC20__WC__WARP.cairo
docker-compose exec warp starknet deploy --no_wallet --contract warp_output/example__contracts/ERC20__WC__WARP_compiled.json --gateway_url http://devnet:5050

Documentation ๐Ÿ“–

You can read the documentation here.

Installation โš™๏ธ

Dependencies


  1. You will need z3 and gmp installed to use Warp.
  • Install command on macOS:
brew install z3 gmp

If you're on an arm based Apple machine (m1/m2 mac) you'll need to install gmp and export some environment variables

export CFLAGS=-I`brew --prefix gmp`/include
export LDFLAGS=-L`brew --prefix gmp`/lib
  • Install command on Ubuntu:
sudo apt install libz3-dev libgmp3-dev
  1. Install Python3.9 with dev dependencies (python3.9 python3.9-venv python3.9-dev) into your base env. If you do not have the dev dependencies installed the installation will fail.
  • Install commands on MacOS:
brew install [email protected]

With python3.9 already installed you have venv covered:

If you are using Python 3.3 or newer (...) venv is included in the Python standard library and requires no additional installation.

Then you can install dev package using pip:

pip install python-dev-tools
  • Install commands on Ubuntu:
sudo apt install python3.9 python3.9-venv python3.9-dev

Or you can just install python3.9 and then install python-dev-tools using pip.

Warp Installation Method 1:


Without any virtual environment activated perform the following in order:
  1. Add the warp package from npm.
yarn global add @nethermindeth/warp
  1. Ensure the package was added by checking the version number:
warp version
  1. Install the dependencies:
warp install --verbose

Use the --python flag to pass the path to python3.9 binary, if the above command complains.

warp install --python <path/to/python3.9> --verbose
  1. Test the installation worked by transpiling an example ERC20 contract:
warp transpile example_contracts/ERC20.sol

Warp Installation Method 2 (from source/for devs):


Make sure you have the dependencies installed first.

With a virtual environment (recommended Python3.9) activated:

  1. Clone this repo and change directory into the warp folder.

  2. Install the JavaScript dependencies:

yarn
  1. Install the Python dependencies:
pip install -r requirements.txt

If you are using a M1 chipped Mac and getting a 'gmp.h' file not found error when installing Cairo run the following:

CFLAGS=-I`brew --prefix gmp`/include LDFLAGS=-L`brew --prefix gmp`/lib pip install ecdsa fastecdsa sympy

Then run the pip command above again.

  1. Compile the project:
yarn warplib
  1. Test the installation worked by transpiling an example ERC20 contract:
bin/warp transpile example_contracts/ERC20.sol

Usage ๐Ÿ’ป

If you have used installation method 1 you can use the warp command in any folder. If you have used installation method 2, you will have to specify the path to the warp directory followed by bin/warp e.g path_to_warp_repo/bin/warp ...

StarkNet setup

Select your network and wallet types. It's recommended to set these as environment variables but they can also be passed as explicit arguments to the Warp CLI and the StarkNet CLI.

export STARKNET_WALLET=starkware.starknet.wallets.open_zeppelin.OpenZeppelinAccount
export STARKNET_NETWORK=alpha-goerli

Make sure you have a StarkNet account set up, if you have not done so yet please:

warp deploy_account

CLI Commands


To transpile a Solidity contract:
warp transpile <path to Solidity contract>

To declare a StarkNet contract:

warp declare <path to StarkNet contract>

Please note to deploy a contract you will first have to declare it.

To deploy a StarkNet contract:

warp deploy <path to StarkNet contract>

The deploy command will generate the compiled json file as well as the abi json file. Use warp deploy --help command to see more deployment options.


Libraries


Libraries are bundled into the point of use, therefore if you try transpile a standalone library it will result in no output. If you would like to transpile and deploy a standalone library please alter its declaration to `contract`.

Unsupported Solidity Features


Several features of Solidity are not supported/do not have analogs in Starknet yet. We will try our best to add these features as StarkNet supports them, but some may not be possible due to fundamental differences in the platforms.

Please see the list below:

Support Status Symbol
Will likely never be supported โŒ
Being developed/investigated โš’๏ธ
Currently Unknown/If added in Cairo โ“
Solidity Support Status
fallback functions with args โš’๏ธ
delegate calls โš’๏ธ
low level calls โŒ
nested tuple expressions โ“
gasleft() โ“
msg.value โ“
msg.sig โ“
msg.data โ“
tx.gasprice โ“
tx.origin โ“
try/catch โ“
block.coinbase โ“
block.gaslimit โ“
block.basefee โ“
block.chainid โ“
block.difficulty โŒ
precompiles (apart from ecrecover) โ“
selfdestruct โ“
blockhash โ“
functions pointers in storage โ“
sha256 (use keccak256 instead) โŒ
receive โ“
Inline Yul Assembly - arithmetic (add, sub ...) โš’๏ธ
Inline Yul Assembly - (memory, calldata, storage) โ“
user defined errors โ“
function call options e.g x.f{gas: 10000}(arg1) โ“
member access of address object e.g address.balance โ“
nested tuple assignments โ“

Note: We have changed the return of ecrecover to be uint160 because we use the address type for StarkNet addresses.

Docker ๐Ÿณ

Note: Execute Warp using Docker works only for x86 architecture, x64 architectures will be supported soon.

Build the image from source:

docker build -t warp .

Run the container with the same options and arguments as the Warp binary:

docker run --rm -v $PWD:/dapp --user $(id -u):$(id -g) warp transpile example_contracts/ERC20.sol

Contributing

First steps ๐Ÿพ

If you like to contribute, the first step is to install Warp from source for devs steps here

To look what features we are currently working on or tasks that are pending to do, please checkout the project on github here

Also, please take a look through our Contribution Guidelines

Developing tips ๐Ÿฏ

While developing your code, remembering to compile the project every time some minor changes are applied could be annoying. You could start a process that watch for changes and automatically recompile it.

In a separate terminal execute:

yarn dev

Developers could run warp instructions using docker. This is an example using transpile command:

docker-compose exec warp npx ts-node src transpile example_contracts/ERC20.sol

Testing for contributors ๐Ÿฉบ

To test that your contribution doesn't break any features you can test that all previous example contracts transpile and then cairo compile by running the following:

warp test

For this to work, you must have the cairo-lang package installed. To test try:

starknet-compile -v

Instructions to set this up can be found at https://www.cairo-lang.org/docs/quickstart.html

Then to see that your contribution doesn't break the behaviour tests follow these steps:

  1. Run the setup script:
tests/behaviour/setup.sh
  1. In a separate terminal, start a StarkNet testnet server (in an environment with cairo-lang installed):
yarn testnet
  1. Run the tests:
yarn test

To generate benchmarks locally during development:

yarn testnet:benchmark
yarn test
python starknet-testnet/generateMarkdown.py

This saves the benchmarks at benchmark/stats/data.md

Contact Us โ˜Ž๏ธ

If you run into any problems please raise an issue or contact us on our Nethermind discord server: https://discord.com/invite/PaCMRFdvWT

warp's People

Contributors

domhenderson avatar rodrigo-pino avatar swapnilraj avatar cicr99 avatar jorikschellekens avatar rjnrohit avatar guymccomb avatar glitch18 avatar tserg avatar alejandrolabourdette avatar phybrackets avatar piwonskp avatar yaziciahmet avatar purva-chaudhari avatar dependabot[bot] avatar luislara-uh avatar axic avatar davidmitesh avatar agbanusi avatar elicbarbieri avatar falcoxyz avatar jelilat avatar tsbauer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.