Docsity

PrepIQ Certified Solidity Developer Ultimate Exam, Exams of Technology

Toggle sidebar
bg1
PrepIQ Certified Solidity Developer
Ultimate Exam
**Question 1. Which pragma directive specifies that the Solidity compiler version
must be at least 0.8.0 but less than 0.9.0?**
A) `pragma solidity ^0.8.0;`
B) `pragma solidity >=0.8.0 <0.9.0;`
C) `pragma solidity =0.8.0;`
D) `pragma solidity 0.8.*;`
Answer: B
Explanation: The syntax `>=0.8.0 <0.9.0` explicitly defines a range that
includes any version from 0.8.0 up to (but not including) 0.9.0.
**Question 2. In Solidity, which data type is best suited for storing a fixed-size
array of 10 unsigned 256-bit integers?**
A) `uint256[10]`
B) `uint256[]`
C) `bytes10`
D) `uint[10]`
Answer: A
Explanation: `uint256[10]` declares a static array with exactly 10 elements of
type `uint256`. `uint[10]` defaults to `uint256[10]` but the explicit type is
clearer.
**Question 3. What is the default visibility of a state variable in Solidity if no
visibility keyword is provided?**
A) `public`
B) `private`
C) `internal`
D) `external`
Answer: C
Explanation: State variables without an explicit visibility default to `internal`,
meaning they are accessible within the contract and derived contracts.
**Question 4. Which of the following statements about the `view` modifier is
correct?**
A) It allows the function to modify state variables.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f

Partial preview of the text

Download PrepIQ Certified Solidity Developer Ultimate Exam and more Exams Technology in PDF only on Docsity!

Ultimate Exam

Question 1. Which pragma directive specifies that the Solidity compiler version must be at least 0.8.0 but less than 0.9.0? A) pragma solidity ^0.8.0; B) pragma solidity &gt;=0.8.0 &lt;0.9.0; C) pragma solidity =0.8.0; D) pragma solidity 0.8.*; Answer: B Explanation: The syntax &gt;=0.8.0 &lt;0.9.0 explicitly defines a range that includes any version from 0.8.0 up to (but not including) 0.9.0. Question 2. In Solidity, which data type is best suited for storing a fixed-size array of 10 unsigned 256-bit integers? A) uint256[10] B) uint256[] C) bytes10 D) uint[10] Answer: A Explanation: uint256[10] declares a static array with exactly 10 elements of type uint256. uint[10] defaults to uint256[10] but the explicit type is clearer. Question 3. What is the default visibility of a state variable in Solidity if no visibility keyword is provided? A) public B) private C) internal D) external Answer: C Explanation: State variables without an explicit visibility default to internal, meaning they are accessible within the contract and derived contracts. Question 4. Which of the following statements about the view modifier is correct? A) It allows the function to modify state variables.

Ultimate Exam

B) It can be called from other contracts only. C) It guarantees that the function does not alter the blockchain state. D) It consumes more gas than a regular function. Answer: C Explanation: view functions promise not to modify state; they can read but not write to storage, and they do not incur gas when called off-chain. Question 5. In Solidity, what does the receive() function handle? A) Calls with empty calldata and non-zero msg.value. B) All fallback calls regardless of calldata. C) Calls with non-empty calldata and zero msg.value. D) Only calls from other contracts. Answer: A Explanation: receive() is a special external payable function that is invoked when the contract receives Ether with empty calldata. Question 6. Which keyword is used to prevent a function from being overridden in derived contracts? A) final B) sealed C) immutable D) virtual Answer: A Explanation: The final keyword (available from Solidity 0.8.9) marks a function as non-overridable. Prior to that, omitting virtual prevented overriding. Question 7. What is the purpose of the unchecked block in Solidity 0.8.x? A) To disable overflow/underflow checks for arithmetic operations inside the block. B) To ignore compiler warnings about unused variables. C) To bypass access-control modifiers. D) To automatically revert the transaction on error. Answer: A

Ultimate Exam

**Question 11. Which of the following statements about delegatecall is TRUE? ** A) It preserves the caller’s msg.sender and msg.value. B) It changes the caller’s storage layout to that of the callee. C) It can be used only with contracts compiled with the same Solidity version. D) It automatically forwards all Ether sent with the call. Answer: A Explanation: delegatecall executes code in the context of the calling contract, keeping msg.sender and msg.value unchanged. Question 12. What is the gas cost impact of using uint8 versus uint256 for a state variable that is stored alone in a storage slot? A) uint8 always costs less gas to read and write. B) Both cost the same because the slot size is 32 bytes. C) uint8 costs more gas because of extra padding. D) uint8 cannot be stored alone; it must be packed. Answer: B Explanation: Solidity packs multiple small variables into a single 32-byte slot, but a solitary uint8 still occupies an entire slot, so gas cost is the same as uint256. Question 13. Which of the following is the correct way to emit an event named Transfer with parameters address indexed from, address indexed to, and uint256 value? A) emit Transfer(msg.sender, to, value); B) Transfer.emit(msg.sender, to, value); C) emit Transfer({from: msg.sender, to: to, value: value}); D) emit Transfer{from: msg.sender, to: to, value: value}(); Answer: A Explanation: Events are emitted using the emit keyword followed by the event name and positional arguments. Question 14. In Solidity, which modifier is used to restrict a function so that it can only be called by the contract’s owner?

