Forum for discussion of mid, final term and final project

Calculating costs of non trivial functions

Calculating costs of non trivial functions

by ANTONIO SISBARRA -
Number of replies: 7

In estimation of the costs of the non-trivial functions we have to take into account both the transaction cost and the execution cost? In slides we refer only to the execution cost if I remember correctly

In reply to ANTONIO SISBARRA

Re: Calculating costs of non trivial functions

by DAMIANO DI FRANCESCO MAESA -

The execution cost is the important one, but to calculate teh entire transaction cost given the execution cost should not be so difficult...

In reply to DAMIANO DI FRANCESCO MAESA

Re: Calculating costs of non trivial functions

by ORLANDO LEOMBRUNI -

When you say "estimate/calculate" the gas cost, how should it be done? "By hand" using the gas costs (per opcode) written in the Yellow Paper? Or it suffices to test the contract on the Remix VM and check transaction/execution cost there?

In reply to ORLANDO LEOMBRUNI

Re: Calculating costs of non trivial functions

by DAMIANO DI FRANCESCO MAESA -

In theory by hand and NOT trough simuations in Remix (actual cost can be parameter dependent and so inaccurate). But you can trick Remix to evaluate it for you by decomposing infinite cost functions and composing the estimated cost back togheter properly. THEN you can use simulation to prove your estimations are right.

In reply to DAMIANO DI FRANCESCO MAESA

Re: Calculating costs of non trivial functions

by ORLANDO LEOMBRUNI -

Sorry, I don't understand. To make a concrete example, my giftContent function already requires less than infinite gas as per Remix's estimation (as seen in the attached screenshot). Can I provide directly this number?

Attachment Screen Shot 2018-06-13 at 19.18.17.png
In reply to ORLANDO LEOMBRUNI

Re: Calculating costs of non trivial functions

by DAMIANO DI FRANCESCO MAESA -

Where have you taken the screenshot execution cost from exactly? In the 'gasEstimates' tab of 'compile'->'details' you can find the gas calculation (when possible) for your functions. And yes you can use remix gas estimations as good. The non trivial part is to evaluate gas of whar looks like infinite gas according to remix (e.g. parameters dependent functions).

In reply to DAMIANO DI FRANCESCO MAESA

Re: Calculating costs of non trivial functions

by ORLANDO LEOMBRUNI -
Thank you for your answer! The screenshot is from Remix: after you compile a contract, if you click on the name of a function in the editor it will show you the estimated gas cost in the upper-right portion (it's basically a shorthand to avoid clicking on compile->details every time).
In reply to ORLANDO LEOMBRUNI

Re: Calculating costs of non trivial functions

by DAMIANO DI FRANCESCO MAESA -

Ok, as long as it is the same (i.e. it is not the cost of a transaction containing that function call, that can be influenced by external factors, as the parameters passed).