Skip to content

Commit 61afbb7

Browse files
authored
fix: P-885 add $network clause in solidity VC (#3026)
Co-authored-by: higherordertech <higherordertech>
1 parent 59506f9 commit 61afbb7

File tree

5 files changed

+181
-12
lines changed

5 files changed

+181
-12
lines changed

tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A20.sol

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ contract A20 is DynamicAssertion {
8585
}
8686

8787
Logging.info("begin create assertion for A20");
88-
AssertionLogic.Condition memory condition = AssertionLogic.Condition(
89-
"$has_joined",
90-
AssertionLogic.Op.Equal,
91-
"true"
92-
);
88+
AssertionLogic.Condition memory condition = AssertionLogic
89+
.newConditionWithoutSubCc(
90+
"$has_joined",
91+
AssertionLogic.Op.Equal,
92+
"true"
93+
);
9394
string[] memory assertions = new string[](1);
9495
assertions[0] = AssertionLogic.toString(condition);
9596

tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/AssertionLogic.sol

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,40 @@ library AssertionLogic {
3434
string src;
3535
Op op;
3636
string dst;
37+
CompositeCondition cc;
3738
}
3839

3940
struct CompositeCondition {
4041
Condition[] conditions;
4142
bool isAnd; // true for 'And', false for 'Or'
4243
}
4344

45+
function newConditionWithoutSubCc(
46+
string memory src,
47+
Op op,
48+
string memory dst
49+
) internal pure returns (Condition memory) {
50+
CompositeCondition memory subCc;
51+
return Condition(src, op, dst, subCc);
52+
}
53+
4454
function addCondition(
4555
CompositeCondition memory cc,
4656
uint256 i,
4757
string memory src,
4858
Op op,
4959
string memory dst
5060
) internal pure {
51-
cc.conditions[i] = Condition(src, op, dst);
61+
CompositeCondition memory subCc;
62+
cc.conditions[i] = Condition(src, op, dst, subCc);
63+
}
64+
65+
function addCompositeCondition(
66+
CompositeCondition memory cc,
67+
uint256 i,
68+
CompositeCondition memory subCc
69+
) internal pure {
70+
cc.conditions[i] = Condition("", Op.Equal, "", subCc);
5271
}
5372

5473
function andOp(
@@ -85,12 +104,15 @@ library AssertionLogic {
85104
abi.encodePacked(result, cc.isAnd ? '"and":[' : '"or":[')
86105
);
87106
for (uint256 i = 0; i < cc.conditions.length; i++) {
107+
Condition memory c = cc.conditions[i];
88108
if (i > 0) {
89109
result = string(abi.encodePacked(result, ","));
90110
}
91-
result = string(
92-
abi.encodePacked(result, toString(cc.conditions[i]))
93-
);
111+
if (c.cc.conditions.length > 0) {
112+
result = string(abi.encodePacked(result, toString(c.cc)));
113+
} else {
114+
result = string(abi.encodePacked(result, toString(c)));
115+
}
94116
}
95117
result = string(abi.encodePacked(result, "]"));
96118
}

tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Identities.sol

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,64 @@ library Identities {
276276
chain = "combo";
277277
}
278278
}
279+
280+
function get_network_name(
281+
uint32 network
282+
) internal pure returns (string memory) {
283+
if (network == Web3Networks.Polkadot) {
284+
return "Polkadot";
285+
}
286+
if (network == Web3Networks.Kusama) {
287+
return "Kusama";
288+
}
289+
if (network == Web3Networks.Litentry) {
290+
return "Litentry";
291+
}
292+
if (network == Web3Networks.Litmus) {
293+
return "Litmus";
294+
}
295+
if (network == Web3Networks.LitentryRococo) {
296+
return "LitentryRococo";
297+
}
298+
if (network == Web3Networks.Khala) {
299+
return "Khala";
300+
}
301+
if (network == Web3Networks.SubstrateTestnet) {
302+
return "SubstrateTestnet";
303+
}
304+
if (network == Web3Networks.Ethereum) {
305+
return "Ethereum";
306+
}
307+
if (network == Web3Networks.Bsc) {
308+
return "Bsc";
309+
}
310+
if (network == Web3Networks.Polygon) {
311+
return "Polygon";
312+
}
313+
if (network == Web3Networks.Arbitrum) {
314+
return "Arbitrum";
315+
}
316+
if (network == Web3Networks.Solana) {
317+
return "Solana";
318+
}
319+
if (network == Web3Networks.Combo) {
320+
return "Combo";
321+
}
322+
if (network == Web3Networks.BitcoinP2tr) {
323+
return "BitcoinP2tr";
324+
}
325+
if (network == Web3Networks.BitcoinP2pkh) {
326+
return "BitcoinP2pkh";
327+
}
328+
if (network == Web3Networks.BitcoinP2sh) {
329+
return "BitcoinP2sh";
330+
}
331+
if (network == Web3Networks.BitcoinP2wpkh) {
332+
return "BitcoinP2wpkh";
333+
}
334+
if (network == Web3Networks.BitcoinP2wsh) {
335+
return "BitcoinP2wsh";
336+
}
337+
return "";
338+
}
279339
}

tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/TokenHoldingAmount.sol

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ abstract contract TokenHoldingAmount is DynamicAssertion {
150150
string memory variable = "$holding_amount";
151151
AssertionLogic.CompositeCondition memory cc = AssertionLogic
152152
.CompositeCondition(
153-
new AssertionLogic.Condition[](max > 0 && balance > 0 ? 3 : 2),
153+
new AssertionLogic.Condition[](max > 0 && balance > 0 ? 4 : 3),
154154
true
155155
);
156156
AssertionLogic.andOp(
@@ -160,9 +160,26 @@ abstract contract TokenHoldingAmount is DynamicAssertion {
160160
AssertionLogic.Op.Equal,
161161
tokenName
162162
);
163+
164+
AssertionLogic.CompositeCondition memory networkCc = AssertionLogic
165+
.CompositeCondition(
166+
new AssertionLogic.Condition[](token.networks.length),
167+
false
168+
);
169+
AssertionLogic.addCompositeCondition(cc, 1, networkCc);
170+
for (uint256 i = 0; i < token.networks.length; i++) {
171+
AssertionLogic.andOp(
172+
networkCc,
173+
i,
174+
"$network",
175+
AssertionLogic.Op.Equal,
176+
Identities.get_network_name(token.networks[i].network)
177+
);
178+
}
179+
163180
AssertionLogic.andOp(
164181
cc,
165-
1,
182+
2,
166183
variable,
167184
min == 0
168185
? AssertionLogic.Op.GreaterThan
@@ -172,7 +189,7 @@ abstract contract TokenHoldingAmount is DynamicAssertion {
172189
if (max > 0 && balance > 0) {
173190
AssertionLogic.andOp(
174191
cc,
175-
2,
192+
3,
176193
variable,
177194
AssertionLogic.Op.LessThan,
178195
StringShift.toShiftedString(

0 commit comments

Comments
 (0)