08.SWC-108_State Variable Default Visibility
2023-07-13 15:51:12 # 09.SWC

SWC-108_State Variable Default Visibility

State Variable Default Visibility

  • Description: Labeling the visibility explicitly makes it easier to catch incorrect assumptions about who can access the variable.

  • Remediation: Variables can be specified as being public, internal or private. Explicitly define visibility for all state variables.

vulnerability contract

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
pragma solidity 0.4.24;

contract TestStorage {

uint storeduint1 = 15;
uint constant constuint = 16;
uint32 investmentsDeadlineTimeStamp = uint32(now);

bytes16 string1 = "test1";
bytes32 private string2 = "test1236";
string public string3 = "lets string something";

mapping (address => uint) public uints1;
mapping (address => DeviceData) structs1;

uint[] uintarray;
DeviceData[] deviceDataArray;

struct DeviceData {
string deviceBrand;
string deviceYear;
string batteryWearLevel;
}

function testStorage() public {
address address1 = 0xbccc714d56bc0da0fd33d96d2a87b680dd6d0df6;
address address2 = 0xaee905fdd3ed851e48d22059575b9f4245a82b04;

uints1[address1] = 88;
uints1[address2] = 99;

DeviceData memory dev1 = DeviceData("deviceBrand", "deviceYear", "wearLevel");

structs1[address1] = dev1;

uintarray.push(8000);
uintarray.push(9000);

deviceDataArray.push(dev1);
}
}
Prev
2023-07-13 15:51:12 # 09.SWC
Next