I know that an assert-style exception is generated in the situation 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?
Following is my code:
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];
}
}
Also, how do I refund the remaining gas to the executor?