sGuard icon indicating copy to clipboard operation
sGuard copied to clipboard

understanding behaviors of sGuard on fallback function

Open sunbeomso opened this issue 3 years ago • 0 comments

It seems sGuard does not add nonReentrant modifier to fallback functions. I wonder if there is any reason for it.

For example, given a test contract below:

contract Fund {
  mapping(address => uint) balances;
  uint counter = 0;
  uint dontFixMe = 0;

  function main(uint x) public {
    if (counter < 100) {
      msg.sender.send(x + 1);
      counter += 1;
      dontFixMe ++;
    }
  }

  function test () public {
    counter +=1;
  }

  function () public {
    counter +=1;
  }
}

sGuard outputs the following contract (it adds nonReentrant to test but not to the fallback):

contract Fund  is sGuard {
  mapping(address => uint) balances;
  uint counter = 0;
  uint dontFixMe = 0;

   function main(uint x) nonReentrant_  public {
    if (counter < 100) {
      msg.sender.send(add_uint256(x, 1));
      counter = add_uint256(counter, 1);
      dontFixMe ++;
    }
  }

   function test () nonReentrant_  public {
    counter = add_uint256(counter, 1);
  }

  function () public {
    counter = add_uint256(counter, 1);
  }
}

Many thanks for your reply in advance.

sunbeomso avatar Feb 03 '22 13:02 sunbeomso