Ultimate Exam

A) onlyOwner (custom) B) ownerOnly (built-in) C) restricted (built-in) D) admin (built-in) Answer: A Explanation: Solidity does not provide a built-in owner-only modifier; developers typically implement a custom onlyOwner modifier that checks msg.sender == owner. Question 15. What does the selfdestruct(address payable recipient) function do? A) It pauses the contract permanently. B) It transfers all remaining Ether to recipient and removes the contract’s bytecode from the blockchain. C) It upgrades the contract to a new implementation. D) It only deletes the contract’s storage but keeps the code. Answer: B Explanation: selfdestruct sends the contract’s balance to the specified address and deletes the contract’s code and storage, making it inaccessible. Question 16. Which of the following statements about the ERC- 20 approve/transferFrom pattern is a known security risk? A) The allowance can be increased without resetting to zero first, leading to a race condition. B) approve automatically transfers tokens. C) transferFrom can be called by anyone without allowance. D) approve emits an event that can be intercepted. Answer: A Explanation: If a spender uses the old allowance while the owner is changing it, the spender may spend both the old and new allowance. The recommended mitigation is to first set allowance to zero. Question 17. Which Solidity construct is used to create a reusable piece of code that can be called without using inheritance? A) abstract contract

Ultimate Exam

Answer: B Explanation: The pattern minimizes re-entrancy risk by first checking conditions, then updating contract state, and finally making external calls. Question 21. What is the purpose of the fallback() function in Solidity 0.6.x and later? A) To receive Ether when calldata is empty. B) To handle calls with non-existent function signatures or empty calldata when receive() is not defined. C) To replace the constructor. D) To automatically forward calls to another contract. Answer: B Explanation: In Solidity ≥0.6.0, fallback() is invoked when the contract receives a call with data that does not match any function signature and when receive() is not present for empty calldata. Question 22. Which of the following statements about the abi.encodePacked function is FALSE? A) It returns tightly packed binary data. B) It can be used to create a deterministic hash for signatures. C) It automatically pads each argument to 32 bytes. D) It is vulnerable to hash collisions if not used carefully. Answer: C Explanation: abi.encodePacked does not pad arguments; it concatenates them tightly, which can lead to collisions if variable-length types are concatenated without delimiters. Question 23. In Solidity, which modifier is required for a function that reads from msg.sender but does not modify state? A) pure B) view C) payable D) No modifier is required. Answer: B

Ultimate Exam

Explanation: Accessing msg.sender is considered a read-only operation, so the function must be marked view. pure would disallow any access to blockchain data. Question 24. Which of the following is a correct way to declare a mapping from an address to a dynamic array of uint256? A) mapping(address =&gt; uint256[]) public balances; B) mapping(address, uint256[]) public balances; C) mapping(address =&gt; uint256)[] public balances; D) mapping(address =&gt; uint256[] ) public balances; Answer: A Explanation: The syntax mapping(keyType =&gt; valueType) allows a value type of any type, including dynamic arrays like uint256[]. Question 25. What does the onlyOwner modifier typically check in a contract? A) That msg.sender is the address stored in a state variable called owner. B) That the caller has a specific ERC-20 token balance. C) That the transaction originated from a contract. D) That the caller is a contract with a specific interface. Answer: A Explanation: The common pattern is require(msg.sender == owner, "Not owner"); to restrict privileged actions. Question 26. Which of the following is the most gas-efficient way to delete an element from a dynamic array in Solidity without preserving order? A) Shift all elements after the index left by one. B) Replace the element with the last array element and then pop(). C) Set the element to zero and keep the length unchanged. D) Use delete array[index]; only. Answer: B Explanation: Swapping the target element with the last element and then calling pop() removes the element in O(1) gas, while shifting is O(n).

Ultimate Exam

