Is there any security issue when making for-loops inside getter functions ? Let's say the array is very large, and it takes a long time to loop through the array. Is it a potential threat or I can ignore this as long as the function is passed as view or pure ? Moreover in general can I consider all view and pure functions as none dangerous for the smart contract security ? Best regards


There is no security issue when making getter functions, period!

A getter function is constant (typically view), hence does not change the state.

Therefore, such function cannot yield a security breach by definition.

You may have a security issue in some non-constant function which calls some getter function, but that security issue will not be resolved by changing the getter function's code.

  • Thank you very much for this very clear answer ! Also I was wondering if there is a limit in the number of getter functions a smart contract can have. As a full stack dev it is very tempting to create a lot of getter function to facilitate futur front end developpements. But I suspect there should be a drawback if I create too much, right ?
    – Kevin Wad
    Sep 16 '19 at 13:39
  • @KevinWad: I'm pretty sure that you won't be able to deploy a contract once the generated byte-code (compiled contract) exceeds a certain size, because the gas amount required for deploying it will be larger than the block gas-limit (which is normally around 80M I think). Sep 16 '19 at 13:49
  • Thank you. Best regards
    – Kevin Wad
    Sep 16 '19 at 13:52
  • @KevinWad: You two mate :) Sep 16 '19 at 14:10
  • Hi can give me your email again, I thought I would retrieve from here but the message has been deleted. Best regards
    – Kevin Wad
    Oct 14 '19 at 18:48

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.