51 votes
Accepted

How can you decompile a smart contract?

Compilation back to the original source code is impossible because all variable names, type names and even function names are removed. It might be technically possible to arrive at some source code ...
user avatar
  • 3,162
39 votes
Accepted

How can I verify that a contract on the blockchain matches the source code?

AFAIK the best way to do this at the moment is to compile the source code again with the exact same compiler version the author used (so this is something that needs to be disclosed) and to compare ...
user avatar
32 votes
Accepted

What are the steps to compile and deploy a library in Solidity?

First, let's save both of those files in the same directory and run solc --optimize --bin MetaCoin.sol. The output is: ======= MetaCoin ======= Binary: ...
user avatar
29 votes
Accepted

How to compile Solidity contracts with Geth v1.6?

Alternative 1 - Use Remix To Compile, Then Copy-Paste To Deploy Use Remix from https://ethereum.github.io/browser-solidity: Copy the Web3 deployment instructions from the Remix page: var ...
user avatar
19 votes

How can I verify that a contract on the blockchain matches the source code?

To add to @thomas-bertani's answer, today etherchain.org released a verification tool for Ethereum contracts Here's the text from the page: Source code verification provides transparency for users ...
user avatar
  • 2,321
16 votes

What are the steps to compile and deploy a library in Solidity?

To add, it's possible to manually link contracts (if you wish to deploy both library and contract together.) The simplest way is just to replace all occurrences of the placeholders with the address. ...
user avatar
13 votes
Accepted

Bytecode on block chain different from the one used when deploying

Yes, it is normal and the code on the blockchain is always a subset of the compiled (byte)code, because the compiled code includes initialization code. The compiled code is/executes a function which ...
user avatar
  • 78.3k
12 votes

How can I verify that a contract on the blockchain matches the source code?

Currently the workflow is quite annoying. You need to compile the contract with the same compiler version and the same setting (look out for the "optimization=true" flag). Now please note that the ...
user avatar
  • 7,216
11 votes

Why does a simple function returning a 'string', call another contract?

On discussing with the Solidity devs on Gitter, this is made clear: Solidity uses the identity function as a cheap memcpy operation, and the optimizer isn't currently clever enough to realise that it ...
user avatar
  • 7,579
11 votes
Accepted

What is the cheapest way to roundup() or ceil() to multiple of 1000?

Here's one solution: contract Ceil { function ceil(uint a, uint m) constant returns (uint ) { return ((a + m - 1) / m) * m; } // To measure gas function ceil1(uint a, uint m) ...
user avatar
10 votes

What does bytecode of blank contract do?

A user on Reddit kindly posted an opcode-by-opcode analysis for you: PUSH1 0x60 PUSH1 0x40 MSTORE Store 0x60 at memory location 0x40. I think this is normally used for variable indexing if you have ...
user avatar
  • 34.2k
10 votes
Accepted

How should we set a import path in solidity?

Files and paths are explained in detail here: http://solidity.readthedocs.org/en/latest/layout-of-source-files.html Key points: Paths In import "filename";, filename is always treated as a path ...
user avatar
  • 15.2k
10 votes
Accepted

Why does compiled solidity code do this check on the argument with which it was called?

Code execution in EVM always starts with PC=0. So the method you have called is jumped to in a switch-like code segment in the beginning of the bytecode of the EVM. CALLDATALOAD is not the argument ...
user avatar
10 votes
Accepted

Status of ABIEncoderV2 now