C) (bool success, ) = address(otherContract).call(data); require(success); D) otherContract.call(data); Answer: C Explanation: The low-level call returns a boolean success flag; the pattern (bool success, ) = ...; require(success); ensures the call did not revert. Question 31. What is the effect of declaring a function with the external visibility modifier? A) It can be called only from within the contract. B) It can be called from other contracts and via transactions, but not internally without using this.. C) It is automatically payable. D) It can be overridden by derived contracts. Answer: B Explanation: external functions are part of the contract’s public ABI and can be called from other contracts or transactions. They are not directly callable from within the same contract unless using this.functionName(). Question 32. Which of the following is the correct way to prevent a contract from being re-entered during a state-changing function? A) Use a mutex variable (bool locked) and a require(!locked) check. B) Call selfdestruct at the end of the function. C) Set the function’s visibility to private. D) Use delegatecall instead of call. Answer: A Explanation: A simple re-entrancy guard uses a bool locked state variable that is set to true before external calls and reset after, combined with a require(! locked) check. Question 33. Which of the following statements about calldata is TRUE? A) It is a mutable storage area. B) It can only be used for function parameters of external functions. C) Data stored in calldata persists across transactions. D) Variables in calldata are cheaper than memory for all types.

Ultimate Exam

Answer: B Explanation: calldata is an immutable, read-only area that exists only for external function arguments. It cannot be used for internal functions. Question 34. In Solidity, which of the following is the most appropriate way to compare two bytes32 values for equality? A) if (keccak256(a) == keccak256(b)) B) if (a.equals(b)) C) if (a == b) D) if (compare(a, b)) Answer: C Explanation: bytes32 values can be compared directly with the == operator. Question 35. Which of the following statements about the address payable type is correct? A) Only address payable can receive Ether via .transfer() or .send(). B) address payable can be cast to uint256 without explicit conversion. C) address payable is the same as address but with additional functions for calling contracts. D) address payable can be used as a mapping key, while address cannot. Answer: A Explanation: Only address payable has the .transfer, .send, and .call{value: …} methods that forward Ether. Question 36. Which of the following is a recommended practice to avoid the “stack too deep” error in Solidity? A) Increase the Solidity compiler version. B) Use fewer local variables and group related data into structs. C) Declare functions as pure. D) Deploy the contract on a testnet first. Answer: B Explanation: The EVM stack limit is 16 slots; reducing the number of local variables or packing them into structs helps stay within limits.

Ultimate Exam

B) returns (type1, type2) syntax C) multiple keyword D) array return type only Answer: B Explanation: Functions can specify multiple return types using returns (type1, type2, ...) and then return a comma-separated list. **Question 41. In Solidity, what does the block.timestamp variable represent? ** A) The exact time the block was mined in seconds since the Unix epoch. B) The block number. C) The gas price of the current transaction. D) The hash of the previous block. Answer: A Explanation: block.timestamp (alias now) gives the Unix timestamp of the current block, set by the miner. Question 42. Which of the following is the correct way to declare a function that can be overridden in derived contracts? A) function foo() public virtual; B) function foo() public override; C) function foo() public final; D) function foo() public abstract; Answer: A Explanation: The virtual keyword marks a function as overridable. Derived contracts use override when providing a new implementation. Question 43. What is the purpose of the require statement in Solidity? A) To pause contract execution indefinitely. B) To check a condition and revert the transaction if the condition is false, optionally providing an error message. C) To log an event. D) To transfer Ether to another address.

Ultimate Exam

Answer: B Explanation: require validates inputs or state and reverts the transaction with an optional error string if the condition fails. Question 44. Which of the following statements about Solidity’s assembly block is FALSE? A) It allows direct access to EVM opcodes. B) Variables declared in Solidity are automatically available inside assembly. C) It can be used to perform low-level operations not possible in Solidity. D) Inline assembly can reduce gas consumption for certain tasks. Answer: B Explanation: Inside an assembly block, Solidity variables are not directly accessible; they must be passed in or loaded using let. Question 45. In a Solidity contract, which function signature is required for ERC- 1155 ’s batch transfer of tokens? A) function safeBatchTransferFrom(address from, address to, uint256[] ids, uint256[] amounts, bytes data) external; B) function batchTransfer(address from, address to, uint256[] ids, uint256[] amounts) external; C) function safeTransferFrom(address from, address to, uint256 id, uint amount, bytes data) external; D) function mintBatch(address to, uint256[] ids, uint256[] amounts, bytes data) external; Answer: A Explanation: ERC-1155 defines safeBatchTransferFrom with the listed parameters to move multiple token types in a single call. Question 46. Which Solidity version introduced the receive() function? A) 0.5. B) 0.6. C) 0.7. D) 0.8. Answer: B

Ultimate Exam

