Smart contract Weakness Classification (SWC) can be found in SWC registry
Contracts are compiled with 0.8.9
. Default behaviour of Solidty 0.8 is to throw an error if there are overflow/underflows source
As shown in Diagrams & Design patterns , Common.sol
and OracleFacade.sol
inherits from Openzeppelin ReentrancyGuard contract . This makes the modifier nonReentrant
available and which makes sure that there are no recursive calls to them. nonReentrant
modifier is applied to all public/external functions which make calls to an external account. For instance, in Insurance.sol
:
function withdrawInsurer(uint256 amount)
external
onlyInsurer
nonReentrant
minimumCovered
{
require(
address(this).balance >= amount,
"Not enough balance in the contract"
);
(bool success, ) = msg.sender.call{value: amount}("");
require(success, "Transfer failed.");
emit WithdrawInsurer(msg.sender, amount, address(this).balance);
}
We always use msg.sender
for authorization. For instance, we use modifiers to check authorization. In Common.sol
,we can find a modifier which checks that caller is a *farmer :
modifier onlyFarmer() {
require(
gatekeeper.isAssigned(FARMER_ROLE, msg.sender),
"Restricted to farmers."
);
_;
}
In order to avoid looping over arrays on-chain which could lead to function execution exceeding the block gas limit, looping is done off-chain. For instance, in Insurance.sol
, process
function is called by a *keeper . at each call, the function processes only one element of openContracts
array
Avoid uing transfer()
and send()
functions as they forward fixed aount of 2300gas. Th gas cost of EVM instructions may change after hard forks which can break functions which rely on fixed assumption about gas cost. Hence, whenever ETH has to be sent, .call.value(..)("")
is used. For instance, in Insurance.sol
, change is returned to *farmers and *government
if (msg.value > fee) {
(bool success, ) = msg.sender.call{value: msg.value - fee}("");
require(success, "Transfer failed.");
}
Rather than having private information such as: farm lattitude, longitude, owner name..ETc. We just expect to receive farmID(bytes32) , which could be a keccak256
digest of the concatenation of all of the above information.
Hence our smart contracts do not deal with any private data