Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: Unknown option --bin #18

Open
chusanchen opened this issue Dec 29, 2020 · 12 comments
Open

ERROR: Unknown option --bin #18

chusanchen opened this issue Dec 29, 2020 · 12 comments

Comments

@chusanchen
Copy link

chusanchen commented Dec 29, 2020

Hello, dear author:
I had this problem:
$ solc --bin test1.sol | tail -n1 > test1.code
ERROR: Unknown option --bin

I think my Solc is installed correctly
When I enter this command $ solc -help
Ubuntu will be displayed
Usage:
solc [OPTIONS] [ARGS]

Options:
--out-dir [PATH] Output directory for the compiled contracts (Default is ./contracts)
--optimise If present activate the solc optimiser
-k, --no-color Omit color from output
--debug Show debug information
-h, --help Display help and usage details

@chusanchen
Copy link
Author

Can i use command $ solcjs --bin test1.sol | tail -n1 > test1.code to replace $ solc --bin test1.sol | tail -n1 > test1.code

@nescio007
Copy link
Owner

Hi,

solc if installed correctly should have a --bin option (see https://docs.soliditylang.org/en/latest/using-the-compiler.html).

The solcjs command line tool available from npm appears to be incompatible:

The commandline options of solcjs are not compatible with solc and tools (such as geth) expecting the behaviour of solc will not work with solcjs.

(Quote from https://docs.soliditylang.org/en/latest/installing-solidity.html#solcjs)

If all else fails, Solidity does provide statically linked binaries for most versions at https://github.com/ethereum/solidity/releases which should work out-of-the-box.

Please note that for our experiments we used Solidity v0.4.9 (see also #17), and that some of the examples might not work with a newer version of Solidity.

@chusanchen
Copy link
Author

Hi dear author
Now my solc version is 0.4.9 and solc can --bin
but When I execute $ solc --bin test.sol | tail -n1 > test.code
the error is: test.sol:27:9: Error: Undeclared identifier.
require(owner == msg.sender);
^-----^

and the content of test.sol is :
pragma solidity ^0.4.0;

contract Test{

struct Transaction{
    address to;
    uint amount;
}

mapping (bytes32 => Transaction) transactions;

address owner;

function set_owner(address new_owner){
    owner = new_owner;
}

function new_transaction(address to, uint amount) returns (bytes32){
    bytes32 token = sha3(to, amount);
    Transaction storage t = transactions[token];
    t.to = to;
    t.amount += amount;
    return token;
}

function approve(bytes32 token){
    require(owner == msg.sender);
    Transaction storage t = transactions[token];
    t.to.transfer(t.amount);
    delete transactions[token];
}

}

@nescio007
Copy link
Owner

Apologies, apparently my notes were incorrect, require was only introduced with v0.4.10 (and the contract compiles well with v0.4.11):

docker run -ti ethereum/solc:0.4.11 --bin -
pragma solidity ^0.4.0;

contract Test{

struct Transaction{
    address to;
    uint amount;
}

mapping (bytes32 => Transaction) transactions;

address owner;

function set_owner(address new_owner){
    owner = new_owner;
}

function new_transaction(address to, uint amount) returns (bytes32){
    bytes32 token = sha3(to, amount);
    Transaction storage t = transactions[token];
    t.to = to;
    t.amount += amount;
    return token;
}

function approve(bytes32 token){
    require(owner == msg.sender);
    Transaction storage t = transactions[token];
    t.to.transfer(t.amount);
    delete transactions[token];
}

}

======= <stdin>:Test =======
Binary: 
6060604052341561000c57fe5b5b61038d8061001c6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630129ab27146100515780637cb97b2b146100ac578063a53a1adf146100e2575bfe5b341561005957fe5b61008e600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610106565b60405180826000191660001916815260200191505060405180910390f35b34156100b457fe5b6100e0600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506101e5565b005b34156100ea57fe5b61010460048080356000191690602001909190505061022a565b005b6000600060008484604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c0100000000000000000000000002815260140182815260200192505050604051809103902091506000600083600019166000191681526020019081526020016000209050848160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508381600101600082825401925050819055508192505b505092915050565b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b50565b60003373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415156102895760006000fd5b60006000836000191660001916815260200190815260200160002090508060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc82600101549081150290604051809050600060405180830381858888f19350505050151561030e57fe5b60006000836000191660001916815260200190815260200160002060006000820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600182016000905550505b50505600a165627a7a723058206776bc2068e267b0908718b2a400bc9e6a8b2b5542a6505c1a171da3ec16c6810029

@chusanchen
Copy link
Author

Hi dear author
when i execute $ python bin/gen_exploit.py test.contract.code 0x1234 0x1000 +1000
and the result is :
INFO:root:Finished all paths
INFO:root:Finished all paths
INFO:root:Finished all paths
INFO:root:Found 1 CALL instructions
INFO:root:Finished all paths
INFO:root:CALL: ( 769) 301: f1 -7 +1 = -6 CALL
INFO:root:Path: 0->39->44->e2->ea->22a->289->301
INFO:root:No DELEGATECALL instructions
INFO:root:No CALLCODE instructions
INFO:root:No SELFDESTRUCT instructions
INFO:root:Found 3 RETURN and STOP instructions
INFO:root:End: ( 171) ab: f3 -2 +0 = -2 RETURN
INFO:root:Path: 0->51->59->106->1dd->8e->ab
INFO:root:End: ( 225) e1: 00 -0 +0 = 0 STOP
INFO:root:Path: 0->39->ac->b4->1e5->227->e0->e1
INFO:root:Calling contract 1461501637330902918203684832716283019655932542975 &
1461501637330902918203684832716283019655932542975 &
UDiv(STORAGE_3[SHA3_5d_3], 1) (136_3)
INFO:root:End: ( 261) 105: 00 -0 +0 = 0 STOP
INFO:root:Path: 0->39->44->e2->ea->22a->289->30e->35d->104->105
INFO:root:All ends: [<teether.evm.results.SymbolicResult object at 0x7fd24ed197f0>, <teether.evm.results.SymbolicResult object at 0x7fd24ec550a0>, <teether.evm.results.SymbolicResult object at 0x7fd24ec554f0>]
INFO:root:Could not exploit any RETURN+CALL
Did I finish and succeed in this experiment?

@nescio007
Copy link
Owner

Hi @chusanchen,

unfortunately no, teEther should be able to find an exploit for the example.
I suspect it is an issue with the interface to z3. Could you post the version of z3 you were using? I'll then check whether I can recreate the problem.

@chusanchen
Copy link
Author

chusanchen commented Jun 7, 2021 via email

@nescio007
Copy link
Owner

Hi,

if you installed z3-solver using pip you can use

pip freeze | grep z3

Otherwise, z3.get_version_string() works from within python:

python -c 'import z3;print(z3.get_version_string())'

@chusanchen
Copy link
Author

chusanchen commented Jun 7, 2021 via email

@chusanchen
Copy link
Author

chusanchen commented Jun 7, 2021 via email

@nescio007
Copy link
Owner

Sorry, it's easy to forget that python3 is not the default for everyone yet :)
Thanks for posting your z3 version, I'll see whether I can recreate your issues.

In the meantime, could you try to downgrade your z3 to version 4.8.5?

pip install z3-solver==4.8.5.0

@chusanchen
Copy link
Author

chusanchen commented Jun 7, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants