1

The following function is a function of a library (The code is written in Solidity). It has an assembly instruction that I do not understand. Specifically at line call(sub(gas, 2000), 6, 0, input, 0xc0, r, 0x60).

From the docs:

call(g, a, v, in, insize, out, outsize)

call contract at address a with input mem[in..(in+insize)) providing g gas and v wei and output area mem[out..(out+outsize)) returning 0 on error (eg. out of gas) and 1 on success

function addition(G1Point p1, G1Point p2) internal returns (G1Point r) {
        uint[4] memory input;
        input[0] = p1.X;
        input[1] = p1.Y;
        input[2] = p2.X;
        input[3] = p2.Y;
        bool success;
        assembly {
            success := call(sub(gas, 2000), 6, 0, input, 0xc0, r, 0x60)
            // Use "invalid" to make gas estimation work
            switch success case 0 { invalid() }
        }
        require(success);
    }

Why the address field a is a simple integer ? Is it referring to an internal library function ? If yes how is the numbering defined ?

Tell me ff you want me to provide the full code of the library.

EDIT

I think I found it. Is the address of the a precompiled contract ?

1 Answer 1

2

It refers to pre-compiled contracts. 6 refers to a the bn256Add pre-compiled contract in the Byzantium release. You should look for PrecompiledContractsByzantium in the geth source code to find a list of pre-compiled contracts, but this link could help you: https://ethereum.stackexchange.com/a/15484/47307

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.