If the only maths you need to do is adding sums of Ether obtained from msg.value
to other sums of Ether obtained from msg.value
, it shouldn't be necessary to use SafeMath, since the msg.value
is bounded by the number of Ether in existence, which is well below the range that can be represented by a uint256
.
As you suggest using SafeMath means a trade-off: The downside is higher gas costs (mainly on deployment) and greater complexity. If the contract is very simple, you're only doing addition and it's very easy to verify that all the values in it are bounded and the total can't possibly overflow, I'd be inclined to leave it out.
However, if there's a little bit of complexity in the contract, there's a case for using it just to make it easy to verify that bounds-checking is being done, and if you have to use it in one place, it's arguably simpler to audit if you use it on all the maths in your contract.
varB
,varA
could potentially overflow orvarD
could potentially underflow. Again, it's impossible to tell you whether or not you have potential overflows/underflows without seeing the code.