3

I am working on a voting library that allows members of a voting-DAO-like organization to vote on arbitrary actions. Security considerations (I know, arbitrary code execution is evil...) and efficiency (this.call is a CALL and not JUMP hence more expensive in terms of gas and not able to call internal functions) aside, how would I implement this without knowing the function to be voted upon at compile time of the voting library?

I know of this method:

bytes4 functionSig = bytes4(sha3("myFunc(uint256,address)"));
uint parameter1 = 123;
address parameter2 = 0xdf190dc7190dfba737d7777a163445b7fff16133;
// now wait for voting to be completed and upon positive outcome do:
this.call(functionSig, parameter1, parameter2);

but this requires me to know at least the number and types of parameters. How could I generalize this? I guess there must be something along the lines of

bytes callDataGeneratedSomehow = ...
this.call(callDataGeneratedSomehow)

But how can I generate the callDataGeneratedSomehow?

2

Here's an alternate route:

  1. Create an interface contract that both the main contract and "proposal" contracts inherit from.
  2. In the fallback of a proposal contract, do what you want to do. Set any arguments explicitly here.
  3. Deploy said contract.
  4. Point the main contract at the proposal and use .delegatecall() to execute the proposal's code in the main contract's context.

There's probably cleaner/more elegant ways of doing this, but basically, rather than mess around with calldata, you can put up a separate contract and .delegatecall().

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.