Giter VIP home page Giter VIP logo

ethereum / solidity Goto Github PK

View Code? Open in Web Editor NEW
22.3K 719.0 5.5K 72.3 MB

Solidity, the Smart Contract Programming Language

Home Page: https://soliditylang.org

License: GNU General Public License v3.0

C++ 54.99% CMake 0.68% Shell 2.38% Python 2.65% C 0.58% Solidity 33.16% Dockerfile 0.16% JavaScript 0.12% PowerShell 0.03% Yul 5.25%
cpp ethereum smartcontracts language solidity blockchain hacktoberfest programming-language

solidity's Introduction

The Solidity Contract-Oriented Programming Language

Matrix Chat Gitter Chat Solidity Forum X Follow Mastodon Follow

You can talk to us on Gitter and Matrix, tweet at us on X (previously Twitter) or create a new topic in the Solidity forum. Questions, feedback, and suggestions are welcome!

Solidity is a statically typed, contract-oriented, high-level language for implementing smart contracts on the Ethereum platform.

For a good overview and starting point, please check out the official Solidity Language Portal.

Table of Contents

Background

Solidity is a statically-typed curly-braces programming language designed for developing smart contracts that run on the Ethereum Virtual Machine. Smart contracts are programs that are executed inside a peer-to-peer network where nobody has special authority over the execution, and thus they allow anyone to implement tokens of value, ownership, voting, and other kinds of logic.

When deploying contracts, you should use the latest released version of Solidity. This is because breaking changes, as well as new features and bug fixes, are introduced regularly. We currently use a 0.x version number to indicate this fast pace of change.

Build and Install

Instructions about how to build and install the Solidity compiler can be found in the Solidity documentation.

Example

A "Hello World" program in Solidity is of even less use than in other languages, but still:

// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;

contract HelloWorld {
    function helloWorld() external pure returns (string memory) {
        return "Hello, World!";
    }
}

To get started with Solidity, you can use Remix, which is a browser-based IDE. Here are some example contracts:

  1. Voting
  2. Blind Auction
  3. Safe remote purchase
  4. Micropayment Channel

Documentation

The Solidity documentation is hosted using Read the Docs.

Development

Solidity is still under development. Contributions are always welcome! Please follow the Developers Guide if you want to help.

You can find our current feature and bug priorities for forthcoming releases in the projects section.

Maintainers

The Solidity programming language and compiler are open-source community projects governed by a core team. The core team is sponsored by the Ethereum Foundation.

License

Solidity is licensed under GNU General Public License v3.0.

Some third-party code has its own licensing terms.

Security

The security policy may be found here.

solidity's People

Contributors

a3d4 avatar aarlt avatar axic avatar bobsummerwill avatar bshastry avatar cameel avatar chfast avatar chriseth avatar christianparpart avatar cjentzsch avatar debris avatar denton-l avatar ekpyron avatar erak avatar federicobond avatar gavofyork avatar gluk256 avatar hrkrshnn avatar lefterisjp avatar leonardoalt avatar lianahus avatar marenz avatar matheusaaguiar avatar mijovic avatar nikola-matic avatar pirapira avatar r0qs avatar subtly avatar vor0220 avatar winsvega 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  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

solidity's Issues

build failed!

