-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calyptus390.sol
80 lines (67 loc) · 1.51 KB
/
Calyptus390.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// SPDX-License-Identifier:MIT
pragma solidity >= 0.8.24;
//https://x.com/CalyptusCareers/status/1801150877165568505
//In the given smart contract, which of the two functions, g() or h(),
//will change the value of x when called through f()? 🤔
contract C {
uint[20] x;
function f() public {
g(x);
h(x);
}
function g(uint[20] memory y) internal pure {
y[2] = 3;
}
function h(uint[20] storage y) internal {
y[3] = 4;
}
}
/////////////////////////////////////////////////////////////
contract Trying {
uint[2] public x;
// set uint[2] x during deploynment
constructor() {
x[0] = 10;
x[1] = 20;
}
// set uint[2] x manually
function setX(uint a, uint b) public {
x[0] = a;
x[1] = b;
}
function f() public returns(uint[2] memory b){
g(x);
h(x);
return b;
}
function g(uint[2] memory y) internal pure {
y[1] = 33;
}
function h(uint[2] storage y) internal {
y[0] = 44;
}
}
contract Tryin2{
uint[20] public x;
// set uint[2] x during deploynment
constructor() {
x[0] = 10;
x[10] = 20;
}
// set uint[2] x manually
function setX(uint a, uint b) public {
x[6] = a;
x[1] = b;
}
function f() public returns(uint[20] memory b){
g(x);
h(x);
return b;
}
function g(uint[20] memory y) internal pure {
y[7] = 33;
}
function h(uint[20] storage y) internal {
y[19] = 44;
}
}