origin-playground icon indicating copy to clipboard operation
origin-playground copied to clipboard

Use of `call`

Open wanderingstan opened this issue 7 years ago • 3 comments

At ERC725-alliance talk in Berlin, @ali2251 mentioned we're using call in our contracts, which is not reccomended:

I think this is the only case here: https://github.com/OriginProtocol/origin-playground/blob/0c9ba5c008d410e1ca82a2b1eed15705db49af0f/contracts/KeyHolder.sol#L86

@nick , I recall you explaining once why we had to do that. Does that still hold, or have improvements to solidity fixed it?

wanderingstan avatar Sep 07 '18 09:09 wanderingstan

It looks like call was considered "ancient" as of 1 year ago:

https://github.com/ethereum/solidity/issues/2884#issuecomment-329169020

cuongdo avatar Sep 07 '18 12:09 cuongdo

@ali2251 ☝️ (Sorry had your username wrong at first)

wanderingstan avatar Sep 07 '18 14:09 wanderingstan

Hi,

This is Junaid. I have been working on ERC725. I have upgraded the contracts to 0.5.12 version but i'm facing error in following line.

bool success = executions[_id].to.call(executions[_id].data, 0);

TypeError: Wrong argument count for function call.

Please tell me how can i handle this error. Thanks

    struct Execution {
        address to;
        uint256 value;
        bytes data;
        bool approved;
        bool executed;
    }

    mapping (bytes32 => Key) keys;
    mapping (uint256 => bytes32[]) keysByPurpose;
    mapping (uint256 => Execution) executions;

    function approve(uint256 _id, bool _approve)
        public
        returns (bool s)
    {
        require(keyHasPurpose(keccak256(abi.encodePacked(msg.sender)), 2), "Sender does not have action key");

        emit Approved(_id, _approve);

        if (_approve == true) {
            executions[_id].approved = true;
            uint count = 0;
            bool success = executions[_id].to.call(executions[_id].data, 0);
            if (success) {
                executions[_id].executed = true;
                emit Executed(
                    _id,
                    executions[_id].to,
                    executions[_id].value,
                    executions[_id].data
                );
                return true;
            } else {
                emit ExecutionFailed(
                    _id,
                    executions[_id].to,
                    executions[_id].value,
                    executions[_id].data
                );
                return false;
            }
        } else {
            executions[_id].approved = false;
        }
        return true;
    }

junaid02012 avatar Feb 27 '20 11:02 junaid02012