second-state / SOLL

SOLL is a new compiler for generate Ewasm from solidity and yul. See a demo here: https://asciinema.org/a/ezJqNLicn5fya02zwu4VXIo8a
https://www.secondstate.io/
377 stars 23 forks source link

How to compile multiple yul files? #46

Open q871795224 opened 3 years ago

q871795224 commented 3 years ago

After I use solidity to yul function of solc, sometimes solc will compile the contract file into multiple yul files. So how do I use soll to compile it into a wasm file? For example:

library SafeMath {
    function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {
        require(b <= a);
        c = a - b;
    }
}
contract Abt {
    using SafeMath for uint256;
    mapping (address => uint256) public etherBalance;
    uint256 feeETH = 0;
    uint256 totalEthFee = 0;
    constructor() {
        feeETH = 1500000000000000;
    }
    function deposit() payable public {
        totalEthFee = totalEthFee.sub(feeETH);
        //etherBalance[msg.sender] = etherBalance[msg.sender].add(msg.value);
    }
    function balanceOfETH(address user) public returns (uint256) {
     return etherBalance[user];
    }
}

After "solc -o ./ --ir ./Abt.sol", multiple files will appear.

Abt.yul SafeMath.yul

So how to compile multiple yul files?

hydai commented 3 years ago

Hi @q871795224 ,

SOLL has not yet supported multiple yul files. I am afraid that you may need to compose it into a single file and then send to SOLL.

For example, here is a workaround for you.

contract Abt {
    mapping (address => uint256) public etherBalance;
    uint256 feeETH = 0;
    uint256 totalEthFee = 0;
    constructor() {
        feeETH = 1500000000000000;
    }
    function deposit() payable public {
        totalEthFee = sub(totalEthFee, feeETH);
        //etherBalance[msg.sender] = etherBalance[msg.sender].add(msg.value);
    }
    function balanceOfETH(address user) public returns (uint256) {
     return etherBalance[user];
    }
    function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {
        require(b <= a);
        c = a - b;
    }
}

And we also found a lack of yul opcode invalid. Because the output yul from the above sol contains invalid(), you may get this error /tmp/sol/Abt.yul:277:17: error: Use of undeclared identifier 'invalid'. I created a new issue to track this error, see #47

q871795224 commented 3 years ago

It helps a lot, thanks you!