0

This is an external function which will be called when a transaction have enough number of confirmations.

    function external_call(address destination, uint value, uint dataLength, bytes data) internal returns (bool) {
        bool result;
        assembly {
            let x := mload(0x40)   // "Allocate" memory for output (0x40 is where "free memory" pointer is stored by convention)
            let d := add(data, 32) // First 32 bytes are the padded length of data, so exclude that
            result := call(
                sub(gas, 34710),   // 34710 is the value that solidity is currently emitting
                                   // It includes callGas (700) + callVeryLow (3, to pay for SUB) + callValueTransferGas (9000) +
                                   // callNewAccountGas (25000, in case the destination address does not exist and needs creating)
                destination,
                value,
                d,
                dataLength,        // Size of the input (in bytes) - this is what fixes the padding problem
                x,
                0                  // Output is ignored, therefore the output size is zero
            )
        }
        return result;
    }

this statement is giving me error

sub(gas, 34710),
Expected '(' but got ','
result := call(sub(gas, 34710), // 34710 is the value that solidity is currently emitting
| improve this question | | | | |
  • Your title and description make it sound like a runtime error, but all it is according to the last paragraph is a compilation error. – goodvibration Mar 26 at 18:04
  • Anyway, this function compiles fine on solc 0.4.x (which this contract was originally implemented for), and it compiles "almost" fine on solc 0.5.x, where you just need to change bytes data to bytes memory data. – goodvibration Mar 26 at 18:20
  • Thanks a lot, Could you please help me understand the logic behind sub(gas, 34710)> – GraphicalDot Mar 26 at 18:27
1

That statement doesn't make much sense.

In solidity 0.5 gas is the remaining gas. With sub(gas, 34710) it would seem they want to send all the remaining gas minus 34710 to the called contract, but from the comment it appear they want to send at least 34710.

The error is trying to say that in solidity 0.6 you have to use gas() as it were a function.

I will write the function like this instead:

function external_call(address destination, uint value, bytes memory data) internal returns (bool) {
    bool result;
    assembly {
        result := call(
            gas(),
            destination,
            value,
            add(data, 32),     // First 32 bytes are the padded length of data, so exclude that
            mload(data),       // Size of the input (in bytes) - this is what fixes the padding problem
            0,
            0                  // Output is ignored, therefore the output size is zero
        )
    }
    return result;
}
  • Removed passing the array length as parameter since the length is in the bytes array.
  • Pass all remaninig gas(). The evm already reserves 1/64 of the remaining gas when making a call anyway.
  • Remove x since output is ignored. We can pass 0 as output memory address and length.
| improve this answer | | | | |
  • Pass all remaninig gas(), Does it mean that the contract doesn't have any gas left to make another external_call? Is there any article which would give me in-depth knowledge of this? – GraphicalDot Mar 27 at 9:37
  • 1
    @sauravverma There are some details in EIP 150. You pass the maximum amount of gas the called contract can use, but if the callee doesn't use all it will be available for the caller to make another call. – Ismael Mar 27 at 16:17

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.