benjaminion / LLL_docs

Documentation for the Ethereum LLL compiler
11 stars 1 forks source link

Installation - `make` returns `cc1plus: all warnings being treated as errors` from `-Werror=range-loop-construct` #2

Closed MarcusWentz closed 1 year ago

MarcusWentz commented 1 year ago

When following guide https://www.youtube.com/watch?v=4qbJFpT1ecI with Solidity snapshot repo with LLL https://github.com/winsvega/lllc with new steps: https://github.com/benjaminion/LLL_docs/pull/1 I get error:

34%] Building CXX object libyul/CMakeFiles/yul.dir/optimiser/NameCollector.cpp.o
/home/marcuswentz/lllc/libyul/optimiser/NameCollector.cpp: In member function ‘virtual void yul::NameCollector::operator()(const yul::FunctionDefinition&)’:
/home/marcuswentz/lllc/libyul/optimiser/NameCollector.cpp:38:25: error: loop variable ‘arg’ creates a copy from type ‘const yul::TypedName’ [-Werror=range-loop-construct]
   38 |         for (auto const arg: _funDef.parameters)
      |                         ^~~
/home/marcuswentz/lllc/libyul/optimiser/NameCollector.cpp:38:25: note: use reference type to prevent copying
   38 |         for (auto const arg: _funDef.parameters)
      |                         ^~~
      |                         &
/home/marcuswentz/lllc/libyul/optimiser/NameCollector.cpp:40:25: error: loop variable ‘ret’ creates a copy from type ‘const yul::TypedName’ [-Werror=range-loop-construct]
   40 |         for (auto const ret: _funDef.returnVariables)
      |                         ^~~
/home/marcuswentz/lllc/libyul/optimiser/NameCollector.cpp:40:25: note: use reference type to prevent copying
   40 |         for (auto const ret: _funDef.returnVariables)
      |                         ^~~
      |                         &
cc1plus: all warnings being treated as errors
make[2]: *** [libyul/CMakeFiles/yul.dir/build.make:832: libyul/CMakeFiles/yul.dir/optimiser/NameCollector.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:451: libyul/CMakeFiles/yul.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

I tried

make -w

to bypass these errors but get the same result.

Note:

I did

git clone https://github.com/winsvega/lllc

instead of

git clone --recursive https://github.com/winsvega/lllc

but get the same error.

MarcusWentz commented 1 year ago

I am able to compile some basic LLL smart contracts in Retesteth.

However, the syntax seems different and doesn't compile the erc20.lll example https://github.com/benjaminion/LLL_erc20/blob/master/erc20.lll and it seems difficult to setup function macros with LLL in Retesteth (could not find a simple working example).

Running

sudo apt-get install --yes libboost-filesystem-dev libboost-system-dev libboost-program-options-dev libboost-test-dev
sudo git clone --depth 1 -b master https://github.com/winsvega/solidity.git /solidity
sudo mkdir /build && cd /build
sudo cmake /solidity -DCMAKE_BUILD_TYPE=Release -DLLL=1 
sudo make lllc
cp /build/lllc/lllc /bin/lllc

from this guide:

https://github.com/ethereum/retesteth#lllc-to-compile-lll-basic-code-in-the-test-fillers

but when I run

sudo make lllc

I get error

[ 92%] Building CXX object liblll/CMakeFiles/lll.dir/Parser.cpp.o
/solidity/liblll/Parser.cpp: In function ‘void dev::lll::debugOutAST(std::ostream&, const boost::spirit::utree&)’:
/solidity/liblll/Parser.cpp:70:56: error: ambiguous overload for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘boost::spirit::basic_string<boost::iterator_range<const char*>, boost::spirit::utree_type::string_type>’)
   70 |         case sp::utree_type::string_type: _out << "\"" << _this.get<sp::basic_string<boost::iterator_range<char const*>, sp::utree_type::string_type>>() << "\""; break;
      |                                           ~~~~~~~~~~~~ ^~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                |                                                                                                      |
      |                                                std::basic_ostream<char>                                                                               boost::spirit::basic_string<boost::iterator_range<const char*>, boost::spirit::utree_type::string_type>
In file included from /usr/include/boost/exception/detail/is_output_streamable.hpp:9,
                 from /usr/include/boost/exception/to_string.hpp:10,
                 from /usr/include/boost/exception/to_string_stub.hpp:9,
                 from /usr/include/boost/exception/info.hpp:11,
                 from /solidity/libdevcore/Exceptions.h:21,
                 from /solidity/liblll/Exceptions.h:24,
                 from /solidity/liblll/Parser.h:24,
                 from /solidity/liblll/Parser.cpp:22:
/usr/include/c++/11/ostream:174:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  174 |       operator<<(bool __n)
      |       ^~~~~~~~
