1

I understand what add() does. It used used in the assembly to perform additions. My question is why are we adding 32 here? What is the purpose of doing so?

The full code is here

0

To better understand it is better to include part of the function

function stringToBytes32(string memory source) public pure returns (bytes32 result) {
    // ..

    assembly {
        result := mload(add(source, 32))
    }
}

source is a memory string so the first 32 bytes contains the length and data follows. Then add(source, 32) skips the size portion of the string, and points to the data.

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.