Git Product home page Git Product logo

charcoal's Introduction

Charcoal is a Solidity-to-Sway translator written in Rust. This tool aims to translate contracts written in Solidity into Sway source code.

This is primarily an educational tool, and some generated Sway code may be incorrect or not optimal.

Please feel free to file an issue.

Requirements

Compiling the charcoal binary requires the Rust compiler and its package manager, cargo.

See the Rust Install page for installation options.

Usage

cargo run --release -- [OPTIONS]

Flags
-h, --help Prints help information
-V, --version Prints version information
Options
-d, --definition-name <definition-name> The name of the specific definition to translate. (Optional; Leave unused for all)
-o, --output-directory <output-directory> The path to save the translated Forc project to. (Optional; Must be a directory)
-t, --target <target> The Solidity target file or folder to translate.

Warning

Known Issues

  • Functions that return owned strings may return string constants.
  • Contracts that contain inheritance may generate incorrect function implementations.
  • Structures that contain mappings may not be translated correctly.
  • Pointer types may not be translated correctly.
  • Signed integers support is incomplete.
  • Low level calls are not all supported.
  • Contract creation with new is not supported.

Implementation Status

  • Language Items
    • Import Directives
    • Struct Types
    • Enum Types
    • Interfaces
    • Libraries
    • using/for
  • Contract-related
    • this
    • super
    • selfdestruct(address payable recipient) (NOTE: Unsupported)
  • State Variables
    • Constant
    • Immutable
    • Regular
  • Functions
    • Parameters
    • Return Variables
    • Returning Multiple Values
    • View Functions
    • Pure Functions
    • Receive Ether Function (NOTE: Unsupported)
    • Fallback Function (NOTE: Unsupported)
    • Function Overloading
    • Function Modifiers
    • Function Signatures (NOTE: Unsupported)
    • Function Selectors (NOTE: Unsupported)
  • Inheritance
    • Inheritance Specification
    • Function Overriding
    • Modifier Overriding
    • Constructors
  • Events
    • Event Type Declarations
    • Indexed Parameters (NOTE: Unsupported)
    • <event>.selector (NOTE: Unsupported)
  • Error Handling
    • Error Type Declarations
    • <error>.selector (NOTE: Unsupported)
    • assert(bool condition)
    • require(bool condition)
    • require(bool condition, string memory message)
    • revert()
    • revert(string memory reason)
    • revert Error(1, 2, 3)
    • revert Error({a: 1, b: 2, c: 3})
  • Control Structures
    • if/else
    • while
    • do/while
    • for
    • break
    • continue
    • return
    • try/catch
  • Function Calls
    • Internal Function Calls
    • External Function Calls
    • Function Calls with Named Parameters
    • Omitted Names in Function Definitions
    • Creating Contracts via new
  • Ether Units
    • wei
    • gwei
    • ether
  • Time Units
    • seconds
    • minutes
    • hours
    • days
    • weeks
  • Block and Transaction Properties
    • blockhash(uint blockNumber) returns (bytes32)
    • blobhash(uint index) returns (bytes32) (NOTE: Unsupported)
    • block.basefee (NOTE: Unsupported)
    • block.blobbasefee (NOTE: Unsupported)
    • block.chainid
    • block.coinbase
    • block.difficulty (NOTE: Unsupported)
    • block.gaslimit
    • block.number
    • block.prevrandao (NOTE: Unsupported)
    • block.timestamp
    • gasleft() returns (uint256)
    • msg.data
    • msg.sender
    • msg.sig (NOTE: Unsupported)
    • msg.value
    • tx.gasprice
    • tx.origin (NOTE: Unsupported)
  • ABI Encoding and Decoding Functions
    • abi.decode(bytes memory encodedData, (...)) returns (...)
    • abi.encode(...) returns (bytes memory)
    • abi.encodePacked(...) returns (bytes memory)
    • abi.encodeWithSelector(bytes4 selector, ...) returns (bytes memory)
    • abi.encodeWithSignature(string memory signature, ...) returns (bytes memory)
    • abi.encodeCall(function functionPointer, (...)) returns (bytes memory)
  • Members of bytes
    • bytes.concat(...) returns (bytes memory)
  • Members of string
    • string.concat(...) returns (string memory)
  • Mathematical and Cryptographic Functions
    • addmod(uint x, uint y, uint k) returns (uint)
    • mulmod(uint x, uint y, uint k) returns (uint)
    • keccak256(bytes memory) returns (bytes32)
    • sha256(bytes memory) returns (bytes32)
    • ripemd160(bytes memory) returns (bytes20) (NOTE: Unsupported)
    • ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)
  • Members of Address Types
    • <address>.balance (uint256)
    • <address>.code (bytes memory)
    • <address>.codehash (bytes32)
    • <address payable>.transfer(uint256 amount)
    • <address payable>.send(uint256 amount) returns (bool)
    • <address>.call(bytes memory) returns (bool, bytes memory)
    • <address>.delegatecall(bytes memory) returns (bool, bytes memory) (NOTE: Unsupported)
    • <address>.staticcall(bytes memory) returns (bool, bytes memory) (NOTE: Unsupported)
  • Type Information
    • type(C).name
    • type(C).creationCode
    • type(C).runtimeCode
    • type(I).interfaceId
    • type(T).min
    • type(T).max
  • Inline Assembly Statements
    • Assignments
    • Variable Declarations
    • If Statements
    • For Statements
    • Switch Statements
    • Leave Statements
    • Break Statements
    • Continue Statements
    • Block Statements
    • Function Definitions
    • Function Calls
  • Inline Assembly Expressions
    • Boolean Literals
    • Number Literals
    • Hex Number Literals
    • Hex String Literals
    • String Literals
    • Variable Identifiers
    • Function Calls
    • Suffix Access
  • Inline Assembly Built-In Functions
    • stop
    • add
    • mul
    • sub
    • div
    • sdiv
    • mod
    • smod
    • exp
    • not
    • lt
    • gt
    • slt
    • sgt
    • eq
    • iszero
    • and
    • or
    • xor
    • byte
    • shl
    • shr
    • sar
    • addmod
    • mulmod
    • signextend
    • sha3
    • keccak256
    • pc
    • pop
    • mload
    • mstore
    • mstore8
    • sload
    • sstore
    • tload
    • tstore
    • msize
    • gas
    • address
    • balance
    • selfbalance
    • caller
    • callvalue
    • calldataload
    • calldatasize
    • calldatacopy
    • codesize
    • codecopy
    • extcodesize
    • extcodecopy
    • returndatasize
    • returndatacopy
    • mcopy
    • extcodehash
    • create
    • create2
    • call
    • callcode
    • delegatecall
    • staticcall
    • return
    • revert
    • selfdestruct
    • invalid
    • log0
    • log1
    • log2
    • log3
    • log4
    • chainid
    • basefee
    • blobbasefee
    • origin
    • gasprice
    • blockhash
    • blobhash
    • coinbase
    • timestamp
    • number
    • difficulty
    • prevrandao
    • gaslimit
    • datasize
    • dataoffset
    • datacopy
    • setimmutable
    • loadimmutable
    • linkersymbol
    • memoryguard
    • verbatim...

