forked from shankars99/StorkNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStorkNetPoC.sol
90 lines (78 loc) · 2.39 KB
/
StorkNetPoC.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
81
82
83
84
85
86
87
88
89
90
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
contract StorkData {
struct DataStruct {
address x;
uint256 y;
bool z;
}
// gas 23493
uint256 public max;
event UploadComplete(address indexed _from, DataStruct _value);
event UploadCompleteEncode(address indexed _from, bytes _data);
// gas for reading 1 30673
// gas for reading 2 30685
// gas for reading 3 30685
DataStruct[] public dataStruct;
// gas for storing 1 115613
// gas for storing 2 78601
// gas for storing 3 78601
function storeData(DataStruct calldata data) public {
dataStruct.push(data);
emit UploadComplete(msg.sender, data);
}
// gas for encoding 26392
// gas for encoding 26380
// gas for encoding 26380
function encode(DataStruct calldata data) public {
emit UploadCompleteEncode(msg.sender, abi.encode(data));
}
// gas for decoding 24183
// gas for decoding 24183
// gas for decoding 24183
function decode(bytes calldata data) public pure returns (DataStruct memory structData)
{
structData = abi.decode(data, (DataStruct));
}
// gas for execution with size 1 23384
// gas for execution with size 2 48421
// gas for execution with size 3 59301
function findMax() public {
for(uint8 i = 1; i<dataStruct.length; ++i){
if(dataStruct[i].y > max){
max = dataStruct[i].y;
}
}
}
// gas for execution [-decode]
// size 1 44211
// size 2 27099
// size 3 24176
function findMaxEncode_PreDecode(DataStruct calldata data) public {
if(data.y > max){
max = data.y;
}
}
//made the aboe an array and then badabing badaboom its perfect now (test this)
function findMaxEncode_PreDecode_ARRAY(DataStruct[] calldata data) public {
for(uint8 i = 1; i<data.length; ++i){
if(data[i].y > max){
max = data[i].y;
}
}
}
// gas for execution [+decode]
// size 1 45940
// size 2 28728
// size 3 25805
function findMaxEncoded_PostDecode(bytes calldata data) public {
DataStruct memory structData = decode(data);
if(structData.y > max){
max = structData.y;
}
}
// gas for resetting value of max 21489
function resetMax() external {
max = 0;
}
}