Giter VIP home page Giter VIP logo

nethermindeth / warp Goto Github PK

View Code? Open in Web Editor NEW
751.0 15.0 68.0 678.76 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.05% Python 0.44% Makefile 0.01% Solidity 6.76% TypeScript 80.64% JavaScript 0.03% Cairo 11.84% Dockerfile 0.01% PEG.js 0.22%
ethereum solidity solidity-contracts starkware cairo-lang starknet evm evm-bytecode

warp's Introduction

Warp

๐Ÿ“ข Warp is no longer maintained. Feel free to fork it. You can start developing warp by checking supported features and issues. Development instructions are here.

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

โš ๏ธ Note: Cairo 1 is not fully supported yet. For more details see supported features.

โš ๏ธ Note: Cairo 0 implementation of warp can be found at this tag.

Quickstart

Note: Executing Warp using Docker works only for x86 architecture. If you're using ARM architecture (such as Apple's M1) you can find warp installation instructions here.

Note: The method refers to warp for cairo 0. If you are looking for cairo 1 warp see installing from source. You might be also interested in supported features in cairo 1 warp.

The easiest way to start with warp is using docker. To do that navigate to the directory where you store your contracts and run command:

docker run --rm -v "$PWD:/dapp" nethermind/warp transpile <contract-path>

You can find docker installation guide here.

Quick links

๐Ÿ“– Documentation

๐Ÿ“ฆ Installation

โœ๏ธ Developing warp

Discord

