0

I've got this line of inline assembly code in a Solidity file and I'm trying to understand what some parameters do.

assembly {
        success := call(sub(gas, 2000), 8, 0, add(input, 0x20), mul(inputSize, 0x20), out, 0x20)
}

I'm struggling to understand how the add() is being used. The input variable is a uint array, and I don't know what 0x20 is referring to. The Ethereum Yellow Paper says it refers to the keccak256 function but that doesn't make sense to be added. My understanding is that the add opcode adds two uint256 values, but its used here to add an array and an address.

The code comes from line 158 in the below github link. The file it is in is an implementation of BLS / BLGS signature verification.

Any help clarifying this would be much appreciated!

Source: https://gist.github.com/BjornvdLaan/ca6dd4e3993e1ef392f363ec27fe74c4#file-blsexample-sol

1

Variable input is probably a dynamically-allocated array, in which case, the first 32 bytes in it store the length of the array, and the actual data starts at an offset of 32 bytes.

With add(input, 0x20), you are passing this offset (since 0x20 == 32).

  • That makes sense! Thank you! – Joe Baxter Jul 9 at 16:05
  • What would add() be outputting then? – Joe Baxter Jul 9 at 16:18
  • @JoeBaxter: I don't understand your question, but it makes me wonder if you understand my answer (more precisely, makes me feel you don't). – goodvibration Jul 10 at 5:23
  • add(input, 0x20) is being passed to call() as the input offset. I'm trying to determine what value would be passed into call(), since the value passed would be the result of add(input, 0x20). Does that make sense? – Joe Baxter Jul 10 at 14:57
  • @JoeBaxter: Yes, it does. The symbol input is eventually compiled into an address, which is essentially... just an integer. You are adding 32 to that integer and then passing it to call, which assumes that this is the start address of the input data. – goodvibration Jul 10 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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