✅Quiz
Last updated
Q1 The use of pragma in the given contract snippet
Q2 The given contract snippet has
Q3 The given contract snippet has
Q4 In the given contract snippet
Q5 The security concern(s) in the given contract snippet is/are
Comment:
Controlled delegatecall: delegatecall() or callcode() to an address controlled by the user allows execution of malicious contracts in the context of the caller’s state. Ensure trusted destination addresses for such calls.
from point 12 of Security Pitfalls & Best Practices 101 - by Secureum
Return values of low-level calls: Ensure that return values of low-level calls (call/callcode/delegatecall/send/etc.) are checked to avoid unexpected failures.
from point 37 of Security Pitfalls & Best Practices 101 - by Secureum
Incorrect access control: Contract functions executing critical logic should have appropriate access control enforced via address checks (e.g. owner, controller etc.) typically in modifiers. Missing checks allow attackers to control critical logic.
from point 4 of Security Pitfalls & Best Practices 101 - by Secureum
Account existence check for low-level calls: Low-level calls call/delegatecall/staticcall return true even if the account called is non-existent (per EVM design). Account existence must be checked prior to calling if needed.
from point 38 of Security Pitfalls & Best Practices 101 - by Secureum
Q6 The vulnerability/vulnerabilities present in the given contract snippet is/are
Q7 The security concern(s) in the given contract snippet is/are
Q8 The security concern(s) in the given contract snippet is/are
Q9 The given contract snippet is vulnerable because of
Q10 In the given contract snippet, the require check will
Q11 The security concern(s) in the given contract snippet is/are
Q12 The security concern(s) in the given contract snippet is/are
Q13 The security concern(s) in the given proxy-based implementation contract snippet is/are
Comment:
There are no imported contracts that need to be made upgradable (by implementing Initializable).
Import upgradeable contracts in proxy-based upgradeable contracts: Contracts imported from proxy-based upgradeable contracts should also be upgradeable where such contracts have been modified to use initializers instead of constructors.
from point 97 of Security Pitfalls & Best Practices 101 - by Secureum
Unprotected initializers in proxy-based upgradeable contracts: Proxy-based upgradeable contracts need to use public initializer functions instead of constructors that need to be explicitly called only once. Preventing multiple invocations of such initializer functions (e.g. via initializer modifier from OpenZeppelin’s Initializable library) is a must.
from point 95 of Security Pitfalls & Best Practices 101 - by Secureum
Initializing state-variables in proxy-based upgradeable contracts: This should be done in initializer functions and not as part of the state variable declarations in which case they won’t be set.
from point 96 of Security Pitfalls & Best Practices 101 - by Secureum
Q14 The security concern(s) in the given contract snippet is/are
Comment:
There's no guarantee that the passed arrays are of same length, so if one would be longer than the other one it can cause an Out Of Bounds error, which is why D is correct.
Calls inside a loop: Calls to external contracts inside a loop are dangerous (especially if the loop index can be user-controlled) because it could lead to DoS if one of the calls reverts or execution runs out of gas. Avoid calls within loops, check that loop index cannot be user-controlled or is bounded.
from point 43 of Security Pitfalls & Best Practices 101 - by Secureum
ERC20 transfer() does not return boolean: Contracts compiled with solc >= 0.4.22 interacting with such functions will revert. Use OpenZeppelin’s SafeERC20 wrappers.
from point 24 of Security Pitfalls & Best Practices 101 - by Secureum
This is ERC20 token transfer and not Ether transfer (which throws on failure). ERC20 transfer is typically expected to return a boolean but non-ERC20-conforming tokens may return nothing or even revert which is typically why SafeERC20 is recommended.
from Rajeev on Secureum Discord Server
Q15 The vulnerability/vulnerabilities present in the given contract snippet is/are
Q16 The security concern(s) in the given contract snippet is/are
Comment:
Signature malleability: The ecrecover function is susceptible to signature malleability which could lead to replay attacks. Consider using OpenZeppelin’s ECDSA library.
from point 23 of Security Pitfalls & Best Practices 101 - by Secureum
Insufficient Signature Information: The vulnerability occurs when a digital signature is valid for multiple transactions, which can happen when one sender (say Alice) sends money to multiple recipients through a proxy contract (instead of initiating multiple transactions). In the proxy contract mechanism, Alice can send a digitally signed message off-chain (e.g., via email) to the recipients, similar to writing personal checks in the real world, to let the recipients withdraw money from the proxy contract via transactions. To assure that Alice does approve a certain payment, the proxy contract verifies the validity of the digital signature in question. However, if the signature does not give the due information (e.g., nonce, proxy contract address), then a malicious recipient can replay the message multiple times to withdraw extra payments. This vulnerability was first exploited in a replay attack against smart contracts [36]. This vulnerability can be prevented by incorporating the due information in each message, such as a nonce value and timestamps
from point 3.1.13 of A Survey on Ethereum Systems Security: Vulnerabilities, Attacks, and Defenses
Indistinguishable Chains: This vulnerability was first observed from the cross-chain replay attack when Ethereum was divided into two chains, namely, ETH and ETC [10]. Recall that Ethereum uses ECDSA to sign transactions. Prior to the hard fork for EIP-155 [7], each transaction consisted of six fields (i.e., nonce, recipient, value, input, gasPrice, and gasLimit). However, the digital signatures were not chain-specific, because no chain-specific information was even known back then. As a consequence, a transaction created for one chain can be reused for another chain. This vulnerability has been eliminated by incorporating chainID into the fields.
from point 3.2.1 of A Survey on Ethereum Systems Security: Vulnerabilities, Attacks, and Defenses
ecrecover() returns (address)
: recover the address associated with the public key from elliptic curve signature or return zero on error.
from of Mathematical and Cryptographic Functions – Solidity Documentation