I'm trying to shave off a few thousand GAS from a transaction. I have the following struct in a mapping:

struct Data{
    uint8[4] a
    uint8[4] b
    bytes5 z; 
mapping(uint => Data) public data;

example update function:

function update(uint _x, uint8 _y, bytes5 _z) public returns (bool){
    data[_x].z= _z;

    return (data[_x].a[_y] < data[_x].b[_y]);

The function needs to update z, increment one of the values of a, and compare it to the corresponding value of b. returning a bool of whether or not the latter is greater than the former.

Just updating the above seems to cost about 40,000 GAS, (not including the read/comparison). it seems high given its all much less than 256 bits. I've played around with a few things but can't seem to get the gas costs any lower. Am I missing something?

  • 3
    Share the code of how you are trying to update them Mar 14, 2023 at 12:24


Your Answer

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

Browse other questions tagged or ask your own question.