└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # solidity-coding-challenges-questions 2 | Solidity coding challenges and interview questions 3 | 4 | ## Solidity screening questions 5 | 6 | 1. Can you prove within transaction runtime that particular event with particular set of arguments has been emitted on the contract in the past? If yes, how (general concept). 7 | 8 | 2. Can you verify that the there is a contract deployed at some Ethereum address with specific bytecode within Ethereum transaction context (i.e. you want to make sure that there is the trusted contract you need at some address with some predefined source code and not some malicious code before calling it)? 9 | 10 | 3. If your contract is calling some other contract’s function can this other contract’s function return a `struct` data structure and what are your options for it? 11 | 12 | ## Solidity coding challenge (10 minutes) 13 | 14 | ### Task 15 | Add code to calculate storage address for value at address: 16 | ``` 17 | contract A { 18 | mapping (address => uint256) values; 19 | 20 | function getValue(address _addr) public view returns (bytes32 storagePointer) { 21 | assembly { 22 | // add code 23 | } 24 | } 25 | } 26 | ``` 27 | 28 | ## Solidity coding challenge 2 (2-4 hours) 29 | 30 | ### Task 31 | Given the following set of contracts the goal is to implement to-bytes and from-bytes converter for structs to be able to pass them from contract to contract in a form of bytes. Please assume that `Storage` and `Controller` contracts have different addresses on the network. `StructDefiner` is never deployed on its own and is used as a part of `Storage` or `Controller`. 32 | 33 | ``` 34 | contract StructDefiner { 35 | struct MyStruct { 36 | uint256 someField; 37 | address someAddress, 38 | uint128 someOtherField 39 | uint128 oneMoreField 40 | } 41 | } 42 | 43 | contract Storage { 44 | StructDefiner.MyStruct[] internal structs; 45 | 46 | function getStructByIdx(uint256 idx) external view returns (bytes) { 47 | assembly { 48 | // your code here 49 | } 50 | } 51 | } 52 | 53 | contract Controller { 54 | Storage internal storage; 55 | 56 | constructor(addrerss _storage) { 57 | storage = Storage(_storage); 58 | } 59 | 60 | getStruct(uint256 idx) public returns (StructDefiner.MyStruct myStruct) { 61 | bytes memory _myStruct = storage.getStructByIdx(idx); 62 | assembly { 63 | // your code here 64 | } 65 | } 66 | } 67 | 68 | 69 | --------------------------------------------------------------------------------