In file included from /usr/include/boost/spirit/home/support/utree.hpp:16,
                 from /usr/include/boost/spirit/include/support_utree.hpp:16,
                 from /solidity/liblll/Parser.cpp:32:
/usr/include/boost/spirit/home/support/utree/operators.hpp:507:26: note: candidate: ‘std::ostream& boost::spirit::operator<<(std::ostream&, const boost::spirit::utree&)’
  507 |     inline std::ostream& operator<<(std::ostream& out, utree const& x)
      |                          ^~~~~~~~
/solidity/liblll/Parser.cpp:71:48: error: ambiguous overload for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘boost::spirit::basic_string<boost::iterator_range<const char*>, boost::spirit::utree_type::symbol_type>’)
   71 |         case sp::utree_type::symbol_type: _out << _this.get<sp::basic_string<boost::iterator_range<char const*>, sp::utree_type::symbol_type>>(); break;
      |                                           ~~~~ ^~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                           |                                                                                                   |
      |                                           std::ostream {aka std::basic_ostream<char>}                                                         boost::spirit::basic_string<boost::iterator_range<const char*>, boost::spirit::utree_type::symbol_type>
In file included from /usr/include/boost/exception/detail/is_output_streamable.hpp:9,
                 from /usr/include/boost/exception/to_string.hpp:10,
                 from /usr/include/boost/exception/to_string_stub.hpp:9,
                 from /usr/include/boost/exception/info.hpp:11,
                 from /solidity/libdevcore/Exceptions.h:21,
                 from /solidity/liblll/Exceptions.h:24,
                 from /solidity/liblll/Parser.h:24,
                 from /solidity/liblll/Parser.cpp:22:
/usr/include/c++/11/ostream:174:7: note: candidate: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]’
  174 |       operator<<(bool __n)
      |       ^~~~~~~~
In file included from /usr/include/boost/spirit/home/support/utree.hpp:16,
                 from /usr/include/boost/spirit/include/support_utree.hpp:16,
                 from /solidity/liblll/Parser.cpp:32:
/usr/include/boost/spirit/home/support/utree/operators.hpp:507:26: note: candidate: ‘std::ostream& boost::spirit::operator<<(std::ostream&, const boost::spirit::utree&)’
  507 |     inline std::ostream& operator<<(std::ostream& out, utree const& x)
      |                          ^~~~~~~~
make[3]: *** [liblll/CMakeFiles/lll.dir/build.make:118: liblll/CMakeFiles/lll.dir/Parser.cpp.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:607: liblll/CMakeFiles/lll.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:643: lllc/CMakeFiles/lllc.dir/rule] Error 2
make: *** [Makefile:300: lllc] Error 2
MarcusWentz commented 1 year ago

When I run

gcc --version

I get

gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0
MarcusWentz commented 1 year ago

I will try

auto const&

for https://github.com/benjaminion/LLL_docs/issues/2#issue-1794654070

MarcusWentz commented 1 year ago

Potential fix with: https://github.com/MarcusWentz/lllc/tree/makeBugFix pull request: https://github.com/winsvega/lllc/pull/11

MarcusWentz commented 1 year ago

Compilation goes through with this patch https://github.com/winsvega/lllc/pull/11.

Clone branch with

git clone -b makeBugFix git@github.com:MarcusWentz/lllc.git

Solidity is detected, but not LLL.

I will try this to detect LLL:

cmake .. -DLLLC=1 
MarcusWentz commented 1 year ago

