pragma solidity ^0.4.0;
contract A{
byte[10] arr;
function setElement(uint index, byte value) public {
require(index >= 0 && index < arr.length); //Should I leave it as is?
arr[index] = value;
}
function getElement(uint index) view public returns (byte) {
require(index >= 0 && index < arr.length); //Or not?
return arr[index];
}
}
As I know an assert-style exception is generated in the following situations and not only:
- If you access an array at a too large or negative index (i.e. x[i] where i >= x.length or i < 0).
But should I check the condition every time?
Also I would like to refund the remaining gas to the executor.