ethereum/solidity

[FEATURE]: "addon" arguments

nmushegian opened this issue · 5 comments

I want to append extra calldata past what a particular function handler expects, but keep the same signature. As the callee, I can give hints about what extra ("optional") data to expect.

example contract:

contract ExampleDefinitions {
    function transfer( address to, uint amount ) options( bytes32 identifier) returns (bool ok);
    // Collides, compiler error:
    // function transfer( address to, uint amount ) returns (bool ok);
    // Distinct signature, compiles:
    function transfer( address to, uint amount, bytes32 identifier ) returns (bool ok)
}

possible call syntax: example.transfer(to, amount)[identifier];

axic commented

Wouldn't this make more sense as an extension of the ABI with optional parameters? E.g. optional parameters are still part of the signature, but for example pre or postfixed with a question mark.

You above method would translate into the signature: transfer(address,uint,bytes32?)

And I think this issue is kind of a duplicate of #232.

The problem with using the same signature for functions with different number of arguments is that it might be hard to tell whether the argument is actually there or whether it is just set to zero. We could use CALLDATASIZE for that, but actually I think that having different signatures is safer and not much more costly.

axic commented

@chriseth I've got used to method overloading instead of optional parameters, but sometimes I keep running into stack errors when many options are present.

i.e.

  • method(a, b, c, d, e, f)
  • method(a, b, c, d) calls method(a, b, c, d, <default e>, <default f>)
  • method(a, b, c) calls method(a, b, c, <default d>, <default e>, <default f>)

I am wondering how optimal such a call chain is and whether the above proposed optional method + CALLDATSIZE would be a more optimal solution.

Additionally in order to make it work with CALLDATASIZE, optional arguments must be reserved to be the last parameters.

@axic I've been working on default parameters. Once fixed points are fixed up (lol), I'm likely going to get back to trekking on that. If you're game to help, that'd be lovely.

Closing as duplicate of #232