Skip to content

Commit 51ce038

Browse files
committed
temp
1 parent e9d8692 commit 51ce038

File tree

2 files changed

+92
-15
lines changed

2 files changed

+92
-15
lines changed

junior-1/solidity/README.md

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
## Типы. Reference types
7070

7171
1. Что можешь рассказать про reference types?
72-
- Data location(storage, memory, calldata)
73-
- Массивы(динамические и с фиксированной длиной)
72+
- Data location (storage, memory, calldata)
73+
- Массивы (динамические и с фиксированной длиной)
7474
- Структуры
7575
2. Как получить длину массива?
7676
3. Как добавлять данные в массив?
@@ -173,3 +173,69 @@ contract C {
173173
1. Что такое библиотека?
174174
2. Как подключить библиотеку?
175175
- Что такое using for?
176+
177+
178+
## Интересные вопросы
179+
180+
1. Округление при делении.
181+
- Какой ожидается результат вызова функции `roundingDivision()`? В чем заключается проблема? Как это можно обойти?
182+
```solidity
183+
function roundingDivision() external pure returns (uint256) {
184+
return uint256(7) / uint256(5);
185+
}
186+
```
187+
- Какой ожидается результат вызова функции `divisionByZero()`?
188+
```solidity
189+
function divisionByZero() external pure returns (uint256) {
190+
return uint256(7) / 0;
191+
}
192+
```
193+
2. Что произойдет при вызове функции `setOwner(addressB, anyAccount)` на контракте A? Чему будет равен вызов функций `manager()` и `owner()`? Почему важен порядок переменных в этих двух контрактах?
194+
```solidity
195+
contract A {
196+
address public manager;
197+
address public owner;
198+
199+
function setOwner(address target, address account) external {
200+
(bool success,) = target.delegatecall(
201+
abi.encodeWithSignature("setOwner(address)", account)
202+
);
203+
204+
if (!success) {
205+
revert();
206+
}
207+
}
208+
}
209+
210+
contract B {
211+
address public owner;
212+
address public manager;
213+
214+
function setOwner(address account) external {
215+
owner = account;
216+
}
217+
}
218+
```
219+
3. Работа модификаторов. Что вернут переменные `stateA`, `stateB`, `stateC` после вызова функции changeStates()?
220+
```solidity
221+
contract Modifier {
222+
uint256 public stateA;
223+
uint256 public stateB;
224+
uint256 public stateC;
225+
226+
modifier changeStateA() {
227+
stateA++;
228+
_;
229+
}
230+
231+
modifier changeStateB() {
232+
_;
233+
stateB++;
234+
_;
235+
}
236+
237+
function changeStates() external changeStateA changeStateB {
238+
stateC++;
239+
}
240+
}
241+
```

junior-2/solidity/README.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
pragma solidity 0.8.0;
2626
2727
contract Counter {
28-
uint8 _counter= 255;
28+
uint8 _counter = 255;
2929
3030
function increase() public payable {
3131
_counter++;
@@ -42,10 +42,12 @@ contract Counter {
4242
pragma solidity 0.8.0;
4343
4444
contract Counter {
45-
uint8 _counter= 255;
45+
uint8 _counter = 255;
4646
4747
function increase() public payable {
48-
unchecked {_counter++;}
48+
unchecked {
49+
_counter++;
50+
}
4951
}
5052
5153
function getCounter() external view returns(uint8) {
@@ -56,16 +58,18 @@ contract Counter {
5658

5759
```solidity
5860
// SPDX-License-Identifier: MIT
59-
pragma solidity 0.7.0;
61+
pragma solidity 0.8.0;
6062
6163
contract Counter {
62-
uint8 _counter= 255;
64+
int8 _counter= -128;
6365
64-
function increase() public payable {
65-
_counter++;
66+
function decrease() public payable {
67+
unchecked {
68+
_counter--;
69+
}
6670
}
6771
68-
function getCounter() external view returns(uint8) {
72+
function getCounter() external view returns(int8) {
6973
return _counter;
7074
}
7175
}
@@ -76,13 +80,19 @@ contract Counter {
7680
pragma solidity 0.8.0;
7781
7882
contract Counter {
79-
int8 _counter= -128;
83+
uint8 _counter = 255;
8084
81-
function decrease() public payable {
82-
unchecked {_counter--;}
85+
function increase() public payable {
86+
unchecked {
87+
_increase();
88+
}
8389
}
8490
85-
function getCounter() external view returns(int8) {
91+
function _increase() private {
92+
_counter++;
93+
}
94+
95+
function getCounter() external view returns(uint8) {
8696
return _counter;
8797
}
8898
}
@@ -268,7 +278,7 @@ contract Counter {
268278

269279
1. Какие есть два возможных способа создания контрактов?
270280
2. Как создать контракт через new? Что на самом деле внутри происходит при создании таким способом?
271-
3. Для чего нужен constructor? Сколько раз он вызывается? Можно ли делать перегрузку для constructor?
281+
3. Для чего нужен constructor? Сколько раз он вызывается? Можно ли делать перегрузку для constructor? Является ли constructor частью байт-кода контракта?
272282
4. Как передать эфир при создании контракта?
273283
5. Как создать контракт через create? Как создать контракт через create2? Какие различия между create и create2? Как у них происходит образование адреса контракта? Почему не безопасно создавать через create?
274284
6. Можно ли каким-то образом передеплоить смарт-контракт на тот же адрес но с другим кодом?
@@ -278,6 +288,7 @@ contract Counter {
278288
- [EVM Dialect](https://docs.soliditylang.org/en/v0.8.18/yul.html#evm-dialect)
279289
- [About create and create2](https://mixbytes.io/blog/pitfalls-of-using-cteate-cteate2-and-extcodesize-opcodes)
280290
- [Factory patterns](https://blog.logrocket.com/cloning-solidity-smart-contracts-factory-pattern/)
291+
- [Ethereum smart contract creation code](https://www.rareskills.io/post/ethereum-contract-creation-code)
281292

282293
## Keccak256
283294

0 commit comments

Comments
 (0)