-- Build files have been written to: /home/ubuntu/solidity/build
ubuntu@:~/solidity/build$ make -j2
Scanning dependencies of target solidity
[ 4%] [ 4%] Building CXX object libsolidity/CMakeFiles/solidity.dir/ASTJsonConverter.cpp.o
Building CXX object libsolidity/CMakeFiles/solidity.dir/Version.cpp.o
/home/ubuntu/solidity/libsolidity/Version.cpp:25:23: fatal error: BuildInfo.h: No such file or directory
#include <BuildInfo.h>
^
compilation terminated.
In file included from /home/ubuntu/solidity/libsolidity/../libsolidity/ASTVisitor.h:28:0,
from /home/ubuntu/solidity/libsolidity/../libsolidity/ASTJsonConverter.h:27,
from /home/ubuntu/solidity/libsolidity/ASTJsonConverter.cpp:23:
/home/ubuntu/solidity/libsolidity/../libsolidity/AST.h:30:38: fatal error: libevmasm/SourceLocation.h: No such file or directory
#include <libevmasm/SourceLocation.h>
^
compilation terminated.
make[2]: *** [libsolidity/CMakeFiles/solidity.dir/Version.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [libsolidity/CMakeFiles/solidity.dir/ASTJsonConverter.cpp.o] Error 1
make[1]: *** [libsolidity/CMakeFiles/solidity.dir/all] Error 2
make: *** [all] Error 2

Update build guide for solc 1.2 on OSX

I can't find instructions for setting up the new solidity repo and building 1.2 on OSX (particularly the eth dev cmake environment). Everything in the wiki is outdated.

cmake: could not load file EthOptions

Here is the cmake log error when trying to generate the makefile:

CMake Error at CMakeLists.txt:26 (include):
  include could not find load file:

    EthOptions


CMake Error at CMakeLists.txt:27 (configure_project):
  Unknown CMake command "configure_project".

Any ideas ?

Storage of String in memory

with this:
string pp = "value1";
The DataLocation is indeed Storage, but the content seems to be stored in Memory.

[BUG] Can't set a address[] key to an address.

The following code does not work as expected.

contract testing
{
    function test() public
    {
        address[] players;
        players.length++;
        players[0] = 0xca35b7d915458ef540ade6068dfe2f44e8fa733cr;
    }
}

Response for the browser compiler: Parser error: Expected primary expression.
players[0] = 0xca35b7d915458ef540ade6068dfe2f44e8fa733cr;

Implement bit shifting

@hynese asks:
Anyone know if it's possible to rotate a uint256 by 8 bits? I can't seem to find any suitable operators ;(

(There is no lower level EVM opcode for SHL/SHR/ROR/ROL, I checked. So they must be emulated.)

It would be nice to implement:
https://github.com/ethereum/solidity/blob/develop/libsolidity/ExpressionCompiler.cpp#L1071
or this:
https://github.com/ethereum/solidity/blob/develop/libsolidity/ExpressionCompiler.cpp#L1067

Using this: (and testing, of course!)
Shifting left by N is equivalent to multiplying by 2^N.
Shifting right by N is (if you are using ones' complement) is the equivalent of dividing by 2^N and rounding to zero.
source: https://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift

SHL(input, bits) = input * (2^bits)
SHR(input, bits) = input / (2^bits) (then round to zero?)
Wikipedia has some code describing how to do rotate using shift, this is probably the most optimal way: https://en.wikipedia.org/wiki/Circular_shift#Implementing_circular_shifts
http://stackoverflow.com/questions/2835469/how-to-perform-rotate-shift-in-c#answer-2835503

(This also has applications for some cryptographic code, although such code is probably optimized by not using an emulated rotate/shift, it would simplify the logic of it.)

address of created contract

Tutorial has:

contract TokenCreator {
  function createToken(bytes32 name) returns (address tokenAddress) {
    // Create a new Token contract and return its address.
    return address(new OwnedToken(name));
  }

how does createToken work? creating a contract requires eth_sendTransaction, but transactions don't have return values...

Eth_DEVCORE_LIBRARY NOTFOUND

on aad59bd

in build dir, running cmake .. gives:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
Eth_DEVCORE_LIBRARY

strings concatenation

hi, is there strings concatenation? because I was need to return an array but it does not support internal types for return!

web3 compiler stop working with solc version 0.1.2

Not sure the appropriated repo to post this so I'm posting to both web3 and here. Upgrading solc from 0.1.1 to 0.1.2 makes the web3 compiler stop working with the message solc: no build results found. The solc command line options changed a lot from 0.1.1 to 0.1.2 and that's probably the reason. Downgrading solc to 0.1.1 solved the issue. I'm using Ubuntu 15.04.

solc generating different evm code in OSX than in Ubuntu

Deploying the code generated in OSX does not work either (resulting address getCode is 0x0), while the Ubuntu one works fine.

Binary generated in OSX (0.1.2-5c3bfd4b)
606060405260405160208060f68339016040526060805190602001505b806000600050819055505b5060c28060346000396000f360606040526000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd914604b57806360fe47b114606a5780636d4ce63c14607b576049565b005b6054600450609a565b6040518082815260200191505060405180910390f35b607960048035906020015060a3565b005b608460045060b1565b6040518082815260200191505060405180910390f35b60006000505481565b806000600050819055505b50565b6000600060005054905060bf565b9056

Binary geneated in Ubuntu (0.1.2-0)
606060405260405160208060f78339016040526060805190602001505b806000600050819055505b5060c28060356000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd914604b57806360fe47b114606a5780636d4ce63c14607b576049565b005b6054600450609a565b6040518082815260200191505060405180910390f35b607960048035906020015060a3565b005b608460045060b1565b6040518082815260200191505060405180910390f35b60006000505481565b806000600050819055505b50565b6000600060005054905060bf565b9056

Converting bytes32 to int always returning 0

Not sure if I this is a bug or I misunderstand how it should work, but the following function returns 0 for all blocks

block.blockhash(blockIndex) returns a bytes32 so I was expecting a uint256

function getHashOfBlock(uint blockIndex) constant returns(uint){
    return uint(block.blockhash(blockIndex));
}

Too many indexed arguments compiler error

If too many indexed arguments are used in an event, an internal compiler error is reported with a dev tag of Too Many indexed arguments rather than a regular error report.

Additionally, no error is reported if the event isn't referenced but is in the code.

Future: mapping iteration

is it possible to iterate over mapping as in Java?also it would be great if I could know size of the mapping.

modifier return values

Request for modifiers to be able return a value. Specifically, this allows modifiers to be used on functions which have return codes.

Setting array.length in a contract storing an msg.sender address creates an infinite loop

Setting array.length in a contract storing an msg.sender address creates an infinite loop.

Minimal reproducible contract:

contract c {

    address a;

    function d() {
        a = msg.sender;
    }

    function test() returns (int) {
        int[] accessList;
        accessList.length = 1;
        return 1;
    }
}

Steps:

  • create contract c
  • call test, see that it returns 1.
  • call d.
  • call test, again see that it is stuck in an infinite loop.

Additional steps:

  • edit d() to set a to any other value. recompile.
  • verify that the infinite loop does not occur.

Version: 0.1.1-34172c3b/RelWithDebInfo-Emscripten/clang/int

intX, X != 256 not converted from internal representation when returned?

Tried with web compiler today, and latest dev ubuntu PPA version (as of 3 days ago). This may be an error. First: If I use uint128, for example, and i set it to 1, the output will be 000...001.

contract Property {
  uint128 public intVal;
  function Property() {
    intVal = 1;
   }
}

Output:

{ value: '0000000000000000000000000000000000000000000000000000000000000001',
  offset: undefined }

In the case of int128.

contract Property {
  int128 public intVal;
  function Property() {
    intVal = 1;
   }
}

Output:

{ value: 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF80000000000000000000000000000000',
  offset: undefined }

Not using the current VM but I see in the assembly output that the values are being converted in the Property function - both in the case of int's and uint's, but i only see the back conversion in the getter function when it's uint's.

"bytes32 constant x" causes disturbance in the stack.

contract BytesConstError {
    bytes32 constant x = "test";

    function (){
        g(x);
    }

    function g(bytes32 arg){}
}
Internal compiler error: I sense a disturbance in the stack.

Tested in latest browser compiler and: 0.1.1-0/Release-Linux/g++/int. Removing constant fixes, or just using a literal.

No support for int[][] (string[], etc.) function parameters.

function f3(string[2] ss) {} results in compiler error:

Type error: Internal type is not allowed for public and external functions.
    function f3(string[2] ss) {
                ^----------^

Looks like the ABI supports this, but the Solidity compiler doesn't

improve an error msg. Wrong location.

    contract ClientReceipt {
        bytes32 x = 0xFFFFFFFF;
        function deposit() returns (uint x1) {
            return int(x);
        }
    }

result in
:4:12: Type error: Type int256 is not implicitly convertible to expected type uint256.
return int(x);
^----^

Build errors on Ubuntu 14.04

Recently did a fresh pull and tried to re-build my copy of solc. Got this error:

c++: error: unrecognized command line option ‘-fstack-protector-strong’

So I updated to gcc-4.9, per a suggestion on StackOverflow and now I get:

In file included from /home/ryepdx/Code/cpp/solidity/test/contracts/Wallet.cpp:27:0:
/home/ryepdx/Code/cpp/solidity/./test/libsolidity/solidityExecutionFramework.h: In static member function ‘static dev::bytes dev::solidity::test::ExecutionFramework::encode(byte)’:
/home/ryepdx/Code/cpp/solidity/./test/libsolidity/solidityExecutionFramework.h:137:15: error: stack protector not protecting function: all local arrays are less than 4 bytes long [-Werror=stack-protector]
  static bytes encode(byte _value) { return bytes(31, 0) + bytes{_value}; }
               ^
cc1plus: all warnings being treated as errors
make[2]: *** [test/CMakeFiles/test.dir/contracts/Wallet.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /home/ryepdx/Code/cpp/solidity/test/contracts/AuctionRegistrar.cpp:28:0:
/home/ryepdx/Code/cpp/solidity/./test/libsolidity/solidityExecutionFramework.h: In static member function ‘static dev::bytes dev::solidity::test::ExecutionFramework::encode(byte)’:
/home/ryepdx/Code/cpp/solidity/./test/libsolidity/solidityExecutionFramework.h:137:15: error: stack protector not protecting function: all local arrays are less than 4 bytes long [-Werror=stack-protector]
  static bytes encode(byte _value) { return bytes(31, 0) + bytes{_value}; }
               ^
cc1plus: all warnings being treated as errors
make[2]: *** [test/CMakeFiles/test.dir/contracts/AuctionRegistrar.cpp.o] Error 1
make[1]: *** [test/CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2

Multiply return values not supported.

solc compiles the following:

    function ret() returns (int a, int b) { 
        a = 1;
        b = 2;
    }

But no ways to get both a and b from return data. That feature would be very handy in absence of Struct returns.

Creating a contract from within itself is not caught properly

Creating a contract from within itself is not possible since it would have to include its own code:

contract C { function f() { var x = new C(); } }

(there might be workarounds to make this possible, but we do not allow it for now)

The error, though, is not caught at the analysis phase, but only at code generation phase and results in an internal compiler error.

modifier overloading

It should be possible to declare different modifiers with the same name but different argument types, as it is possible for functions.

For example:

contract C {
  modifier m(uint a) { _; }
  modifier m(bytes b) { _; }
  modifier m(uint a, bytes b) { _; }
}

Typo in project title

The project title The Solidity Contract-Oriented Programming Langauge
Nitpicker: should be Language instead of Langauge
(sorry, don't know a better place to suggest this)

[BUG] Struct arrays set the first element's first component to the array length.

When creating a struct array, the first element of the array will have the first component of the struct set to the length of the struct array.

contract test
{
    struct leader
    {
        uint256 winnings;
        address player;
    }

    leader[10] private leaderboard;

    /**
     * Get a list of leaders.
     * 
     * @return playersList address[]   The list of player addresses
     */
    function getLeaders() public constant returns(uint256[])
    {
        uint256 leaderboardLength = leaderboard.length;

        uint256[] winnings;
        winnings.length = leaderboardLength;

        for (uint8 i = 0; i < leaderboardLength; ++i) {
            winnings[i] = leaderboard[i].winnings;
        }

        return winnings;
    }
}

The browser compiler says: Returned: ["10","0","0","0","0","0","0","0","0","0"]

"player" from the struct is unaffected. Try reversing the components of the struct, then run the script. the result is: Returned: ["0","0","0","0","0","0","0","0","0","0"]. However, "player" will then have 0x000000000000000000000000000000000000000a as the first address. (10 in hex)

EDIT
I've also tested what happens when setting the first item in the struct to something other than a 10 value. When changing that first element, it causes the compiler to crash, though when it's set to the 10 value, then it will function normally. After the "crash" the browser compiler reports the following in the console.

Uncaught BigNumber Error: new BigNumber() not a base 16 number:

Get storage location of variable

The new "libraries" feature will not be very useful if we cannot give the library information about what is where in storage.

contract Example {
    address A;
    function update(Library L) {
        L.get_latest(&A);
    }
}

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.