✅Quiz
Last updated
Last updated
Q1 Solidity language is
Q2 Which of the following is/are correct?
Q3 Which of the following is/are true?
Q4 Solidity functions
Q5 Function visibility
Q6 Function foo() uses block.number. Which of the following is/are always true about foo()?
Q7 Which of the following is/are true about events?
Q8 A contract can receive Ether via
Q9 receive() and fallback() functions
Q10 Which of the below are value types?
Comment:
Value Types: Types that are passed by value, i.e. they are always copied when they are used as function arguments or in assignments — Booleans, Integers, Fixed Point Numbers, Address, Contract, Fixed-size Byte Arrays (bytes1, bytes2, …, bytes32), Literals (Address, Rational, Integer, String, Unicode, Hexadecimal), Enums, Functions.
from point 37 of Solidity 101 - by Secureum
Reference Types: Types that can be modified through multiple different names. Arrays (including Dynamically-sized bytes array bytes and string), Structs, Mappings.
from point 38 of Solidity 101 - by Secureum
Q11 The default value of
Q12 Address types
Comment:
Address Type: The address type comes in two types: (1) address: Holds a 20 byte value (size of an Ethereum address) (2) address payable: Same as address, but with the additional members transfer and send. address payable is an address you can send Ether to, while a plain address cannot be sent Ether.
from point 45 of Solidity 101 - by Secureum
Members of Address Type: address.balance (uint256): balance of the Address in Wei address.code (bytes memory): code at the Address (can be empty) address.call(bytes memory) returns (bool, bytes memory): issue low-level CALL with the given payload, returns success condition and return data, forwards all available gas, adjustable
from point 46 of Solidity 101 - by Secureum
Conversions: Implicit conversions from address payable to address are allowed, whereas conversions from address to address payable must be explicit via payable(address). Explicit conversions to and from address are allowed for uint160, integer literals, bytes20 and contract types.
from point 45.2 of Solidity 101 - by Secureum
TypeError: Operator - not compatible with types address and int_const 1. Arithmetic operations on addresses are not supported. Convert to integer first before using them.
from playing around with remix Remix
Q13 transfer and send primitives
Q14 Which of the following is/are true for call/delegatecall/staticcall primitives?
Q15 If we have an array then its data location can be
Q16 The impact of data location of reference types on assignments is
Q17 Which of the following is/are valid control structure(s) in Solidity (excluding YUL)?
Q18 The gas left in the current transaction can be obtained with
Q19 Which of the following is/are valid function specifier(s)?
Q20 Integer overflows/underflows in Solidity
Q21 Arrays in Solidity
Q22 Structs in Solidity
Q23 Which of the following is true about mapping types in mapping(_KeyType => _ValueType)?
Comment:
The _KeyType can be any built-in value type, bytes, string, or any contract or enum type. Other user-defined or complex types, such as mappings, structs or array types are not allowed. _ValueType can be any type, including mappings, arrays and structs. They can only have a data location of storage and thus are allowed for state variables, as storage reference types in functions, or as parameters for library functions. You cannot iterate over mappings, i.e. you cannot enumerate their keys. It is possible, though, to implement a data structure on top of them and iterate over that.
from point 65 of Solidity 101 - by Secureum
Q24 if a = 1 then which of the following is/are true?
Q25 delete varName; has which of the following effects?
Comment:
delete a assigns the initial value for the type to a For integers it is equivalent to a = 0 For structs, it assigns a struct with all members reset delete has no effect on mappings. So if you delete a struct, it will reset all members that are not mappings and also recurse into the members unless they are mappings.
from point 67 of Solidity 101 - by Secureum
Default Values: A variable which is declared will have an initial default value whose byte-representation is all zeros. The “default values” of variables are the typical “zero-state” of whatever the type is. For example, the default value for a bool is false.
from point 39 of Solidity 101 - by Secureum
Q26 Conversions in Solidity have the following behavior
Q27 If the previous block number was 1000 on Ethereum mainnet, which of the following is/are true?
Comment:
Block number is the number of the block that is currently being mined, the next one. Block number 1 was too long ago and its hash can no longer be accessed due to scaling reasons. Mainnet ID Chain is 1.
Block and Transaction Properties: blockhash(uint blockNumber) returns (bytes32): hash of the given block - only works for 256 most recent, excluding current, blocks block.chainid (uint): current chain id block.number (uint): current block number block.timestamp (uint): current block timestamp as seconds since unix epoch
from point 73 of Solidity 101 - by Secureum
Q28 User from EOA A calls Contract C1 which makes an external call (CALL opcode) to Contract C2. Which of the following is/are true?
Q29 For error handling
Comment:
assert(bool condition): causes a Panic error and thus state change reversion if the condition is not met - to be used for internal errors. require(bool condition): reverts if the condition is not met - to be used for errors in inputs or external components. require(bool condition, string memory message): reverts if the condition is not met - to be used for errors in inputs or external components. Also provides an error message. revert(): abort execution and revert state changes revert(string memory reason): abort execution and revert state changes, providing an explanatory string
from point 78 of Solidity 101 - by Secureum
The assert function creates an error of type Panic(uint256). Assert should only be used to test for internal errors, and to check invariants. Properly functioning code should never create a Panic, not even on invalid external input.
from point 88 of Solidity 101 - by Secureum
Q30 The following is/are true about ecrecover primitive
Comment:
Although internally it first recovers the public key from the signature, it actually returns the address derived from the public key.
ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address): recover the address associated with the public key from elliptic curve signature or return zero on error. The function parameters correspond to ECDSA values of the signature: r = first 32 bytes of signature, s = second 32 bytes of signature, v = final 1 byte of signature. ecrecover returns an address, and not an address payable.
from point 79.6 of Solidity 101 - by Secureum
If you use ecrecover, be aware that a valid signature can be turned into a different valid signature without requiring knowledge of the corresponding private key. This is usually not a problem unless you require signatures to be unique or use them to identify items. OpenZeppelin has a ECDSA helper library that you can use as a wrapper for ecrecover without this issue.
from point 80 of Solidity 101 - by Secureum
Q31 When Contract A attempts to make a delegatecall to Contract B but a prior transaction to Contract B has executed a selfdestruct
Comment:
The low-level functions call, delegatecall and staticcall return true as their first return value if the account called is non-existent, as part of the design of the EVM. Account existence must be checked prior to calling if needed.
from point 87 of Solidity 101 - by Secureum
Q32 In Solidity, selfdestruct(address)