All Projects → s6ruby → Ruby To Solidity

s6ruby / Ruby To Solidity

Licence: cc0-1.0
(Secure) Ruby to Solidity (Source-to-Source) Cross-Compiler Cheat Sheet / White Paper

Programming Languages

ruby
36898 projects - #4 most used programming language
solidity
1140 projects

Projects that are alternatives of or similar to Ruby To Solidity

Sputnikvm
A Blockchain Virtual Machine
Stars: ✭ 238 (+3300%)
Mutual labels:  ethereum, evm
Ethersplay
EVM dissassembler
Stars: ✭ 304 (+4242.86%)
Mutual labels:  ethereum, evm
Monax
DEPRECATED. To be removed December, 2018 (use monax/bosmarmot)
Stars: ✭ 269 (+3742.86%)
Mutual labels:  ethereum, evm
Pyquarkchain
Python implementation of QuarkChain
Stars: ✭ 194 (+2671.43%)
Mutual labels:  ethereum, evm
Aleth
Aleth – Ethereum C++ client, tools and libraries
Stars: ✭ 3,885 (+55400%)
Mutual labels:  ethereum, evm
Remix Project
Remix is a browser-based compiler and IDE that enables users to build Ethereum contracts with Solidity language and to debug transactions.
Stars: ✭ 225 (+3114.29%)
Mutual labels:  ethereum, evm
Bamboo
Bamboo see https://github.com/cornellblockchain/bamboo
Stars: ✭ 300 (+4185.71%)
Mutual labels:  ethereum, evm
Evmone
Fast Ethereum Virtual Machine implementation
Stars: ✭ 162 (+2214.29%)
Mutual labels:  ethereum, evm
Dapptools
Dapp, Seth, Hevm, and more
Stars: ✭ 362 (+5071.43%)
Mutual labels:  ethereum, evm
Awesome Ethereum Security
A curated list of awesome Ethereum security references
Stars: ✭ 345 (+4828.57%)
Mutual labels:  ethereum, evm
Armors Solidity
Armors-solidity is a framework to build secure smart contracts on Ethereum.
Stars: ✭ 184 (+2528.57%)
Mutual labels:  ethereum, evm
Intellij Solidity
Solidity plugin for IntelliJ
Stars: ✭ 646 (+9128.57%)
Mutual labels:  ethereum, evm
Securify
[DEPRECATED] Security Scanner for Ethereum Smart Contracts
Stars: ✭ 177 (+2428.57%)
Mutual labels:  ethereum, evm
Evm Tools
Ethereum Virtual Machine tools and guide
Stars: ✭ 238 (+3300%)
Mutual labels:  ethereum, evm
Ethabi
Encode and decode smart contract invocations
Stars: ✭ 172 (+2357.14%)
Mutual labels:  ethereum, evm
Ruby Ethereum
A Ruby implementation of Ethereum.
Stars: ✭ 270 (+3757.14%)
Mutual labels:  ethereum, evm
Evmc
EVMC – Ethereum Client-VM Connector API
Stars: ✭ 137 (+1857.14%)
Mutual labels:  ethereum, evm
Rattle
evm binary static analysis
Stars: ✭ 152 (+2071.43%)
Mutual labels:  ethereum, evm
Evm Opcodes
Ethereum opcodes and instruction reference
Stars: ✭ 344 (+4814.29%)
Mutual labels:  ethereum, evm
Echidna
Ethereum smart contract fuzzer
Stars: ✭ 571 (+8057.14%)
Mutual labels:  ethereum, evm

New to (Secure) Ruby? See the Red Paper!

(Secure) Ruby to Solidity (Source-to-Source) Cross-Compiler Cheat Sheet / White Paper

By Example

Hello, World! - Greeter

############################
# Greeter Contract 


# @sig (string) public
def setup( greeting )
  @owner    = msg.sender
  @greeting = greeting
end

# @sig () public view returns (string)
def greet
  @greeting
end

# @sig () public
def kill
  if msg.sender == @owner
    selfdestruct( msg.sender )
  end
end

gets cross-compiled to:

