I am trying to estimate the complexity of the smart contracts I employ when later triggered. Assume I have 3 smart contracts:

contract con1{

contract con2{

contract main{

Assume that main triggers cont2, and con2 triggers con1. Also assume the complexity of con1 and con2 is O(n) and that of main is O(1).

When I test my contracts over the Ropsten network. There is no cost for running main. Shouldn't it be expensive since it calls con2 of complexity O(n) which will also call con1 of complexity O(n) as well? Am I missing something?

Is there a better way to analyze contract complexity? The problem is I do not want to think about it from gas price and gas limits because this is very dependent on the written code.

  • If you mean what I think you mean, you are correct. However, you probably made a mistake in the measurement or in the contract code. For example, a solidity contract does not have a complexity. Functions inside the contract have a complexity. You need to post more details to make this post answerable.
    – mafrasi2
    Apr 7, 2018 at 23:14

1 Answer 1


The only measurement you should be interested in is gas usage. If you are thinking of writing functions which require minutes (even hours?) to run, then you can forget about Ethereum being the right platform for you. You would run out of gas really quick - there's a maximum gas limit for each transaction.

Your statement about "there is no cost in running main" isn't correct. You always pay (gas, even if you get the Ether for free) for running contract functions.

Otherwise, if you really insist, you can calculate function complexity in normal way. If you have a O(n) calling O(n) function (a loop inside a loop), the complexity is O(n^2).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.