43

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 that is similar to the original source code but that is very complicated, especially when the optimizer was used during compilation. I don't know of any tools ...


30

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 the bytecode. So the match you should check is the compiled bytecode against the data of the contract creation tx.


29

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 untitled_testContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"value","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"...


28

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


16

To add to @thomas-bertani's answer, today etherchain.org released a verification tool for Ethereum contracts Here's the quoted text from the How does it work page: Retrieve the payload of the transaction that created the contract Compile the provided source code with the provided compiler & settings If the creation and the provided bytecode ...


14

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. An example, taken from my own (modified) code: var linkedMetaCoinCode = metaCoinBytecode.replace( /_+TestLib_+/g, testLib.address.replace("0x", "") ); ...


10

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 can just load the string literal into memory as the entirety of the return value. So, it loads the string into memory, uses the identity function to memcpy it ...


10

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 one. I've never got into the detail of this PUSH1 0x6 DUP1 Push 2 values of 0x6 into the stack. One is to be used as a parameter to CODECOPY, ...


10

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 resulting bytecode does NOT match with the bytecode that is stored on the address. The reason for that is that the compiled contract does contain an ...


10

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 with / as directory separator, . as the current and .. as the parent directory. Path names that do not start with . are treated as absolute paths. To import a ...


9

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') Paste this statement into the geth console. Your code will be loaded and your contract will be deployed automatically. There are also a few helper functions ...


8

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 uint8 here */ ; var ballotContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"to","type":"address"}],"name":"delegate","outputs":[],"type":"...


8

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: array access out of bounds failed sub-call (due to any reason reported by the EVM including invalid jump dest in the sub-call) ether sent to a library fallback ...


8

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 given to the function "call". CALLDATALOAD is the function signature which is calculated as web3.sha3('call(address)').substr(0,10) where "call" is the name of ...


7

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 concept. The (init code of the) blank contract copies the final contract code from code into memory and then returns that. Both the final contract code and ...


7

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 some information on how http://etherchain.org checks the contract source code against the contract bytecode at How can I verify that a contract on the blockchain ...


7

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 returns the blockchain code, but as part of the execution also initializes the contract being deployed. For your contract, look at its transaction 1 and you ...


6

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 should choose the same compiler and to enable or disable the optimimsation.


6

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) returns (uint ) { return ((a + m - 1) / m) * m; } } And testing for the correct results: > ceil.ceil(123456, 1000) 124000 > ceil.ceil(1,...


6

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 the execution of a contract. The CALLDATALOAD (with argument 0x00 (on the stack)) gets the input data for the method call onto the stack. The first input data ...


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 soliditySource.sol To generate ABI: > solc --abi soliditySource.sol Then, with your newly generated bytecode and abi, in geth 1.6: var abi = <abi ...


5

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: error: "invalid jump destination (PUSH1) 2" (Somewhat Related) Stack Limit Reached 1024 Not what was asked in the question, but interesting anyway. contract ...


5

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/


5

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 blockchain explorers as the compiled source will have to match the deployed code. You may want to consider deploying your contracts on the Mainnet or Testnet ...


5

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 not the case, please report a bug.


5

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.


5

I solved my problem by RTFM. Mac users should install using Homebrew. From Installing Solidity brew update brew upgrade brew tap ethereum/ethereum brew install solidity brew linkapps solidity If you need a specific version of Solidity you can install a Homebrew formula directly from Github.


4

It turns out that in solidity, you can't go passing around strings from contract to contract. When I removed the two string values my code compiled without a hitch.


4

According to this, solc does not allow to import from github directly. You need to clone the repo and remap the directory path to be able to use them like in browser-solidity.


4

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 function - one which returns (uint256) to be specific - to a uint called attribut, when what you need to do is call that function, and assign the result of ...


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