-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathpatricia_tree.sol
118 lines (97 loc) · 3.33 KB
/
patricia_tree.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
pragma solidity ^0.4.16;
pragma experimental "v0.5.0";
pragma experimental "ABIEncoderV2";
import {Data} from "../../src/patricia_tree/Data.sol";
import {PatriciaTree} from "../../src/patricia_tree/PatriciaTree.sol";
import {STLPerf} from "../STLPerf.sol";
contract PatriciaTreeDataPerf is STLPerf {
using Data for Data.Tree;
using Data for Data.Node;
using Data for Data.Edge;
using Data for Data.Label;
uint internal constant MAX_LENGTH = 256;
uint internal constant UINT256_ZEROES = 0;
uint internal constant UINT256_ONES = ~uint(0);
bytes32 internal constant B32_ZEROES = bytes32(UINT256_ZEROES);
bytes32 internal constant B32_ONES = bytes32(UINT256_ONES);
}
contract PerfPatriciaTreeInsertIntoEmpty is PatriciaTreeDataPerf {
function perf() public payable returns (uint) {
var pt = new PatriciaTree();
uint gasPre = msg.gas;
pt.insert("val", "VAL");
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}
contract PerfPatriciaTreeInsertAfterRoot is PatriciaTreeDataPerf {
function perf() public payable returns (uint) {
var pt = new PatriciaTree();
pt.insert("val", "VAL");
uint gasPre = msg.gas;
pt.insert("val2", "VAL2");
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}
contract PerfPatriciaTreeInsertReplaceRoot is PatriciaTreeDataPerf {
function perf() public payable returns (uint) {
var pt = new PatriciaTree();
pt.insert("val", "VAL");
uint gasPre = msg.gas;
pt.insert("val", "VAL2");
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}
contract PerfPatriciaTreeInsertReplaceAfterRoot is PatriciaTreeDataPerf {
function perf() public payable returns (uint) {
var pt = new PatriciaTree();
pt.insert("val", "VAL");
pt.insert("val2", "VAL2");
uint gasPre = msg.gas;
pt.insert("val2", "VAL3");
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}
contract PerfPatriciaTreeGetProofRoot is PatriciaTreeDataPerf {
function perf() public payable returns (uint) {
var pt = new PatriciaTree();
pt.insert("val", "VAL");
uint gasPre = msg.gas;
pt.getProof("val");
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}
contract PerfPatriciaTreeGetProofSecondAfterRoot is PatriciaTreeDataPerf {
function perf() public payable returns (uint) {
var pt = new PatriciaTree();
pt.insert("val", "VAL");
pt.insert("val2", "VAL2");
uint gasPre = msg.gas;
pt.getProof("val2");
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}
contract PerfPatriciaTreeValidateProofRootOnlyNode is PatriciaTreeDataPerf, PatriciaTree {
function perf() public payable returns (uint) {
insert("val", "VAL");
var (mask, siblings) = getProof("val");
uint gasPre = msg.gas;
verifyProof(tree.root, "val", "VAL", mask, siblings);
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}
contract PerfPatriciaTreeEdgeHash is PatriciaTreeDataPerf, PatriciaTree {
function perf() public payable returns (uint) {
var e = Data.Edge(0, Data.Label(0, 1));
uint gasPre = msg.gas;
e.edgeHash();
uint gasPost = msg.gas;
return gasPre - gasPost;
}
}