ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
23.29k stars 5.77k forks source link

abi.decode: function type cannot be decoded #6942

Open amkCha opened 5 years ago

amkCha commented 5 years ago

Description

Function types are now available in solidity : I would like to abi.encode a function and then be able to abi.decode this function. The encoding works but the decoding bugs

Environment

Steps to Reproduce

In solidity, encoding function type works

uint256 id;
address from;
function func (uint256 id1, uint256 id2) external  { } ; 
bytes memory data = abi.encode(id, from, func);

The decoding part here bugs

(uint orderId, address add, function (uint,uint) external thisFunc) = abi.decode(data, (uint,address,function));

Run : truffle compile => Error message CompileError: ParsedContract.sol:88:158: ParserError: Expected primary expression.

I also tried this

(uint orderId, address add, function (uint,uint) external func) = abi.decode(data, (uint,address,function(uint,uint) external));

Run : truffle compile => Error message CompileError: ParsedContract.sol:88:158: ParserError: Expected primary expression.

Could someone help me with this issue ?

Thank you very much in advance ! ^^

chriseth commented 5 years ago

Thanks for your report! This seems to be a limitation of the parser and this might not be so easy to fix.

chriseth commented 4 years ago

This might be solvable with templates (#869), where abi.decode(data, (uint,address,function (uint,uint) external)); could turn into abi.decode.<uint, address, function (uint,uint) external>(data).

chriseth commented 3 years ago

This cannot be solved without changing the AST: A function type name is not an elementary type name, but only elementary type name, identifiers and literals can be primary expressions. We would have to add a new AST node type, but I'm actually not sure this should be a primary expression. If it is not a primary expression, things get even more complicated.