Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert if calldata has wrong size #2109

Closed
chriseth opened this issue Apr 7, 2017 · 13 comments
Closed

Revert if calldata has wrong size #2109

chriseth opened this issue Apr 7, 2017 · 13 comments

Comments

@chriseth
Copy link
Contributor

chriseth commented Apr 7, 2017

An external function should revert in the following additional situations:

  • it has statically-sized arguments and the calldata size does not exactly match that size
  • it has dynamically-sized arguments and the calldata is shorter than the shortest possible encoding
@chriseth chriseth changed the title DICSUSS: Revert if calldata has wrong size DISCUSS: Revert if calldata has wrong size Apr 7, 2017
@axic
Copy link
Member

axic commented Apr 7, 2017

Related #510.

@federicobond
Copy link
Contributor

federicobond commented Apr 7, 2017

I assume this has been recently motivated by potential attacks as described here:
https://blog.golemproject.net/how-to-find-10m-by-just-reading-blockchain-6ae9d39fcd95

Opt-in security like the one discussed in #510 is usually troublesome from my point of view, but with Solidity, it also costs quite a bit of money. How much overhead are we talking about if one would validate the calldata size for each function by default?

@federicobond
Copy link
Contributor

On the other hand, I think there are good reasons to leave these checks to adequate tools for interfacing with contracts. No need to make every Ethereum node do more work to compensate for deficiencies in tooling.

@chriseth
Copy link
Contributor Author

Something like require(msg.data.length == 32) costs roughly 25 gas. It will be more expensive to catch some errors for encoding dynamic data. Another thing to note is that, strictly, this would be a breaking change in the ABI.

@chriseth chriseth changed the title DISCUSS: Revert if calldata has wrong size Revert if calldata has wrong size Jul 5, 2017
@chriseth
Copy link
Contributor Author

chriseth commented Jul 5, 2017

Can be done together with a rewrite of the ABI decoder.

@axic
Copy link
Member

axic commented Oct 30, 2017

Raised over at Remix (https://github.com/ethereum/remix/issues/585) is a good suggestion that this should be definitely enforced for constructors, because it is unlikely case to create something without passing calldata. And considering it is concatenated after the bytecode it does leave a bigger surface for errors than regular transactions.

@axic
Copy link
Member

axic commented Dec 1, 2017

This is kind of enabled now with the new ABI decoder. Keep in mind: turned the new ABI decoder on by default is a breaking change because of that.

@chriseth
Copy link
Contributor Author

The old and the new decoder now have options to revert if the data is too short.

@lastperson
Copy link
Contributor

it has statically-sized arguments and the calldata size does not exactly match that size

Will result in that all multisig wallets and other contracts that use address.call() will not be able to interact with newly compiled contracts. Details: #2884

@chriseth
Copy link
Contributor Author

@lastperson we probably won't check for input being too long, only for being too short, so it should be fine.

The reason why we don't check for input being too long is that in order to do it properly (i.e. have a bijective decoding function), we also have to check whether there are no gaps between dynamically encoded data and that would be rather complicated.

@chriseth
Copy link
Contributor Author

We actually have a check in place in the decoder, so it is easy to add this to 0.5.0. Do we want it?

@lastperson
Copy link
Contributor

For "too short", I vote "yes".

@leonardoalt
Copy link
Member

Closing after #4224 was merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants