Does Solidity gets reduced to LLL in the process of compiling it to EVM bytecode?

204 views Asked by At

Looking at the Solidity compiler Github repository, I see that the project also integrates an LLL compiler.

This has made me wonder whether Solidity gets reduced to LLL in the process of compilation to EVM bytecode?

I've read that LLL serves as a wrapper around EVM ASM, so intuitively it would make sense to compile Solidity to LLL?

Or is the LLL compiler just included as part of the Solidity project, because it is too small to serve as a project in itself?

2

There are 2 answers

0
Dwight Guth On

Contrary to the previous answer, the actual correct answer is no. The solidity compiler compiles solidity code directly to EVM. There is an intermediate language for solidity called Julia, which is what is actually accepted by assembly{} blocks, but it is not yet developed to the point where Julia code is generated from solidity code. The LLL compiler is included in the solidity repository primarily for historical reasons.

0
Javier Guajardo J. On

Actually I have the same question, but I think the answer is Yes! In Solidity you can use an assembly segment

assembly {
    // LLL OR OPCODES HERE
}

Where you can write code as you do in LLL, same syntax and pretty cheap GAS cost, at least 30% in my experience.

pragma solidity ^0.4.24;
/*
    Autor: Javier Guajardo J.
    Website: https://ethereumchile.cl
    Twitter: @EthereumChile
*/
contract Assembly {
    function returnSum1(uint a, uint b) public pure returns (uint sum) {
        // We ADD a and b in a new variable called doSum
        assembly {
            let doSum := add(a, b)
            sum := doSum
        }
    }
    function returnSum2(uint a, uint b) public pure returns (uint sum) {
        // OR you can ADD a and b directly
        assembly {
            sum := add(a, b)
        }
    }
    function returnSum3(uint a, uint b) public pure returns (uint) {
        // OR you can ADD a and b into 0x40 memory address 
        assembly {
            let sum := mload(0x40) // loading 0x40 address memory
            mstore(sum, add(a, b)) // We store the add(a, b) in 0x40 address memory
            return(sum, 32) // We return result.
        }
    }
}

Result in Remix IDE

Screencapture.png Assembly in Solidity by Javier Guajardo