3

In solc 0.4.22 onward, it is possible to provide a string message containing details about the error that will be passed back to the caller (in require, assert and revert statements).

Does the gas usage of these statements depend on the length of the provided string?

I assume that the answer is no, since it would otherwise imply that this information is saved on the blockchain, and AFAIK, reverted transactions are not saved on the blockchain.

If I am correct, then it means that it's the Ethereum node itself which somehow knows how to return this message back to the caller.

Am I correct, and if yes, how exactly is the Ethereum node able to do that? To my understanding, it would need to get the revert opcode (in the case of require and revert) or the invalid opcode (in case of assert) returned from the transaction, and determine exactly where they occurred within the code.

Also, if this is indeed the case, then it means that the deployed bytecode should contain the message, meaning that the gas cost of the contract-deployment itself depends on the length of this message. Is that correct?

Thank you!

2

OK, I have realized that I may as well just test it.

The results show that both of my speculations are correct:

  1. The gas cost of a transaction does not change as a result of changing the string message
  2. The gas cost of a contract-deployment changes as a result of changing the string message

I would be happy if someone can confirm these findings (and even back them with what the official documentation states with regards to this, a piece of information which I haven't been able to trace).

0

I am hopping that you use the require condition in the modifiers, If so then before you are executing the function its just a simple comparison and will not be consider as a transaction. Whereas the message you write in the require will popup in the MetaMask and it will not store anything in the blockchain. As blockchain only stores the data if its a transaction. Your gas cost for the contract deployment increase because your contract take more bytes because of the more data in the string.

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.