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
1 Answer
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 ? Commented Sep 16, 2019 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). Commented Sep 16, 2019 at 13:49
-
-
Hi can give me your email again, I thought I would retrieve from here but the message has been deleted. Best regards Commented Oct 14, 2019 at 18:48
-
Ok thank yo, I will email you can delete the email now. Best regards Commented Oct 14, 2019 at 19:36