contract Greeter {
    address owner;
    string  greeting;

    constructor( string _greeting ) public {
        owner    = msg.sender;
        greeting = _greeting;
    }

    function greet() public view returns (string) {
        return greeting;
    }

    function kill() public { 
      if(msg.sender == owner) selfdestruct(msg.sender); 
    }
}

Simple Storage

####################
# Simple Storage

def setup
  @stored_data = 0      # Note: Integer defaults to uint type
end

# @sig (uint) public
def set( x )
  @stored_data = x
end

# @sig () public view returns (uint)
def get
  @stored_data
end

gets cross-compiled to:

contract SimpleStorage {
    uint storedData;

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint) {
        return storedData;
    }
}

CryptoZombies Collectibles Code School - 300 000 Students and Counting!

##############################################
# Zombie Factory Contract

# @sig (uint, string, uint)
event :NewZombie, :zombie_id, :name, :dna

DNA_DIGITS  = 16
DNA_MODULUS = 10 ** DNA_DIGITS

struct :Zombie, name: '', dna: 0

def setup
  @zombies = Array.of( Zombie )
end

# @sig (string, uint) private
def create_zombie( name, dna )
  id = @zombies.push( Zombie.new( name, dna)) - 1
  log NewZombie.new( id, name, dna )
end

# @sig (string) private view returns (uint) 
def generate_random_dna( str )
  rand = hex_to_i( sha256( str ) )
  rand % DNA_MODULUS
end

# @sig (string) public
def create_random_zombie( name ) 
  rand_dna = generate_random_dna( name )
  create_zombie( name, rand_dna )
end

gets cross-compiled to:

contract ZombieFactory {

    event NewZombie(uint zombieId, string name, uint dna);

    uint dnaDigits  = 16;
    uint dnaModulus = 10 ** dnaDigits;

    struct Zombie {
        string name;
        uint dna;
    }

    Zombie[] public zombies;

    function _createZombie(string _name, uint _dna) private {
        uint id = zombies.push(Zombie(_name, _dna)) - 1;
        emit NewZombie(id, _name, _dna);
    } 

    function _generateRandomDna(string _str) private view returns (uint) {
        uint rand = uint(keccak256(abi.encodePacked(_str)));
        return rand % dnaModulus;
    }

    function createRandomZombie(string _name) public {
        uint randDna = _generateRandomDna(_name);
        _createZombie(_name, randDna);
    }
}

Mint Your Own Money - Minimal Viable Token

############################
# My Token Contract

# @sig (uint256) public
def setup( initial_supply )
  @balance_of = Mapping.of( Address => Money )
  @balance_of[ msg.sender] = initial_supply
end

# @sig (address, uint256) public returns (bool)
def transfer( to, value )
  assert @balance_of[ msg.sender ] >= value
  assert @balance_of[ to ] + value >= @balance_of[ to ]

  @balance_of[ msg.sender ] -= value
  @balance_of[ to ]         += value

  true
end

gets cross-compiled to:

contract MyToken {
    mapping (address => uint256) public balanceOf;

    constructor( uint256 _initialSupply ) public {
        balanceOf[msg.sender] = _initialSupply;
    }

    function transfer(address _to, uint256 _value) public returns (bool) {
        require(balanceOf[msg.sender] >= _value);
        require(balanceOf[_to] + _value >= balanceOf[_to]);

        balanceOf[msg.sender] -= _value;
        balanceOf[_to]        += _value;
        
        return true;
    }
}

Note: For now there's no magic type inference for function signatures - you MUST annotate all ruby functions. Example:

# @sig (uint256) public
def setup( initial_supply ) 
  # ...
end

becomes

constructor( uint256 _initialSupply ) public {
  // ...
}

and

# @sig (address, uint256) public returns (bool)
def transfer( to, value )
  # ...
end

becomes

function transfer(address _to, uint256 _value) public returns (bool) {
  // ...
}

and so on and so forth.

License

The (secure) ruby cross-compiler scripts are dedicated to the public domain. Use it as you please with no restrictions whatsoever.

Request for Comments (RFC)

Send your questions and comments to the ruby-talk mailing list. Thanks!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].