Update 2020 (#2) As of Solidity 0.6.0, ABIEncoderV2 is no longer experimental. Update 2020 (#1) An update from the Solidity team reads: We are almost finished with implementing breaking changes and ...
user avatar
9 votes
Accepted

How to load Solidity source file into geth

I found this Solidity Compile Helper ruby wrapper Usage solc_helper contract.sol This will generate a javascript file and print out a statement like the following. loadScript('/path/contract.js') ...
user avatar
  • 9,343
9 votes
Accepted

All cases when Solidity compiles to invalid jump destination

Jumps to invalid jump destinations are generated only for (explicit or implicit) exceptions. An explicit exception is when you use the keyword throw. Implicit exceptions happen for runtime errors: ...
user avatar
  • 3,162
9 votes
Accepted

What is the program counter at the start of an Ethereum method execution?

The program counter is always 0 at the beginning of an execution. The contract sets the program counter to match the correct method call through a switch statement (a jump table) at the beginning of ...
user avatar
8 votes
Accepted

Can I compile a smart contract without removing the line breaks?

My advice would be to use the Browser Solidity: Just copy paste your contract, and if it compiles without errors you can just copy past the content of Web3 deploy: var _numProposals = /* var of type ...
user avatar
  • 2,262
7 votes

How can I verify that a contract on the blockchain matches the source code?

https://etherscan.io/verifyContract is a verification tool. By providing the Solidity Source Code it checks if the generated Bytecode matches to the contract Bytecode (under the given address). user ...
user avatar
  • 17.5k
7 votes
Accepted

What does bytecode of blank contract do?

The "data" section mentioned in the yellow paper is the part that follows the PUSH instruction, i.e. the yellow paper only talks about push data. What you see in the assembly output is a higher-level ...
user avatar
  • 3,162
7 votes
Accepted

Is there a way to detect which compiler version produced a contract binary?

No, as there is no difference in the output of the bytecode from the simple contract Test {} plugged into Browser-solidity when using different recent versions of the Solidity compiler. There is ...
user avatar
7 votes
Accepted

Is the Solidity compiler deterministic?

At least it should be deterministic. We eliminated some sources of non-determinism in May, so it now should always produce the same result on the same input, even on different platforms. If that is ...
user avatar
  • 3,162
7 votes

How to compile Solidity contracts with Geth v1.6?

I've encountered the same issue recently. There are a variety of workarounds, but here is the method I've employed. This isn't necessarily the best approach. To generate bytecode: > solc --bin ...
user avatar
  • 586
6 votes

All cases when Solidity compiles to invalid jump destination

Array Out Of Bounds contract InvalidJump { uint[5] data; function invalidJump1() { uint i = 6000; data[i] = 1; } } And the message is from debug.traceTransaction(...) is: ...
user avatar
6 votes

How can you decompile a smart contract?

There is a project Porosity now https://github.com/comaeio/porosity It's also integrated into Quorum toolchain https://www.coindesk.com/first-ethereum-decompiler-launches-jp-morgan-quorum-integration/
user avatar
  • 161
6 votes
Accepted

returns (uint256) is not implicitly convertible to expected type uint256

Try adding a pair of brackets after gas(800): feed.info.value(10).gas(800) becomes feed.info.value(10).gas(800)() What the error message is trying to tell you is that you're telling it to assign a ...
user avatar
  • 16.3k
6 votes

What is the program counter at the start of an Ethereum method execution?

Illustrating more of @Thorkil's answer. Example A very rough example, for conceptual purposes only, of the "switch-like statement at the beginning of the contract". method_id = first 4 bytes ...
user avatar
  • 78.3k
5 votes

How to load Solidity source file into geth

Update Jan 3 2017 Note that Solidity 4.7 compiler makes different code for the same contract when you have different whitespacing. This will be important when you try to add verified sources in the ...
user avatar
5 votes
Accepted

How are the arguments of the constructor encoded in the contract creation transaction?

According to the Ethereum Yellow Paper (section 4.2), the contract creation transaction does not have a data byte array where the arguments to method calls are placed. The contract creation only has ...
user avatar
5 votes

Require in modifier: Undeclared identifier

require is available since Solidity 0.4.10: https://github.com/ethereum/solidity/releases Since your pragma requires an older Solidity version this leads to a compiler error.
user avatar
  • 8,114

Only top scored, non community-wiki answers of a minimum length are eligible