Question 50. Which of the following best describes the purpose of the modifier onlyAfter(uint _time) pattern? A) To restrict a function so it can be called only after a specific block timestamp. B) To ensure a function runs only after a certain gas limit is reached. C) To make a function callable only by the contract itself. D) To enforce that a function can be called only once. Answer: A Explanation: A modifier that checks require(block.timestamp &gt;= _time) restricts execution until the given time has passed. Question 51. Which of the following statements about the bytes type in Solidity is true? A) bytes is a dynamically sized byte array stored in memory or calldata. B) bytes is a fixed-size 32-byte type. C) bytes cannot be used as a function parameter. D) bytes is equivalent to string. Answer: A Explanation: bytes (without a size) is a dynamic array of bytes, similar to string but without UTF-8 validation. Question 52. In an ERC-20 token contract, which function must emit the Transfer event even when tokens are minted? A) transfer(address to, uint256 amount) B) transferFrom(address from, address to, uint256 amount) C) mint(address to, uint256 amount) (custom) D) approve(address spender, uint256 amount) Answer: C (custom mint must emit Transfer from address(0) to to) Explanation: The ERC-20 specification requires that token creation emit a Transfer event with the from address set to address(0). Question 53. Which of the following is the correct way to declare an event that logs an indexed address and a non-indexed uint256 value? A) event Log(address indexed user, uint256 amount); B) event Log(address user, uint256 indexed amount);

Ultimate Exam

C) event Log(address user, uint256 amount) indexed; D) event Log(address indexed user, uint256 indexed amount); Answer: A Explanation: Only parameters marked with indexed become topics; the syntax event Name(address indexed param1, uint256 param2); is correct. Question 54. Which of the following Solidity statements correctly casts an address to an address payable? A) address payable p = payable(addr); B) address payable p = address(uint160(addr)); C) address payable p = address.convert(addr); D) address payable p = addr; Answer: A Explanation: The payable conversion keyword is used: address payable p = payable(addr);. **Question 55. What does the msg.sender variable represent in a contract call? ** A) The address of the contract that created the current contract. B) The address of the account or contract that invoked the current function. C) The address of the miner who mined the block. D) The address of the transaction’s originator (EOA). Answer: B Explanation: msg.sender is the immediate caller of the function, which may be an EOA or another contract. Question 56. Which of the following is a known limitation of the selfdestruct opcode? A) It can only be called by the contract’s owner. B) It does not remove the contract’s address from the blockchain, allowing it to receive Ether afterwards. C) It refunds all gas to the caller. D) It automatically upgrades the contract to the latest Solidity version. Answer: B

Ultimate Exam

Question 60. Which of the following is the correct way to declare a struct named Person with a string name and uint256 age? A) struct Person { string name; uint256 age; } B) struct Person { string memory name; uint256 age; } C) struct Person { string calldata name; uint256 age; } D) struct Person { bytes name; uint age; } Answer: A Explanation: Inside a struct definition, data locations are not specified; they are determined when the struct is used. Question 61. Which of the following statements about the unchecked block is FALSE? A) It can only be used with arithmetic operations. B) It can be nested inside other unchecked blocks. C) It bypasses overflow checks for all operations inside it. D) It automatically reverts on division by zero. Answer: D Explanation: Division by zero always reverts regardless of unchecked; the block only affects overflow/underflow checks. Question 62. In Solidity, which of the following is the correct way to declare a function that can be called without sending Ether, but also allows the caller to send Ether optionally? A) function donate() external payable {} B) function donate() external { payable; } C) function donate() external payable returns (bool); D) function donate() external returns (bool payable); Answer: A Explanation: Declaring the function as payable allows it to receive Ether, but callers may send zero Ether as well. Question 63. Which of the following is an accurate description of the tx.origin global variable?

Ultimate Exam

A) It returns the address of the immediate caller of the function. B) It returns the address of the account that originated the transaction, even through multiple contract calls. C) It can be used safely for access control. D) It is identical to msg.sender. Answer: B Explanation: tx.origin is the original EOA that started the transaction, which remains constant across nested calls. Using it for authorization is discouraged. Question 64. What is the gas cost implication of using a public state variable versus a private state variable with a getter function? A) public variables are cheaper because the compiler automatically creates a getter. B) private variables are cheaper because they are not stored. C) Both have identical gas costs for reading the variable from outside the contract. D) public variables are more expensive due to extra visibility checks. Answer: C Explanation: Accessing a public variable from outside triggers the autogenerated getter, which costs the same as calling an explicit external view function. Question 65. Which of the following is the correct syntax to declare a constant address named ADMIN? A) address constant ADMIN = 0x123...; B) constant address ADMIN = 0x123...; C) address immutable ADMIN = 0x123...; D) address public constant ADMIN = 0x123...; Answer: A Explanation: The order is type constant NAME = value;. Adding public is optional but not required. Question 66. Which of the following functions is part of the ERC-165 standard for interface detection? A) function supportsInterface(bytes4 interfaceID) external view returns (bool);