twitter

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`.

Supported features

Solidity: Warp supports Solidity 0.8. In order to support newer versions nethersolc has to be updated, and nethersolc binaries within warp repository have to be updated.

Cairo: The latest version of Cairo compiler supported by warp is 1.1. You can find compiler binaries together with warp plugin executable in cairo1 directory. Warp plugin repository is located here.

Warp doesn't support all features of Cairo 1 yet. You can find an example contract supported by warp in tests/behaviour/contracts/if/localVariables.sol:

contract WARP {
function ifNoElse(bool choice) pure public returns (uint8 a) {
uint8 x = 2;
if (choice) {
x = 1;
}
return x;
}
function ifWithElse(bool choice) pure public returns (uint8 a) {
uint8 x = 2;
if (choice) {
x = 1;
} else {
x= 3;
}
return x;
}
}

For more fully working examples see here. Uncommented lines are Solidity files that are passing tests. Those files are located in tests/behaviour/contracts/. There is also a list of compilation tests here. It contains contracts that are partially working ie. they are compiling, but the code might not yield correct results in runtime.

You can find a list of missing features here. Feel free to pick one of those and implement it yourself!

warp's People

Contributors

agbanusi avatar alejandrolabourdette avatar aniket2405 avatar ankit7241 avatar axic avatar cicr99 avatar cwkang1998 avatar davidmitesh avatar dependabot[bot] avatar domhenderson avatar elicbarbieri avatar esdras-sena avatar falcoxyz avatar glitch18 avatar guymccomb avatar hyodar avatar jelilat avatar jorikschellekens avatar julio4 avatar luislara-uh avatar phybrackets avatar piwonskp avatar purva-chaudhari avatar rjnrohit avatar rodrigo-pino avatar swapnilraj avatar temyurchenko avatar tsbauer avatar tserg avatar yaziciahmet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

warp's Issues

Remove warp test

It is confusing for users of warp to have a test command which doesn't test their contracts but tests warp functionality

Natspec AST parser issue

It seems the natspec in this is not parseable by the AST (attributed to wrong parent node):

interface IOwnable {
    /**
     * @dev Change of ownership proposed.
     * @param currentOwner The current owner.
     * @param proposedOwner The proposed owner.
     */
    event OwnershipProposed(address  currentOwner, address  proposedOwner);
}

abstract contract Ownable is IOwnable {}
---
InsaneASTError: Child StructuredDocumentation #1 has wrong parent: expected EventDefinition #7 got EventDefinition #23
    at checkSane (/warp/build/utils/astChecking.js:191:23)
    at /warp/build/utils/astChecking.js:524:13
    at Array.every (<anonymous>)
    at isSane (/warp/build/utils/astChecking.js:522:22)
    at runSanityCheck (/warp/build/utils/utils.js:100:34)
    at checkAST (/warp/build/transpiler.js:131:56)
    at /warp/build/transpiler.js:95:9
    at Array.reduce (<anonymous>)
    at applyPasses (/warp/build/transpiler.js:91:36)
    at transpile (/warp/build/transpiler.js:17:22)
    at Command.<anonymous> (/warp/build/index.js:35:36)
    at Command.listener [as _actionHandler] (/warp/node_modules/commander/lib/command.js:481:17)
    at /warp/node_modules/commander/lib/command.js:1236:65
    at Command._chainOrCall (/warp/node_modules/commander/lib/command.js:1152:12)
    at Command._parseCommand (/warp/node_modules/commander/lib/command.js:1236:27)
    at Command._dispatchSubcommand (/warp/node_modules/commander/lib/command.js:1058:25)
AST failed internal consistency check. Most recently run pass: InheritanceInliner
Transpilation abandoned AST failed internal consistency check. Most recently run pass: InheritanceInliner

Ternary operator is not properly supported

Transpilation abandoned Conditional expressions (ternary operator, node) are not supported

File test.sol:

	1  contract C {
	2    function f(uint256 a) external returns (uint8) {
	3      return (a < 42) ? 11 : 22;
	4    }
	5  }

does warp support library imports?

My contract comes with standard openzeppelin imports:

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

Is there an easy way to get these imports transpiled other than copy pasting them in the current path?

Unclear command

It is not clear for me about the error message :

Try using --python option for warp install to specify the path to python3.7

Commands that i've tried are including :

warp install --python 
warp install --python3.7 
warp install --python3

Is warp current support Contract extensibility ?

I am testing with two contract , and one will import the other one, and something go wrong.
Foo.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

struct Point {
    uint256 x;
    uint256 y;
}

error Unauthorized(address caller);

function add(uint256 x, uint256 y) pure returns (uint256) {
    return x + y;
}

contract Foo {
    string public name = "Foo";
}

Import.sol

/ SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

// import Foo.sol from current directory
import "./Foo.sol";

// import {symbol1 as alias, symbol2} from "filename";
import {Unauthorized, add as func, Point} from "./Foo.sol";

contract Import {
    // Initialize Foo.sol
    Foo public foo = new Foo();

    // Test Foo.sol by getting it's name.
    function getFooName() public view returns (string memory) {
        return foo.name();
    }
}

Error message :

Error: Identifier already declared.
  --> Import_marked.sol:13:36:

Support for inline Yul assembly

Hi everyone, congratulations for the great project !
I noticed that, currently, inline Yul assembly is not supported, and I was wondering if you are thinking of introducing it.
Actually, I noticed that some work was already done some time ago in the warp-yul branch so, in case there is no upcoming plan to re-introduce this feature, how much difficult would it be to integrate the relevant content of the warp-yul branch in the current most up-to-date one (I guess it's warp-ts) ?
Thanks in advance !

Clean up output

  • Make a file which contains:
    • the storage var declaration
    • all the storage reads and writes
    • all type conversions
  • Make a 'types' file which contains
    • all the struct definitions
  • Fix some of the indentation and new line issues, we can definitely do better than the current output

Compiling cast of address to uint160

The following pattern is often repeated in solidity contracts:

uint256(uint160(addr)

Where the author's intent is to use the address as a number, Warp returns the following error when encountering this pattern:

TypeError: Explicit type conversion not allowed from "address" to "uint160". Warp changed address size to be 251 bits. Consider replacing uint160 casts with uint256 casts

Can/should this be implicitly converted to a felt (which is an address on starknet)? Any negative implications for this?

Transpiling uniswap v3. warp lib missing associated cairo imports

I am transpiring uniswap v3 and the generated code expects the following cairo imports which are missing from warp_lib.

from warplib.maths.int_conversions import warp_int8_to_int128
from warplib.maths.negate import warp_negate128
from warplib.maths.add import warp_add128
from warplib.maths.add_signed import warp_add_signed256
from warplib.maths.ge_signed import warp_ge_signed256
from warplib.maths.sub_signed import warp_sub_signed256
from warplib.maths.le_signed import warp_le_signed256
from warplib.maths.mul import warp_mul256

Finish the transition to solc-typed-ast v11.0.2

The new version of solc-typed-ast introduced a lot of changes. Even though warp updated the package to the newest version it's not been fully ported to it yet. Especially warp is not using InferType class, but an obsolete typestring parser.

To see how many tests are failing when using infertype class uncomment the block of code.

Some changes that are needed to fully port warp to the new version:

  • Modify nodes each time typestring is modified
  • Adapt builtins link
  • Move some transformations to the end of processing (e.g. constants to literals)
  • #849
  • Set typename when creating a new node (spotted on VariableDeclaration node)
  • Remove generateExpressionTypeString or add implementation for new nodes (eg. super, emitting event)
  • Handle warp's custom cairo nodes
  • Handle function visibility. Eg. use isFunctionCallExternal
  • Research and fix problems with missing MemberAccess properties (e.g. using_for/library.sol)
  • #971

Generated code is broken with `receive` function

contract C {
  function f() external {
    address payable a = payable(this);
    selfdestruct(a);
  }
  receive() external payable {}
}
warp_output/test__WARP_CONTRACT__C.cairo:36:10: Unexpected token Token('LBRACE', '{'). Expected: identifier.
    func {syscall_ptr : felt*, range_check_ptr : felt}()-> ():
         ^
Unexpected error during transpilation
Error: Command failed: PATH=/warp/warp_venv/bin:$PATH cairo-format -i warp_output/test__WARP_CONTRACT__C.cairo
warp_output/test__WARP_CONTRACT__C.cairo:36:10: Unexpected token Token('LBRACE', '{'). Expected: identifier.
    func {syscall_ptr : felt*, range_check_ptr : felt}()-> ():
         ^

    at checkExecSyncError (node:child_process:826:11)
    at execSync (node:child_process:900:15)
    at formatOutput (/warp/build/io.js:117:34)
    at outputResult (/warp/build/io.js:102:9)
    at /warp/build/index.js:36:35
    at Array.map (<anonymous>)
    at Command.<anonymous> (/warp/build/index.js:35:104)
    at Command.listener [as _actionHandler] (/warp/node_modules/commander/lib/command.js:481:17)
    at /warp/node_modules/commander/lib/command.js:1236:65
    at Command._chainOrCall (/warp/node_modules/commander/lib/command.js:1152:12)
    at Command._parseCommand (/warp/node_modules/commander/lib/command.js:1236:27)
    at Command._dispatchSubcommand (/warp/node_modules/commander/lib/command.js:1058:25)
    at Command._parseCommand (/warp/node_modules/commander/lib/command.js:1201:19)
    at Command.parse (/warp/node_modules/commander/lib/command.js:890:10)
    at Object.<anonymous> (/warp/build/index.js:142:9)
    at Module._compile (node:internal/modules/cjs/loader:1101:14) {
  status: 2,
  signal: null,
  output: [
    null,
    <Buffer >,
    <Buffer 77 61 72 70 5f 6f 75 74 70 75 74 2f 78 5f 5f 57 41 52 50 5f 43 4f 4e 54 52 41 43 54 5f 5f 43 2e 63 61 69 72 6f 3a 33 36 3a 31 30 3a 20 55 6e 65 78 70 ... 130 more bytes>
  ],
  pid: 64185,
  stdout: <Buffer >,
  stderr: <Buffer 77 61 72 70 5f 6f 75 74 70 75 74 2f 78 5f 5f 57 41 52 50 5f 43 4f 4e 54 52 41 43 54 5f 5f 43 2e 63 61 69 72 6f 3a 33 36 3a 31 30 3a 20 55 6e 65 78 70 ... 130 more bytes>
}
Transpilation failed

Update: actually this is a bug in receive, this triggers it:

contract C {
  receive() external payable {}
}

And the generated function is:

    @external
    func {syscall_ptr : felt*, range_check_ptr : felt}()-> ():
        alloc_locals
        return ()
    end

transpile failed with 'RuntimeError: Unsupported OS: macOS-10.16-x86_64-i386-64bit'

ENV

  • MacOS Monterey 12.1
  • Python 3.9
  • solc Version: 0.8.11+commit.d7f03943.Darwin.appleclang

log

% warp transpile ERC20.sol WARP
Traceback (most recent call last):
  File "/usr/local/bin/warp", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/site-packages/warp/cli/cli.py", line 199, in main
    warp()
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/warp/cli/cli.py", line 53, in transpile
    output = transpile_from_solidity(file_path, contract_name)
  File "/usr/local/lib/python3.9/site-packages/warp/yul/main.py", line 53, in transpile_from_solidity
    with kudu_exe() as exe:
  File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
    return next(self.gen)
  File "/usr/local/lib/python3.9/site-packages/warp/kudu.py", line 39, in kudu_exe
    raise RuntimeError(f"Unsupported OS: {platform.platform()}")
RuntimeError: Unsupported OS: macOS-10.16-x86_64-i386-64bit

All commands should have short descriptions

Usage: warp [options] [command]

Options:
  -h, --help                          display help for command

Commands:
  transpile [options] <files...>
  transform [options] <file>
  test [options]
  analyse [options] <file>
  status [options] <tx_hash>
  compile [options] <file>
  gen_interface [options] <file>
  deploy [options] <file>
  deploy_account [options]
  invoke [options] <file>
  call [options] <file>
  install [options]
  declare [options] <cairo_contract>  Command to declare Cairo contract on a StarkNet Network.
  version

Got CLientConnectorCertiticateError while trying to access https://alpha4.starknet.io/gateway/add_transaction.

Environment:

  • OS: macOS Monterey v12.5.1
  • Python 3.7.9
  • Cairo version: 0.9.1
  • Warp Version: 2.1.0

Description:
I'm using. the example_contracts ERC20 to transpile the solidity code into cairo code, this generate a warp_output dir successfully with 3 files, ERC20__WC__WARP_abi.json, ERC20__WC__WARP_compiled.json, ERC20__WC__WARP.cairo and when I try to deploy the contract file I get this error:

Captura de Pantalla 2022-08-31 a la(s) 22 38 31

Improve initialisation of static arrays in memory

To initialise empty static arrays in memory we generate a function to write 0 or the default value for the type (think structs) at the right offsets in memory. For example

function test() external {
   uint256[100] d;
}

Generates a function with 100 parameters all taking a value of 0 and then it writes 0 at each index sequentially, for these cases we only need to pass one parameter and instead of writing 0 sequentially to each location we should generate a recursive function that loops through the indexes of the array to do this.

build errors in yul_api.cairo and memory.cairo when running them through a recent cairo compiler

Hi, please help :-)

After warp transpile --cairo-output

and copying /usr/local/lib/python3.7/site-packages/warp/cairo-src/evm to the contracts/ dir

I run the outputs through nile compile

๐Ÿค– Compiling all Cairo contracts in the contracts directory
๐Ÿ”จ Compiling contracts/Test.cairo
๐Ÿ”จ Compiling contracts/contract.cairo
๐Ÿ”จ Compiling contracts/evm/yul_api.cairo
contracts/evm/yul_api.cairo:83:18: While trying to retrieve the implicit argument 'memory_dict' in:
let (data) = array_create_from_memory(mem_offset.low, mem_len.low)
^*********************^
/root/code/cqg/optio/match/contracts/evm/array.cairo:16:9: Unknown identifier 'memory_dict'.
memory_dict : DictAccess
, range_check_ptr, bitwise_ptr : BitwiseBuiltin
}(
^
^
๐Ÿ”จ Compiling contracts/evm/utils.cairo
๐Ÿ”จ Compiling contracts/evm/bit_packing.cairo
๐Ÿ”จ Compiling contracts/evm/array.cairo
๐Ÿ”จ Compiling contracts/evm/hashing.cairo
๐Ÿ”จ Compiling contracts/evm/pow2.cairo
๐Ÿ”จ Compiling contracts/evm/memory.cairo
contracts/evm/memory.cairo:133:12: Expected Uint256 to be a function name. Found: struct.
return Uint256(immediate, 0)
^
^
๐Ÿ”จ Compiling contracts/evm/calls.cairo
๐Ÿ”จ Compiling contracts/evm/uint256.cairo
๐Ÿ”จ Compiling contracts/evm/exec_env.cairo
๐Ÿ›‘ Failed to compile the following 2 contracts:
contracts/evm/yul_api.cairo
contracts/evm/memory.cairo

Deploy with no constructor args doesn't work


// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;

contract Mapping {
    // Mapping from address to uint
    mapping(address => uint) public myMap;

    function get(address _addr) public view returns (uint) {
        // Mapping always returns a value.
        // If the value was never set, it will return the default value.
        return myMap[_addr];
    }

    function set(address _addr, uint _i) public {
        // Update the value at this address
        myMap[_addr] = _i;
    }

    function remove(address _addr) public {
        // Reset the value to the default value.
        delete myMap[_addr];
    }
}

contract NestedMapping {
    // Nested mapping (mapping from address to another mapping)
    mapping(address => mapping(uint => bool)) public nested;

    function get(address _addr1, uint _i) public view returns (bool) {
        // You can get values from a nested mapping
        // even when it is not initialized
        return nested[_addr1][_i];
    }

    function set(address _addr1, uint _i, bool _boo) public {
        nested[_addr1][_i] = _boo;
    }

    function remove(address _addr1, uint _i) public {
        delete nested[_addr1][_i];
    }
}

`bin/warp transpile solc_file -o .` is not working anymore

bin/warp transpile solc_file -o . is not working anymore, it used to work before. Possibly because of the dir name clash with the solidity file name itself.

Error: ENOTDIR: not a directory, open 'order_of_eval.sol/A_sol_abi.json'
    at Object.openSync (node:fs:599:3)
    at Object.writeFileSync (node:fs:2221:35)
    at Object.outputFileSync (/Users/rohit/nmd/warp/node_modules/fs-extra/lib/output-file/index.js:31:15)
    at outputResult (/Users/rohit/nmd/warp/build/io.js:104:12)
    at /Users/rohit/nmd/warp/build/index.js:73:35
    at Array.map (<anonymous>)
    at Command.<anonymous> (/Users/rohit/nmd/warp/build/index.js:72:14)
    at Command.listener [as _actionHa

...

spello?

firstly, I am NOT a programmer.

In the page (warp/examples/ERC20/ERC20.sol), was this string - "Warrpped - meant to be spelt that way, or is this a typo/mistake?

string public name        = "Warrpped Ether";

cheers

M1 Installation failure

Running pip install -r requirements.txt does result in a known error in macbooks with M1 chip, in order to solve it I would advice to run:

CFLAGS=-I`brew --prefix gmp`/include LDFLAGS=-L`brew --prefix gmp`/lib pip install -r requirements.txt

Cleanup README - discord link, installation instructions, FAQ

I think this would encourage people to join the conversation earlier.

Also, we have two discords. Should we pick one and close the other to keep the conversation in one place?

The file paths for the Cairo files are still using the old format

Error running warp transpile

I am running macOS Monterey 12.0.1. I have followed the installation guide in the repository's README. For context, I also have a python venv in which I am using cairo which I can use to compile, deploy and interact with cairo contracts. I have also built docker containers for cairo and OpenZeppelin Nile which both appear to work without error at this time. I have built a docker container for warp (following the installation instructions in the README). I have also tried the warp installation on my Linux machine (Ubuntu 20.04) neither of which work and display the same error set out below.

On my MacBook I have installed the following with brew:

  1. python3.7.12
  2. gmp
  3. boost

I then created a new python venv activated it and installed sol-warp==0.2.15 with pip.

Everything appears to install properly and without error. However, when I run warp transpile I get the following error:

(sol-warp) # warp transpile ERC20.sol WARP
Traceback (most recent call last):
File "/Users/david/sol-warp/bin/warp", line 5, in
from cli.warp_cli import main
File "/Users/david/sol-warp/lib/python3.7/site-packages/cli/warp_cli.py", line 13, in
from cli.commands import _deploy, _invoke, _status
File "/Users/david/sol-warp/lib/python3.7/site-packages/cli/commands.py", line 13, in
from starkware.starknet.services.api.contract_definition import ContractDefinition
File "/Users/david/sol-warp/lib/python3.7/site-packages/starkware/starknet/services/api/contract_definition.py", line 9, in
from starkware.cairo.lang.compiler.program import Program
File "/Users/david/sol-warp/lib/python3.7/site-packages/starkware/cairo/lang/compiler/program.py", line 10, in
from starkware.cairo.lang.compiler.debug_info import DebugInfo
File "/Users/david/sol-warp/lib/python3.7/site-packages/starkware/cairo/lang/compiler/debug_info.py", line 10, in
from starkware.cairo.lang.compiler.preprocessor.flow import FlowTrackingDataActual
File "/Users/david/sol-warp/lib/python3.7/site-packages/starkware/cairo/lang/compiler/preprocessor/flow.py", line 16, in
from starkware.cairo.lang.compiler.references import FlowTrackingError, Reference
File "/Users/david/sol-warp/lib/python3.7/site-packages/starkware/cairo/lang/compiler/references.py", line 18, in
from starkware.cairo.lang.compiler.fields import ExpressionAsStr
File "/Users/david/sol-warp/lib/python3.7/site-packages/starkware/cairo/lang/compiler/fields.py", line 4, in
from starkware.cairo.lang.compiler.parser import parse_expr, parse_type
File "/Users/david/sol-warp/lib/python3.7/site-packages/starkware/cairo/lang/compiler/parser.py", line 34, in
propagate_positions=True,
File "/Users/david/sol-warp/lib/python3.7/site-packages/lark/lark.py", line 355, in init
assert_config(lexer, ('basic', 'contextual', 'dynamic', 'dynamic_complete'))
File "/Users/david/sol-warp/lib/python3.7/site-packages/lark/exceptions.py", line 21, in assert_config
raise ConfigurationError(msg % (value, options))
lark.exceptions.ConfigurationError: Got 'standard', expected one of ('basic', 'contextual', 'dynamic', 'dynamic_complete')

Your help with this would be appreciated.

Transpiling Oracle.sol from uniswap v3 Core

This is the file and see error below https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/Oracle.sol. I remove the ternary operators into simpler if blocks to get through the expected transpiration error.

Unexpected error during transpilation
Error: Couldn't find StructDefinition Oracle.Observation
at makeUserDefinedType (/Users/fawad/.config/yarn/global/node_modules/solc-typed-ast/dist/types/typeStrings/typeString_parser.js:78:15)
at peg$c195 (/Users/fawad/.config/yarn/global/node_modules/solc-typed-ast/dist/types/typeStrings/typeString_parser.js:451:16)
at peg$parseUserDefinedType (/Users/fawad/.config/yarn/global/node_modules/solc-typed-ast/dist/types/typeStrings/typeString_parser.js:3849:26)
at peg$parseSimpleType (/Users/fawad/.config/yarn/global/node_modules/solc-typed-ast/dist/types/typeStrings/typeString_parser.js:3215:50)
at peg$parseNonArrPtrType (/Users/fawad/.config/yarn/global/node_modules/solc-typed-ast/dist/types/typeStrings/typeString_parser.js:4906:18)
at peg$parseArrayPtrType (/Users/fawad/.config/yarn/global/node_modules/solc-typed-ast/dist/types/typeStrings/typeString_parser.js:4923:14)
at peg$parseType (/Users/fawad/.config/yarn/global/node_modules/solc-typed-ast/dist/types/typeStrings/typeString_parser.js:5220:34)
at peg$parseStart (/Users/fawad/.config/yarn/global/node_modules/solc-typed-ast/dist/types/typeStrings/typeString_parser.js:644:18)
at peg$parse (/Users/fawad/.config/yarn/global/node_modules/solc-typed-ast/dist/types/typeStrings/typeString_parser.js:5229:18)
at getNodeType (/Users/fawad/.config/yarn/global/node_modules/solc-typed-ast/dist/types/typeStrings/typeString_parser.js:56:30)
at /Users/fawad/.config/yarn/global/node_modules/@nethermindeth/warp/build/utils/getTypeString.js:73:55
at Array.map ()
at getReturnTypeString (/Users/fawad/.config/yarn/global/node_modules/@nethermindeth/warp/build/utils/getTypeString.js:72:10)
at createCallToFunction (/Users/fawad/.config/yarn/global/node_modules/@nethermindeth/warp/build/utils/functionGeneration.js:11:107)
at createSplitFunction (/Users/fawad/.config/yarn/global/node_modules/@nethermindeth/warp/build/passes/ifFunctionaliser.js:117:64)
at IfFunctionaliser.visitIfStatement (/Users/fawad/.config/yarn/global/node_modules/@nethermindeth/warp/build/passes/ifFunctionaliser.js:29:37)
Transpilation failed

Batching for behaviour tests

Run behaviour tests in batches to reduce CI running time in github

Enable parallel execution of behaviour tests batches

Add conditionals to literalExpressionEvaluator pass

Currently conditional expressions (ternary operation) are not being evaluated in literalExpressionEvaluator pass.

Conditionals have the form: condition ? thenBranch : elseBranch.
If the value of condition can be known during this pass, then the whole conditional expression can be replaced with the corresponding branch expression. In other words, if condition is evaluated to be true then :
condition ? thenBranch : elseBranch can be replaced by thenBranch
Similar thing happens in case it is evaluated to be false

Uniform file naming

Modify file names in order to have the same format across the entire project (camelCase). Keep in mind to update imports when doing so

why try/catch is not supported?

I am testing some sample contracts and ran into try catch not supported issue:

Error: Warp does not support try catch
   --> node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol:378:15:
    |
378 |             } catch (bytes memory reason) {
    |               ^ (Relevant source part starts here and spans across multiple lines).
                                                                        ^ (Relevant source part starts here and spans across multiple lines).

My question is whether this is a matter of implementation or a limitation?

warp silently fails on an exclusive solidity version interval

How to reproduce:

In the example contract ERC20.sol replace the first line with pragma solidity >0.4.18;.

Expected

Warp successfully generates an ERC20.cairo file.

Actual

There is no ERC20.cairo file and no indication of failure or reasons for failure


I think the issue is that get_source_version in Compile.py simply grabs the first version boundary without considering that it might be an exclusive boundary as in the example above. Thus, compiling the contract with this version fails (for some reason, silently)

nethersolc segfault -- dockerfile?

Hi, I think this is linux flavor issue, but, I started here: (in alpine)

https://github.com/Shard-Labs/cairo-cli-docker

then

apk add git openssh nano build-base boost-dev gmp-dev cmake boost-static
apk add libstdc++ curl ca-certificates python3-dev

#Then glib
#https://stackoverflow.com/questions/66963068/docker-alpine-executable-binary-not-found-even-if-in-path
export GLIBC_REPO=https://github.com/sgerrand/alpine-pkg-glibc
export GLIBC_VERSION=2.30-r0
for pkg in glibc-${GLIBC_VERSION} glibc-bin-${GLIBC_VERSION}; do curl -sSL ${GLIBC_REPO}/releases/download/${GLIBC_VERSION}/${pkg}.apk -o /tmp/${pkg}.apk; done
apk add --allow-untrusted /tmp/*.apk

pip install z3-solver
pip install sol-warp

nethersolc segfaults when I give it .sol file

and warp transpile gives me:

Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/warp/yul/utils.py", line 53, in get_solc_json
capture_output=True,
File "/usr/local/lib/python3.7/subprocess.py", line 512, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '[PosixPath('/usr/local/lib/python3.7/site-packages/warp/bin/linux/nethersolc'), '--optimize', '--combined-json', 'abi,ir-optimized-ast', 'Test.sol']' died with <Signals.SIGSEGV: 11>.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/bin/warp", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.7/site-packages/warp/cli/cli.py", line 246, in main
warp()
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1130, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.7/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/warp/cli/cli.py", line 53, in transpile
output = transpile_from_solidity(file_path, contract_name)
File "/usr/local/lib/python3.7/site-packages/warp/yul/main.py", line 45, in transpile_from_solidity
abi, yul_json = get_requests(filepath, main_contract, ["abi", "ir-optimized-ast"])
File "/usr/local/lib/python3.7/site-packages/warp/yul/utils.py", line 63, in get_requests
output = get_solc_json(requests, filepath)
File "/usr/local/lib/python3.7/site-packages/warp/yul/utils.py", line 57, in get_solc_json
raise WarpException(err_msg) from e
warp.yul.WarpException.WarpException: nethersolc call failed: /usr/local/lib/python3.7/site-packages/warp/bin/linux/nethersolc: /usr/lib/libstdc++.so.6: no version information available (required by /usr/local/lib/python3.7/site-packages/warp/bin/linux/nethersolc)

Add support for selector

In solidity you can get the function selector by

this.funcName.selector

Currently when we transpile that expression we get invalid cairo code. We should either support it, or throw a dedicated exception

Cannot install warp: Docker image?

Hi There,

Really cool project.

I tried 3 separate ways of installing warp:

  • Big Sur (invalid OS issue)
  • In Docker (Ubuntu 18) => missing libc6 dependency, apparently only 21 has the right version
  • In Docker (Ubuntu 21) => fails at add-apt-repository ppa:deadsnakes/ppa

Do you think it would make sense to provide a Dockerfile for reproducibility? I would happily provide one if I could get this to work.

Here's what I did, I ran the command:

docker run -it ubuntu:impish /bin/bash

and then followed the sequence of steps in the README order.

Flattener issue with solmate

Hi !
I'm currently using warp and have as dependency the solmate library. They are using some vanity comments to separate code blocks inside their contract that are not properly remove by the wrap flattener. I created a simple repo with foundry and also pushed the flattened contract => https://github.com/mortimr/warp_flattener_issue

This is the output I'm getting

    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
    event URI(string value, uint256 indexed id);
                            ERC1155 STORAGE
    mapping(address => mapping(uint256 => uint256)) public balanceOf;
    mapping(address => mapping(address => bool)) public isApprovedForAll;
                             METADATA LOGIC
    function uri(uint256 id) public view virtual returns (string memory);
                             ERC1155 LOGIC
    function setApprovalForAll(address operator, bool approved) public virtual {
        isApprovedForAll[msg.sender][operator] = approved;
        emit ApprovalForAll(msg.sender, operator, approved);
    }

And this is what the original solmate contract looks like

    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    event URI(string value, uint256 indexed id);

    /*///////////////////////////////////////////////////////////////
                            ERC1155 STORAGE
    //////////////////////////////////////////////////////////////*/

    mapping(address => mapping(uint256 => uint256)) public balanceOf;

    mapping(address => mapping(address => bool)) public isApprovedForAll;

    /*///////////////////////////////////////////////////////////////
                             METADATA LOGIC
    //////////////////////////////////////////////////////////////*/

    function uri(uint256 id) public view virtual returns (string memory);

    /*///////////////////////////////////////////////////////////////
                             ERC1155 LOGIC
    //////////////////////////////////////////////////////////////*/

    function setApprovalForAll(address operator, bool approved) public virtual {
        isApprovedForAll[msg.sender][operator] = approved;

        emit ApprovalForAll(msg.sender, operator, approved);
    }

GLIBC_2.33 Not Found Error

System Version: Ubuntu 20.04
Python Version: 3.7.12
Warp Version: 0.2.16
GLIBC Version: 2.31 (default on Ubuntu 20.04)

I'm receiving the following error when attempting to transpile a contract:
/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /mnt/c/Blockchain/envs/warp/lib/python3.7/site-packages/bin/linux/kudu)

It looks like only Ubuntu version 21.04 comes with GLIBC 2.33, so looks like a docker container with 21.04 is the only way currently around this? Any other way? Also if 21.04 is the only compatible version for transpiling it would probably be best to supply a docker container in the repo.

Dependency conflicts

I encounter an error when I first try to run warp. It seems to be some issues with the dependency but I am not a python guy, I will let the full error here

(warp_demo) [filip@filip-pc warp]$ warp
Traceback (most recent call last):
  File "/home/filip/warp_demo/lib64/python3.9/site-packages/pkg_resources/__init__.py", line 568, in _build_master
    ws.require(__requires__)
  File "/home/filip/warp_demo/lib64/python3.9/site-packages/pkg_resources/__init__.py", line 886, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/home/filip/warp_demo/lib64/python3.9/site-packages/pkg_resources/__init__.py", line 777, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (aiohttp 4.0.0a1 (/home/filip/warp_demo/lib/python3.9/site-packages/aiohttp-4.0.0a1-py3.9-linux-x86_64.egg), Requirement.parse('aiohttp<4,>=3.7.4.post0'), {'Web3'})

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/filip/warp_demo/bin/warp", line 33, in <module>
    sys.exit(load_entry_point('warp==0.1.0', 'console_scripts', 'warp')())
  File "/home/filip/warp_demo/bin/warp", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib64/python3.9/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/usr/lib64/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/home/filip/warp_demo/lib64/python3.9/site-packages/warp-0.1.0-py3.9.egg/cli/warp_cli.py", line 7, in <module>
    from cli.commands import _call, _deploy, _invoke, _status
  File "/home/filip/warp_demo/lib64/python3.9/site-packages/warp-0.1.0-py3.9.egg/cli/commands.py", line 8, in <module>
    from cli.StarkNetEvmContract import get_evm_calldata
  File "/home/filip/warp_demo/lib64/python3.9/site-packages/warp-0.1.0-py3.9.egg/cli/StarkNetEvmContract.py", line 4, in <module>
    from eth_abi.codec import ABICodec
  File "/home/filip/warp_demo/lib64/python3.9/site-packages/eth_abi-2.1.1-py3.9.egg/eth_abi/__init__.py", line 1, in <module>
    import pkg_resources
  File "/home/filip/warp_demo/lib64/python3.9/site-packages/pkg_resources/__init__.py", line 3243, in <module>
    def _initialize_master_working_set():
  File "/home/filip/warp_demo/lib64/python3.9/site-packages/pkg_resources/__init__.py", line 3226, in _call_aside
    f(*args, **kwargs)
  File "/home/filip/warp_demo/lib64/python3.9/site-packages/pkg_resources/__init__.py", line 3255, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/home/filip/warp_demo/lib64/python3.9/site-packages/pkg_resources/__init__.py", line 570, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/home/filip/warp_demo/lib64/python3.9/site-packages/pkg_resources/__init__.py", line 583, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/home/filip/warp_demo/lib64/python3.9/site-packages/pkg_resources/__init__.py", line 777, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (aiohttp 4.0.0a1 (/home/filip/warp_demo/lib/python3.9/site-packages/aiohttp-4.0.0a1-py3.9-linux-x86_64.egg), Requirement.parse('aiohttp<4,>=3.7.4.post0'), {'Web3'})

Warp Creating a contract with a smart contract fail

I am able to transpile and deploy some simple function contract,
However , when I try to transpile a mother contract which will create a daugther Contract,
It is not working.

  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/warp", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/warp/cli/cli.py", line 246, in main
    warp()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/warp/cli/cli.py", line 53, in transpile
    output = transpile_from_solidity(file_path, contract_name)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/warp/yul/main.py", line 82, in transpile_from_solidity
    codes = json.loads(result.stdout)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
pragma solidity ^0.8.6;
import "./DaughterContract.sol";

contract test {
    string public greet = "Hello World!";
    DaughterContract public daughter;

    function getGreet(uint256 testNumber) public pure returns (uint256) {
        return testNumber;
    }

    function newChildContract() public {
        daughter = new DaughterContract("testing1", 1);
    }
}
pragma solidity ^0.8.6;

contract DaughterContract {
    string public name;
    uint256 public age;

    constructor(string memory _daughtersName, uint256 _daughtersAge) public {
        name = _daughtersName;
        age = _daughtersAge;
    }
}

No such file or directory: '_marked.sol'

System Version: Ubuntu 20.04
Python Version: 3.7.12
sol-warp Version: 0.5.1

I am attempting to transpile a contract with the command "warp transpile ./loan.sol loan" from within the directory containing loan.sol, where loan is the name of the primary contract. I get the following error (with full traceback):

ERROR: Compilation failed

Traceback (most recent call last):
File "/mnt/c/Blockchain/envs/warp/bin/warp", line 8, in
sys.exit(main())
File "/mnt/c/Blockchain/envs/warp/lib/python3.7/site-packages/cli/warp_cli.py", line 162, in main
warp()
File "/mnt/c/Blockchain/envs/warp/lib/python3.7/site-packages/click/core.py", line 1128, in call
return self.main(*args, **kwargs)
File "/mnt/c/Blockchain/envs/warp/lib/python3.7/site-packages/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/mnt/c/Blockchain/envs/warp/lib/python3.7/site-packages/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/mnt/c/Blockchain/envs/warp/lib/python3.7/site-packages/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/mnt/c/Blockchain/envs/warp/lib/python3.7/site-packages/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/mnt/c/Blockchain/envs/warp/lib/python3.7/site-packages/cli/warp_cli.py", line 45, in transpile
output = transpile_from_solidity(file_path, contract_name)
File "/mnt/c/Blockchain/envs/warp/lib/python3.7/site-packages/yul/main.py", line 77, in transpile_from_solidity
output = get_for_contract(sol_src_path_modified, main_contract, ["abi"])
File "/mnt/c/Blockchain/envs/warp/lib/python3.7/site-packages/yul/utils.py", line 136, in get_for_contract
get_source_version(sol_source)
File "/mnt/c/Blockchain/envs/warp/lib/python3.7/site-packages/yul/utils.py", line 146, in get_source_version
with open(sol_source) as f:
FileNotFoundError: [Errno 2] No such file or directory: './loan_marked.sol'

Support UserDefinedErrors

This is a little tricky since StarkNet doesn't support anything like this. Maybe we can replace this with a simple revert and emit a compiler warning stating that we've done so?

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.