Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: P-885 add $network clause in solidity VC #3026

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ contract A20 is DynamicAssertion {
}

Logging.info("begin create assertion for A20");
AssertionLogic.Condition memory condition = AssertionLogic.Condition(
"$has_joined",
AssertionLogic.Op.Equal,
"true"
);
AssertionLogic.Condition memory condition = AssertionLogic
.newConditionWithoutSubCc(
"$has_joined",
AssertionLogic.Op.Equal,
"true"
);
string[] memory assertions = new string[](1);
assertions[0] = AssertionLogic.toString(condition);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,40 @@ library AssertionLogic {
string src;
Op op;
string dst;
CompositeCondition cc;
}

struct CompositeCondition {
Condition[] conditions;
bool isAnd; // true for 'And', false for 'Or'
}

function newConditionWithoutSubCc(
string memory src,
Op op,
string memory dst
) internal pure returns (Condition memory) {
CompositeCondition memory subCc;
return Condition(src, op, dst, subCc);
}

function addCondition(
CompositeCondition memory cc,
uint256 i,
string memory src,
Op op,
string memory dst
) internal pure {
cc.conditions[i] = Condition(src, op, dst);
CompositeCondition memory subCc;
cc.conditions[i] = Condition(src, op, dst, subCc);
}

function addCompositeCondition(
CompositeCondition memory cc,
uint256 i,
CompositeCondition memory subCc
) internal pure {
cc.conditions[i] = Condition("", Op.Equal, "", subCc);
}

function andOp(
Expand Down Expand Up @@ -85,12 +104,15 @@ library AssertionLogic {
abi.encodePacked(result, cc.isAnd ? '"and":[' : '"or":[')
);
for (uint256 i = 0; i < cc.conditions.length; i++) {
Condition memory c = cc.conditions[i];
if (i > 0) {
result = string(abi.encodePacked(result, ","));
}
result = string(
abi.encodePacked(result, toString(cc.conditions[i]))
);
if (c.cc.conditions.length > 0) {
result = string(abi.encodePacked(result, toString(c.cc)));
} else {
result = string(abi.encodePacked(result, toString(c)));
}
}
result = string(abi.encodePacked(result, "]"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,64 @@ library Identities {
chain = "combo";
}
}

function get_network_name(
uint32 network
) internal pure returns (string memory) {
if (network == Web3Networks.Polkadot) {
return "Polkadot";
}
if (network == Web3Networks.Kusama) {
return "Kusama";
}
if (network == Web3Networks.Litentry) {
return "Litentry";
}
if (network == Web3Networks.Litmus) {
return "Litmus";
}
if (network == Web3Networks.LitentryRococo) {
return "LitentryRococo";
}
if (network == Web3Networks.Khala) {
return "Khala";
}
if (network == Web3Networks.SubstrateTestnet) {
return "SubstrateTestnet";
}
if (network == Web3Networks.Ethereum) {
return "Ethereum";
}
if (network == Web3Networks.Bsc) {
return "Bsc";
}
if (network == Web3Networks.Polygon) {
return "Polygon";
}
if (network == Web3Networks.Arbitrum) {
return "Arbitrum";
}
if (network == Web3Networks.Solana) {
return "Solana";
}
if (network == Web3Networks.Combo) {
return "Combo";
}
if (network == Web3Networks.BitcoinP2tr) {
return "BitcoinP2tr";
}
if (network == Web3Networks.BitcoinP2pkh) {
return "BitcoinP2pkh";
}
if (network == Web3Networks.BitcoinP2sh) {
return "BitcoinP2sh";
}
if (network == Web3Networks.BitcoinP2wpkh) {
return "BitcoinP2wpkh";
}
if (network == Web3Networks.BitcoinP2wsh) {
return "BitcoinP2wsh";
}
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ abstract contract TokenHoldingAmount is DynamicAssertion {
string memory variable = "$holding_amount";
AssertionLogic.CompositeCondition memory cc = AssertionLogic
.CompositeCondition(
new AssertionLogic.Condition[](max > 0 && balance > 0 ? 3 : 2),
new AssertionLogic.Condition[](max > 0 && balance > 0 ? 4 : 3),
true
);
AssertionLogic.andOp(
Expand All @@ -160,9 +160,26 @@ abstract contract TokenHoldingAmount is DynamicAssertion {
AssertionLogic.Op.Equal,
tokenName
);

AssertionLogic.CompositeCondition memory networkCc = AssertionLogic
.CompositeCondition(
new AssertionLogic.Condition[](token.networks.length),
false
);
AssertionLogic.addCompositeCondition(cc, 1, networkCc);
for (uint256 i = 0; i < token.networks.length; i++) {
AssertionLogic.andOp(
networkCc,
i,
"$network",
AssertionLogic.Op.Equal,
Identities.get_network_name(token.networks[i].network)
);
}

AssertionLogic.andOp(
cc,
1,
2,
variable,
min == 0
? AssertionLogic.Op.GreaterThan
Expand All @@ -172,7 +189,7 @@ abstract contract TokenHoldingAmount is DynamicAssertion {
if (max > 0 && balance > 0) {
AssertionLogic.andOp(
cc,
2,
3,
variable,
AssertionLogic.Op.LessThan,
StringShift.toShiftedString(
Expand Down
Loading