charcoal's People

Contributors

camden-smallwood avatar georgiosdelkos avatar sdankel avatar yunche404 avatar

Stargazers

 avatar Bitcoinski avatar Sheville.Warhand avatar mbarto avatar  avatar block0xhash avatar Michael Dank avatar Ben Greenberg avatar Igor Rončević avatar

Watchers

 avatar

charcoal's Issues

Fails to compile due to a dependency error

This just started failing in the last hour or so. I noticed it because it runs in CI on https://github.com/FuelLabs/sway-playground. It fails with the --locked flag as well.

cargo install --git https://github.com/ourovoros-io/charcoal.git --rev 7c2fd7d1539d15304616269f11dbe20c1bd5d6ca

error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 1 field
   --> src/project.rs:170:59
    |
170 |                 solidity::SourceUnitPart::PragmaDirective(_, _, _) => {
    |                                                           ^  ^  ^ expected 1 field, found 3
    |
   ::: /Users/sophiedankel/.cargo/registry/src/index.crates.io-6f17d22bba15001f/solang-parser-0.3.4/src/pt.rs:349:21
    |
349 |     PragmaDirective(Box<PragmaDirective>),
    |                     -------------------- tuple variant has 1 field

For more information about this error, try `rustc --explain E0023`.

ERC20 generated code fails to compile with forc 0.60.0

For this example: https://gist.github.com/fuel-service-user/09232d1485c507658ba47abca263fd6c#file-playground-sol

The error is:

  --> /Users/sophiedankel/Development/sway-playground/projects/swaypad/src/main.sw:20:5
   |
18 | 
19 | impl AbiEncode for ERC20Event {
20 |     fn abi_encode(self, buffer: Buffer) {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected: Buffer 
found:    () 
help:     The definition of this function must match the one in the trait "AbiEncode" declaration.
21 |         match self {
22 |             ERC20Event::Approval((a, b, c)) => {
   |
____

  Aborting due to 1 error.

The issue is that the generated code for abi_encode does not return a value:

This line should be fn abi_encode(self, buffer: core::codec::Buffer) -> core::codec::Buffer {

use of unstable library feature 'int_roundings'

Looks like an old breaking change in Rust is causing issues with Charcoal? I'm getting the following error when using the tool:

error[E0658]: use of unstable library feature 'int_roundings'
   --> /Users/b/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fuel-tx-0.43.2/src/transaction/fee.rs:114:17
    |
114 |     total_price.div_ceil(factor as u128)
    |                 ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information

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.