Works with Retesteth now by following these steps:

  1. Download the latest Retesteth version https://ethereum-tests.readthedocs.io/en/latest/retesteth-tutorial.html#using-the-latest-version

  2. After building the docker image, download the raw erc20.lll file and compile the smart contract with lllc by running

    cd
    cd ~/retestethBuild
    wget https://raw.githubusercontent.com/benjaminion/LLL_erc20/18cfbd32a08ec525668ee57533779903e2717b12/erc20.lll
    sudo ./dretesteth.sh lllc --testpath /home/marcuswentz/retestethBuild/ erc20.lll

    you should get the generated bytecode in the terminal

    341561000b5760006000fd5b606433556103758061001f6000396000f300fe341561000b5760006000fd5b600060005260046000601c600001376306fdde036000511415610047576020600052601f80610356604039602052601f19605f60205101166000f35b6395d89b416000511415610074576020600052600380610353604039602052601f19605f60205101166000f35b63313ce567600051141561008d57600060005260206000f35b6318160ddd60005114156100a657606460005260206000f35b6370a0823160005114156100c1576004355460005260206000f35b63a9059cbb600051141561017257366044146100dd5760006000fd5b60a060020a60043504156100f15760006000fd5b606460243511156101025760006000fd5b6024351561016757335460205260205160243511156101215760006000fd5b602435602051033355602435600435540160043555602435602052600435337fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60206020a35b600160005260206000f35b6323b872dd6000511415610272573660641461018e5760006000fd5b60a060020a60043504156101a25760006000fd5b60a060020a60243504156101b65760006000fd5b606460443511156101c75760006000fd5b60443515610267576004355460205233600052602060002060043501546040526001602051604435116101fd5750604051604435115b156102085760006000fd5b60443560205103600435556044356024355401602435556044356040510333600052602060002060043501556044356020526024356004357fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60206020a35b600160005260206000f35b63095ea7b36000511415610324573660441461028e5760006000fd5b60a060020a60043504156102a25760006000fd5b606460243511156102b35760006000fd5b6000602435156102cd575060043560005260206000203301545b156102d85760006000fd5b6024356004356000526020600020330155602435602052600435337f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560206020a3600160005260206000f35b63dd62ed3e600051141561034b576024356000526020600020600435015460005260206000f35b60006000fd00fe4c4c4c4c4c4c20436f696e202d206c6f766520746f20636f646520696e204c4c4c2e
  3. Deploy bytecode as transaction data using ethers.js (note: add the 0x prefix to the bytecode)

    
    const ethers = require("ethers");
    const rpcURL = process.env.sepoliaInfuraWSS // Your RPC URL goes here
    const provider = new ethers.providers.WebSocketProvider(rpcURL)
    const signer = new ethers.Wallet(Buffer.from(process.env.devTestnetPrivateKey, 'hex'), provider);

deploy_lll_contract()

async function deploy_lll_contract(){

const contractBytecode = "0x" + "341561000b5760006000fd5b606433556103758061001f6000396000f300fe341561000b5760006000fd5b600060005260046000601c600001376306fdde036000511415610047576020600052601f80610356604039602052601f19605f60205101166000f35b6395d89b416000511415610074576020600052600380610353604039602052601f19605f60205101166000f35b63313ce567600051141561008d57600060005260206000f35b6318160ddd60005114156100a657606460005260206000f35b6370a0823160005114156100c1576004355460005260206000f35b63a9059cbb600051141561017257366044146100dd5760006000fd5b60a060020a60043504156100f15760006000fd5b606460243511156101025760006000fd5b6024351561016757335460205260205160243511156101215760006000fd5b602435602051033355602435600435540160043555602435602052600435337fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60206020a35b600160005260206000f35b6323b872dd6000511415610272573660641461018e5760006000fd5b60a060020a60043504156101a25760006000fd5b60a060020a60243504156101b65760006000fd5b606460443511156101c75760006000fd5b60443515610267576004355460205233600052602060002060043501546040526001602051604435116101fd5750604051604435115b156102085760006000fd5b60443560205103600435556044356024355401602435556044356040510333600052602060002060043501556044356020526024356004357fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60206020a35b600160005260206000f35b63095ea7b36000511415610324573660441461028e5760006000fd5b60a060020a60043504156102a25760006000fd5b606460243511156102b35760006000fd5b6000602435156102cd575060043560005260206000203301545b156102d85760006000fd5b6024356004356000526020600020330155602435602052600435337f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560206020a3600160005260206000f35b63dd62ed3e600051141561034b576024356000526020600020600435015460005260206000f35b60006000fd00fe4c4c4c4c4c4c20436f696e202d206c6f766520746f20636f646520696e204c4c4c2e";
const txData = contractBytecode; //No constructor arguments to keep bytecode simple.

tx = await signer.sendTransaction({
    data: txData
});

console.log(tx)

}



erc20.lll deployed to Sepolia testnet successfully:
https://sepolia.etherscan.io/tx/0xe28b28d289dff7cc656d137d427699ca227f2283a0d0c3ce3b0285447ef443ef

4. Import deployed contract address into Metamask and transfer tokens 

erc20.lll tokens on Sepolia testnet transferred successfully:
https://sepolia.etherscan.io/tx/0x6d635d65f0b046afba8cb582b12824845a77c372288a05a1433829c04a005ae8

5. Test transferFrom after you approve tokens to bulk transfer contract

erc20.lll approve tokens on Sepolia testnet successful:
https://sepolia.etherscan.io/tx/0xc0508d0c543e68783a8ba8c063f93110a62dc0a019ad8d470abc2d9975f994aa

erc20.lll bulk transfer calling transferFrom on Sepolia testnet successful:
https://sepolia.etherscan.io/tx/0xb8658cceba599c4984184d9116fee96ce7fdd7cd4f76ff677ca229e2025097d5

Thank you for adding this feature to Retesteth @winsvega with https://github.com/ethereum/retesteth/commit/56ae7a7b9efad8ba642717bf061400128b17be88 !
winsvega commented 1 year ago

Edit Dockerfile not to build any of the sideclients (geth/besu/evmone/...)