-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calyptus468.sol
63 lines (48 loc) · 1.45 KB
/
Calyptus468.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
// https://x.com/calyptus_web3/status/1861320650595430453
// The below contract has a function that gets the location at which the balances mapping is stored.
// Can you tell what will be the output if the getBalanceSlot() function is called?
contract StorageContract {
uint constant code = 300;
mapping(address => uint256) private balances;
function getBalancesSlot()
external
pure
returns (uint256){
// get the location of the slot where the mapping is saved
uint256 slot;
assembly {
slot := balances.slot
}
return (slot);
}
}
////////////////////////////////////////////////////////////////////////
contract StorageContractB{
uint public acode = 300;
mapping(address => uint256) private balances;
function getCodeSlot() external pure returns (uint256){
// get the location of the slot where the uint public acode is saved
uint256 slot;
assembly {
slot := acode.slot
}
return (slot);
}
function getBalancesSlot()
external
pure
returns (uint256){
// get the location of the slot where the mapping is saved
uint256 slot;
assembly {
slot := balances.slot
}
return (slot);
}
}
/*
uint constant code se not saved at slot 0
uint public acode is saved at slot 0
*/