@coti-io/coti-contracts 1.0.0 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/.github/workflows/npm-publish.yml +2 -1
  2. package/CONTRIBUTING.md +2 -2
  3. package/LICENSE +1 -1
  4. package/README.md +18 -35
  5. package/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.sol +112 -0
  6. package/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol +152 -0
  7. package/contracts/mocks/utils/mpc/BitwiseTestsContract.sol +11 -1
  8. package/contracts/mocks/utils/mpc/Comparison2TestsContract.sol +8 -0
  9. package/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.sol +33 -4
  10. package/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract.sol +35 -10
  11. package/contracts/mocks/utils/mpc/ShiftTestsContract.sol +126 -0
  12. package/contracts/mocks/utils/mpc/TransferTestsContract.sol +3 -0
  13. package/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract.sol +222 -0
  14. package/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract.sol +222 -0
  15. package/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol +223 -0
  16. package/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract.sol +222 -0
  17. package/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract.sol +265 -0
  18. package/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol +281 -0
  19. package/contracts/token/PrivateERC20/PrivateERC20.sol +1 -1
  20. package/contracts/token/PrivateERC721/IERC721Errors.sol +57 -0
  21. package/contracts/token/PrivateERC721/PrivateERC721.sol +1 -1
  22. package/contracts/utils/mpc/MpcCore.sol +40 -0
  23. package/contracts/utils/mpc/MpcInterface.sol +2 -0
  24. package/hardhat.config.ts +9 -1
  25. package/package.json +20 -4
  26. package/test/onboard/AccountOnboard.test.ts +2 -2
  27. package/test/token/PrivateERC20/PrivateERC20.test.ts +2 -2
  28. package/test/utils/accounts.ts +2 -2
  29. package/test/utils/mpc/Precompile.test.ts +24 -2
  30. package/typechain-types/@openzeppelin/contracts/interfaces/index.ts +0 -2
  31. package/typechain-types/contracts/GasTest.ts +91 -0
  32. package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.ts +66 -0
  33. package/typechain-types/contracts/mocks/utils/mpc/BitwiseTestsContract.ts +6 -0
  34. package/typechain-types/contracts/mocks/utils/mpc/Comparison2TestsContract.ts +6 -0
  35. package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract.ts +36 -6
  36. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowance64TestsContract.ts +251 -0
  37. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowanceTestsContract.ts +250 -0
  38. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/index.ts +5 -0
  39. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.ts +389 -0
  40. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract.ts +391 -0
  41. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract.ts +391 -0
  42. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_64TestsContract.ts +391 -0
  43. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_8TestsContract.ts +391 -0
  44. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/index.ts +5 -0
  45. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.ts +391 -0
  46. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract.ts +391 -0
  47. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract.ts +306 -0
  48. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferTestsContract.ts +125 -0
  49. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferWithAllowanceTestsContract.ts +125 -0
  50. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/index.ts +5 -0
  51. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.ts +296 -0
  52. package/typechain-types/contracts/mocks/utils/mpc/index.ts +7 -0
  53. package/typechain-types/contracts/token/PrivateERC721/IERC721Errors.ts +69 -0
  54. package/typechain-types/contracts/token/PrivateERC721/index.ts +1 -0
  55. package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +38 -0
  56. package/typechain-types/factories/@openzeppelin/contracts/interfaces/index.ts +0 -1
  57. package/typechain-types/factories/contracts/GasTest__factory.ts +75 -0
  58. package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +1 -1
  59. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +1 -1
  60. package/typechain-types/factories/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock__factory.ts +1 -1
  61. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +73 -1
  62. package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +11 -1
  63. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1TestsContract__factory.ts +1 -1
  64. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +11 -1
  65. package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +1 -1
  66. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +1 -1
  67. package/typechain-types/factories/contracts/mocks/utils/mpc/MiscellaneousTestsContract__factory.ts +1 -1
  68. package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract__factory.ts +26 -30
  69. package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +1 -1
  70. package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +1 -1
  71. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +1 -1
  72. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +1 -1
  73. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowance64TestsContract__factory.ts +294 -0
  74. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowanceTestsContract__factory.ts +292 -0
  75. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/index.ts +5 -0
  76. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract__factory.ts +720 -0
  77. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract__factory.ts +724 -0
  78. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract__factory.ts +724 -0
  79. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_64TestsContract__factory.ts +724 -0
  80. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_8TestsContract__factory.ts +724 -0
  81. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/index.ts +5 -0
  82. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract__factory.ts +724 -0
  83. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract__factory.ts +724 -0
  84. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract__factory.ts +507 -0
  85. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferTestsContract__factory.ts +150 -0
  86. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferWithAllowanceTestsContract__factory.ts +150 -0
  87. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/index.ts +5 -0
  88. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract__factory.ts +434 -0
  89. package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +7 -0
  90. package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +1 -1
  91. package/typechain-types/factories/contracts/onboard/AccountOnboard__factory.ts +1 -1
  92. package/typechain-types/factories/contracts/token/PrivateERC721/IERC721Errors__factory.ts +128 -0
  93. package/typechain-types/factories/contracts/token/PrivateERC721/index.ts +1 -0
  94. package/typechain-types/factories/contracts/utils/mpc/MpcCore__factory.ts +1 -1
  95. package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +58 -0
  96. package/typechain-types/hardhat.d.ts +144 -54
  97. package/typechain-types/index.ts +16 -6
  98. package/contracts/access/DataPrivacyFramework/README.md +0 -68
  99. package/contracts/onboard/README.md +0 -65
  100. package/contracts/token/PrivateERC20/README.md +0 -104
  101. package/contracts/token/PrivateERC721/README.md +0 -282
  102. package/contracts/utils/mpc/README.md +0 -82
@@ -0,0 +1,126 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.19;
3
+
4
+ import "../../../utils/mpc/MpcCore.sol";
5
+
6
+ contract ShiftTestsContract {
7
+
8
+ struct AllGTCastingValues {
9
+ gtUint8 a8_s;
10
+ gtUint8 b8_s;
11
+ gtUint16 a16_s;
12
+ gtUint16 b16_s;
13
+ gtUint32 a32_s;
14
+ gtUint32 b32_s;
15
+ gtUint64 a64_s;
16
+ gtUint64 b64_s;
17
+ }
18
+
19
+ struct Check16 {
20
+ gtUint16 res16_16;
21
+ gtUint16 res8_16;
22
+ gtUint16 res16_8;
23
+ }
24
+
25
+ struct Check32 {
26
+ gtUint32 res32_32;
27
+ gtUint32 res8_32;
28
+ gtUint32 res32_8;
29
+ gtUint32 res16_32;
30
+ gtUint32 res32_16;
31
+ }
32
+
33
+ struct Check64 {
34
+ gtUint64 res64_64;
35
+ gtUint64 res8_64;
36
+ gtUint64 res64_8;
37
+ gtUint64 res16_64;
38
+ gtUint64 res64_16;
39
+ gtUint64 res32_64;
40
+ gtUint64 res64_32;
41
+ }
42
+
43
+ uint8 result;
44
+ uint8 result8;
45
+ uint16 result16;
46
+ uint32 result32;
47
+ uint64 result64;
48
+
49
+ function getResult() public view returns (uint8) {
50
+ return result;
51
+ }
52
+
53
+ function getAllShiftResults() public view returns (uint8, uint16, uint32, uint64) {
54
+ return (result8, result16, result32, result64);
55
+ }
56
+
57
+ function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{
58
+ castingValues.a8_s = MpcCore.setPublic8(a);
59
+ castingValues.b8_s = MpcCore.setPublic8(b);
60
+ castingValues.a16_s = MpcCore.setPublic16(a);
61
+ castingValues.b16_s = MpcCore.setPublic16(b);
62
+ castingValues.a32_s = MpcCore.setPublic32(a);
63
+ castingValues.b32_s = MpcCore.setPublic32(b);
64
+ castingValues.a64_s = MpcCore.setPublic64(a);
65
+ castingValues.b64_s = MpcCore.setPublic64(b);
66
+ }
67
+
68
+ function decryptAndCompareResults16(Check16 memory check16) public returns (uint16){
69
+
70
+ // Calculate the result
71
+ uint16 result = MpcCore.decrypt(check16.res16_16);
72
+
73
+ require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8),
74
+ "decryptAndCompareAllResults: Failed to decrypt and compare all results");
75
+
76
+ return result;
77
+ }
78
+
79
+ function decryptAndCompareResults32(Check32 memory check32) public returns (uint32){
80
+
81
+ // Calculate the result
82
+ uint32 result = MpcCore.decrypt(check32.res32_32);
83
+
84
+ require(result == MpcCore.decrypt(check32.res8_32) && result == MpcCore.decrypt(check32.res32_8)
85
+ && result == MpcCore.decrypt(check32.res32_16) && result == MpcCore.decrypt(check32.res16_32),
86
+ "decryptAndCompareAllResults: Failed to decrypt and compare all results");
87
+
88
+ return result;
89
+ }
90
+
91
+ function decryptAndCompareResults64(Check64 memory check64) public returns (uint64){
92
+
93
+ // Calculate the result
94
+ uint64 result = MpcCore.decrypt(check64.res64_64);
95
+
96
+ require(result == MpcCore.decrypt(check64.res8_64) && result == MpcCore.decrypt(check64.res64_8)
97
+ && result == MpcCore.decrypt(check64.res64_16) && result == MpcCore.decrypt(check64.res16_64)
98
+ && result == MpcCore.decrypt(check64.res64_32) && result == MpcCore.decrypt(check64.res32_64),
99
+ "decryptAndCompareAllResults: Failed to decrypt and compare all results");
100
+
101
+ return result;
102
+ }
103
+
104
+ function shlTest(uint8 a, uint8 b) public returns (uint8, uint16, uint32, uint64) {
105
+ AllGTCastingValues memory castingValues;
106
+ setPublicValues(castingValues, a, b);
107
+
108
+ result8 = MpcCore.decrypt(MpcCore.shl(castingValues.a8_s, b));
109
+ result16 = MpcCore.decrypt(MpcCore.shl(castingValues.a16_s, b));
110
+ result32 = MpcCore.decrypt(MpcCore.shl(castingValues.a32_s, b));
111
+ result64 = MpcCore.decrypt(MpcCore.shl(castingValues.a64_s, b));
112
+ return (result8, result16, result32, result64);
113
+ }
114
+
115
+ function shrTest(uint8 a, uint8 b) public returns (uint8) {
116
+ AllGTCastingValues memory castingValues;
117
+ setPublicValues(castingValues, a, b);
118
+
119
+ result = MpcCore.decrypt(MpcCore.shr(castingValues.a8_s, b));
120
+ require(result == MpcCore.decrypt(MpcCore.shr(castingValues.a16_s, b)) && result == MpcCore.decrypt(MpcCore.shr(castingValues.a32_s, b))
121
+ && result == MpcCore.decrypt(MpcCore.shr(castingValues.a64_s, b)),
122
+ "shrTest failed");
123
+ return result;
124
+ }
125
+
126
+ }
@@ -51,6 +51,9 @@ contract TransferTestsContract {
51
51
 
52
52
  (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b8_s, allAmountValues.amount16_s);
53
53
  require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed");
54
+
55
+ (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b16_s, allAmountValues.amount8_s);
56
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed");
54
57
  }
55
58
 
56
59
  function computeAndCheckTransfer32(AllGTCastingValues memory allGTCastingValues, AllAmountValues memory allAmountValues, uint8 new_a, uint8 new_b, bool res) public {
@@ -0,0 +1,222 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.19;
3
+
4
+ import "../../../utils/mpc/MpcCore.sol";
5
+
6
+ contract TransferWithAllowance64_16TestsContract {
7
+
8
+ struct AllGTCastingValues {
9
+ gtUint8 a8_s;
10
+ gtUint8 b8_s;
11
+ gtUint16 a16_s;
12
+ gtUint16 b16_s;
13
+ gtUint32 a32_s;
14
+ gtUint32 b32_s;
15
+ gtUint64 a64_s;
16
+ gtUint64 b64_s;
17
+ }
18
+
19
+ struct AllAmountValues {
20
+ gtUint8 amount8_s;
21
+ gtUint16 amount16_s;
22
+ gtUint32 amount32_s;
23
+ gtUint64 amount64_s;
24
+ uint8 amount;
25
+ }
26
+
27
+ struct AllAllowanceValues {
28
+ gtUint8 allowance8_s;
29
+ gtUint16 allowance16_s;
30
+ gtUint32 allowance32_s;
31
+ gtUint64 allowance64_s;
32
+ uint8 allowance;
33
+ }
34
+
35
+ uint8 newA;
36
+ uint8 newB;
37
+ bool result;
38
+ uint8 newAllowance;
39
+
40
+ function getResults() public view returns (uint8, uint8, bool, uint8) {
41
+ return (newA, newB, result, newAllowance);
42
+ }
43
+
44
+
45
+ function computeAndCheckTransfer64_8_16(
46
+ AllGTCastingValues memory allGTCastingValues,
47
+ AllAmountValues memory allAmountValues,
48
+ AllAllowanceValues memory allAllowanceValues,
49
+ uint8 new_a,
50
+ uint8 new_b,
51
+ bool res,
52
+ uint8 new_allowance
53
+ )
54
+ public
55
+ {
56
+ (gtUint64 newA_s, gtUint64 newB_s, gtBool res_s, gtUint64 newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a8_s, allGTCastingValues.b64_s, allAmountValues.amount8_s, allAllowanceValues.allowance16_s);
57
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
58
+
59
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b8_s, allAmountValues.amount8_s, allAllowanceValues.allowance16_s);
60
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
61
+
62
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b64_s, allAmountValues.amount8_s, allAllowanceValues.allowance16_s);
63
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
64
+
65
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a16_s, allGTCastingValues.b64_s, allAmountValues.amount8_s, allAllowanceValues.allowance16_s);
66
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
67
+
68
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b16_s, allAmountValues.amount8_s, allAllowanceValues.allowance16_s);
69
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
70
+
71
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a32_s, allGTCastingValues.b64_s, allAmountValues.amount8_s, allAllowanceValues.allowance16_s);
72
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
73
+
74
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b32_s, allAmountValues.amount8_s, allAllowanceValues.allowance16_s);
75
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
76
+ }
77
+
78
+
79
+ function computeAndCheckTransfer64_16_16(
80
+ AllGTCastingValues memory allGTCastingValues,
81
+ AllAmountValues memory allAmountValues,
82
+ AllAllowanceValues memory allAllowanceValues,
83
+ uint8 new_a,
84
+ uint8 new_b,
85
+ bool res,
86
+ uint8 new_allowance
87
+ )
88
+ public
89
+ {
90
+ (gtUint64 newA_s, gtUint64 newB_s, gtBool res_s, gtUint64 newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a8_s, allGTCastingValues.b64_s, allAmountValues.amount16_s, allAllowanceValues.allowance16_s);
91
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
92
+
93
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b8_s, allAmountValues.amount16_s, allAllowanceValues.allowance16_s);
94
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
95
+
96
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a16_s, allGTCastingValues.b64_s, allAmountValues.amount16_s, allAllowanceValues.allowance16_s);
97
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
98
+
99
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b16_s, allAmountValues.amount16_s, allAllowanceValues.allowance16_s);
100
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
101
+
102
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b64_s, allAmountValues.amount16_s, allAllowanceValues.allowance16_s);
103
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
104
+
105
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a32_s, allGTCastingValues.b64_s, allAmountValues.amount16_s, allAllowanceValues.allowance16_s);
106
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
107
+
108
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b32_s, allAmountValues.amount16_s, allAllowanceValues.allowance16_s);
109
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
110
+ }
111
+
112
+ function computeAndCheckTransfer64_32_16(
113
+ AllGTCastingValues memory allGTCastingValues,
114
+ AllAmountValues memory allAmountValues,
115
+ AllAllowanceValues memory allAllowanceValues,
116
+ uint8 new_a,
117
+ uint8 new_b,
118
+ bool res,
119
+ uint8 new_allowance
120
+ )
121
+ public
122
+ {
123
+ (gtUint64 newA_s, gtUint64 newB_s, gtBool res_s, gtUint64 newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a8_s, allGTCastingValues.b64_s, allAmountValues.amount32_s, allAllowanceValues.allowance16_s);
124
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
125
+
126
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b8_s, allAmountValues.amount32_s, allAllowanceValues.allowance16_s);
127
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
128
+
129
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a16_s, allGTCastingValues.b64_s, allAmountValues.amount32_s, allAllowanceValues.allowance16_s);
130
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
131
+
132
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b16_s, allAmountValues.amount32_s, allAllowanceValues.allowance16_s);
133
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
134
+
135
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a32_s, allGTCastingValues.b64_s, allAmountValues.amount32_s, allAllowanceValues.allowance16_s);
136
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
137
+
138
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b32_s, allAmountValues.amount32_s, allAllowanceValues.allowance16_s);
139
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
140
+
141
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b64_s, allAmountValues.amount32_s, allAllowanceValues.allowance16_s);
142
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
143
+ }
144
+
145
+
146
+ function computeAndCheckTransfer64_64_16(
147
+ AllGTCastingValues memory allGTCastingValues,
148
+ AllAmountValues memory allAmountValues,
149
+ AllAllowanceValues memory allAllowanceValues,
150
+ uint8 new_a,
151
+ uint8 new_b,
152
+ bool res,
153
+ uint8 new_allowance
154
+ )
155
+ public
156
+ {
157
+ (gtUint64 newA_s, gtUint64 newB_s, gtBool res_s, gtUint64 newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a8_s, allGTCastingValues.b64_s, allAmountValues.amount64_s, allAllowanceValues.allowance16_s);
158
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
159
+
160
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b8_s, allAmountValues.amount64_s, allAllowanceValues.allowance16_s);
161
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
162
+
163
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b64_s, allAmountValues.amount64_s, allAllowanceValues.allowance16_s);
164
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
165
+
166
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a16_s, allGTCastingValues.b64_s, allAmountValues.amount64_s, allAllowanceValues.allowance16_s);
167
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
168
+
169
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b16_s, allAmountValues.amount64_s, allAllowanceValues.allowance16_s);
170
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
171
+
172
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a32_s, allGTCastingValues.b64_s, allAmountValues.amount64_s, allAllowanceValues.allowance16_s);
173
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
174
+
175
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b32_s, allAmountValues.amount64_s, allAllowanceValues.allowance16_s);
176
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
177
+ }
178
+
179
+
180
+ function transferWithAllowance64Test(uint8 a, uint8 b, uint8 amount, uint8 allowance) public returns (uint8, uint8, bool, uint8) {
181
+ AllGTCastingValues memory allGTCastingValues;
182
+ AllAmountValues memory allAmountValues;
183
+ AllAllowanceValues memory allAllowanceValues;
184
+ allGTCastingValues.a8_s = MpcCore.setPublic8(a);
185
+ allGTCastingValues.b8_s = MpcCore.setPublic8(b);
186
+ allGTCastingValues.a16_s = MpcCore.setPublic16(a);
187
+ allGTCastingValues.b16_s = MpcCore.setPublic16(b);
188
+ allGTCastingValues.a32_s = MpcCore.setPublic32(a);
189
+ allGTCastingValues.b32_s = MpcCore.setPublic32(b);
190
+ allGTCastingValues.a64_s = MpcCore.setPublic64(a);
191
+ allGTCastingValues.b64_s = MpcCore.setPublic64(b);
192
+ allAmountValues.amount8_s = MpcCore.setPublic8(amount);
193
+ allAmountValues.amount16_s = MpcCore.setPublic16(amount);
194
+ allAmountValues.amount32_s = MpcCore.setPublic32(amount);
195
+ allAmountValues.amount64_s = MpcCore.setPublic64(amount);
196
+ allAmountValues.amount = amount;
197
+ allAllowanceValues.allowance8_s = MpcCore.setPublic8(allowance);
198
+ allAllowanceValues.allowance16_s = MpcCore.setPublic16(allowance);
199
+ allAllowanceValues.allowance32_s = MpcCore.setPublic32(allowance);
200
+ allAllowanceValues.allowance64_s = MpcCore.setPublic64(allowance);
201
+ allAllowanceValues.allowance = allowance;
202
+
203
+ // Calculate the expected result
204
+ (gtUint8 newA_s, gtUint8 newB_s, gtBool res_s, gtUint8 newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a8_s, allGTCastingValues.b8_s, allAmountValues.amount8_s, allAllowanceValues.allowance8_s);
205
+ newA = MpcCore.decrypt(newA_s);
206
+ newB = MpcCore.decrypt(newB_s);
207
+ result = MpcCore.decrypt(res_s);
208
+ newAllowance = MpcCore.decrypt(newAllowance_s);
209
+
210
+ // Calculate the result with casting to 64
211
+ computeAndCheckTransfer64_8_16(allGTCastingValues, allAmountValues, allAllowanceValues, newA, newB, result, newAllowance);
212
+
213
+ computeAndCheckTransfer64_16_16(allGTCastingValues, allAmountValues, allAllowanceValues, newA, newB, result, newAllowance);
214
+
215
+ computeAndCheckTransfer64_32_16(allGTCastingValues, allAmountValues, allAllowanceValues, newA, newB, result, newAllowance);
216
+
217
+ computeAndCheckTransfer64_64_16(allGTCastingValues, allAmountValues, allAllowanceValues, newA, newB, result, newAllowance);
218
+
219
+ return (newA, newB, result, newAllowance);
220
+ }
221
+
222
+ }
@@ -0,0 +1,222 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.19;
3
+
4
+ import "../../../utils/mpc/MpcCore.sol";
5
+
6
+ contract TransferWithAllowance64_32TestsContract {
7
+
8
+ struct AllGTCastingValues {
9
+ gtUint8 a8_s;
10
+ gtUint8 b8_s;
11
+ gtUint16 a16_s;
12
+ gtUint16 b16_s;
13
+ gtUint32 a32_s;
14
+ gtUint32 b32_s;
15
+ gtUint64 a64_s;
16
+ gtUint64 b64_s;
17
+ }
18
+
19
+ struct AllAmountValues {
20
+ gtUint8 amount8_s;
21
+ gtUint16 amount16_s;
22
+ gtUint32 amount32_s;
23
+ gtUint64 amount64_s;
24
+ uint8 amount;
25
+ }
26
+
27
+ struct AllAllowanceValues {
28
+ gtUint8 allowance8_s;
29
+ gtUint16 allowance16_s;
30
+ gtUint32 allowance32_s;
31
+ gtUint64 allowance64_s;
32
+ uint8 allowance;
33
+ }
34
+
35
+ uint8 newA;
36
+ uint8 newB;
37
+ bool result;
38
+ uint8 newAllowance;
39
+
40
+ function getResults() public view returns (uint8, uint8, bool, uint8) {
41
+ return (newA, newB, result, newAllowance);
42
+ }
43
+
44
+
45
+ function computeAndCheckTransfer64_8_32(
46
+ AllGTCastingValues memory allGTCastingValues,
47
+ AllAmountValues memory allAmountValues,
48
+ AllAllowanceValues memory allAllowanceValues,
49
+ uint8 new_a,
50
+ uint8 new_b,
51
+ bool res,
52
+ uint8 new_allowance
53
+ )
54
+ public
55
+ {
56
+ (gtUint64 newA_s, gtUint64 newB_s, gtBool res_s, gtUint64 newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a8_s, allGTCastingValues.b64_s, allAmountValues.amount8_s, allAllowanceValues.allowance32_s);
57
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
58
+
59
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b8_s, allAmountValues.amount8_s, allAllowanceValues.allowance32_s);
60
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
61
+
62
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b64_s, allAmountValues.amount8_s, allAllowanceValues.allowance32_s);
63
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
64
+
65
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a16_s, allGTCastingValues.b64_s, allAmountValues.amount8_s, allAllowanceValues.allowance32_s);
66
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
67
+
68
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b16_s, allAmountValues.amount8_s, allAllowanceValues.allowance32_s);
69
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
70
+
71
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a32_s, allGTCastingValues.b64_s, allAmountValues.amount8_s, allAllowanceValues.allowance32_s);
72
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
73
+
74
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b32_s, allAmountValues.amount8_s, allAllowanceValues.allowance32_s);
75
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
76
+ }
77
+
78
+
79
+ function computeAndCheckTransfer64_16_32(
80
+ AllGTCastingValues memory allGTCastingValues,
81
+ AllAmountValues memory allAmountValues,
82
+ AllAllowanceValues memory allAllowanceValues,
83
+ uint8 new_a,
84
+ uint8 new_b,
85
+ bool res,
86
+ uint8 new_allowance
87
+ )
88
+ public
89
+ {
90
+ (gtUint64 newA_s, gtUint64 newB_s, gtBool res_s, gtUint64 newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a8_s, allGTCastingValues.b64_s, allAmountValues.amount16_s, allAllowanceValues.allowance32_s);
91
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
92
+
93
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b8_s, allAmountValues.amount16_s, allAllowanceValues.allowance32_s);
94
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
95
+
96
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a16_s, allGTCastingValues.b64_s, allAmountValues.amount16_s, allAllowanceValues.allowance32_s);
97
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
98
+
99
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b16_s, allAmountValues.amount16_s, allAllowanceValues.allowance32_s);
100
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
101
+
102
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b64_s, allAmountValues.amount16_s, allAllowanceValues.allowance32_s);
103
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
104
+
105
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a32_s, allGTCastingValues.b64_s, allAmountValues.amount16_s, allAllowanceValues.allowance32_s);
106
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
107
+
108
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b32_s, allAmountValues.amount16_s, allAllowanceValues.allowance32_s);
109
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
110
+ }
111
+
112
+
113
+ function computeAndCheckTransfer64_32_32(
114
+ AllGTCastingValues memory allGTCastingValues,
115
+ AllAmountValues memory allAmountValues,
116
+ AllAllowanceValues memory allAllowanceValues,
117
+ uint8 new_a,
118
+ uint8 new_b,
119
+ bool res,
120
+ uint8 new_allowance
121
+ )
122
+ public
123
+ {
124
+ (gtUint64 newA_s, gtUint64 newB_s, gtBool res_s, gtUint64 newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a8_s, allGTCastingValues.b64_s, allAmountValues.amount32_s, allAllowanceValues.allowance32_s);
125
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
126
+
127
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b8_s, allAmountValues.amount32_s, allAllowanceValues.allowance32_s);
128
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
129
+
130
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a16_s, allGTCastingValues.b64_s, allAmountValues.amount32_s, allAllowanceValues.allowance32_s);
131
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
132
+
133
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b16_s, allAmountValues.amount32_s, allAllowanceValues.allowance32_s);
134
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
135
+
136
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a32_s, allGTCastingValues.b64_s, allAmountValues.amount32_s, allAllowanceValues.allowance32_s);
137
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
138
+
139
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b32_s, allAmountValues.amount32_s, allAllowanceValues.allowance32_s);
140
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
141
+
142
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b64_s, allAmountValues.amount32_s, allAllowanceValues.allowance32_s);
143
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
144
+ }
145
+
146
+ function computeAndCheckTransfer64_64_32(
147
+ AllGTCastingValues memory allGTCastingValues,
148
+ AllAmountValues memory allAmountValues,
149
+ AllAllowanceValues memory allAllowanceValues,
150
+ uint8 new_a,
151
+ uint8 new_b,
152
+ bool res,
153
+ uint8 new_allowance
154
+ )
155
+ public
156
+ {
157
+ (gtUint64 newA_s, gtUint64 newB_s, gtBool res_s, gtUint64 newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a8_s, allGTCastingValues.b64_s, allAmountValues.amount64_s, allAllowanceValues.allowance32_s);
158
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
159
+
160
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b8_s, allAmountValues.amount64_s, allAllowanceValues.allowance32_s);
161
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
162
+
163
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b64_s, allAmountValues.amount64_s, allAllowanceValues.allowance32_s);
164
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
165
+
166
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a16_s, allGTCastingValues.b64_s, allAmountValues.amount64_s, allAllowanceValues.allowance32_s);
167
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
168
+
169
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b16_s, allAmountValues.amount64_s, allAllowanceValues.allowance32_s);
170
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
171
+
172
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a32_s, allGTCastingValues.b64_s, allAmountValues.amount64_s, allAllowanceValues.allowance32_s);
173
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
174
+
175
+ (newA_s, newB_s, res_s, newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a64_s, allGTCastingValues.b32_s, allAmountValues.amount64_s, allAllowanceValues.allowance32_s);
176
+ require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s) && new_allowance == MpcCore.decrypt(newAllowance_s), "transferTest: cast 64 failed");
177
+ }
178
+
179
+
180
+ function transferWithAllowance64Test(uint8 a, uint8 b, uint8 amount, uint8 allowance) public returns (uint8, uint8, bool, uint8) {
181
+ AllGTCastingValues memory allGTCastingValues;
182
+ AllAmountValues memory allAmountValues;
183
+ AllAllowanceValues memory allAllowanceValues;
184
+ allGTCastingValues.a8_s = MpcCore.setPublic8(a);
185
+ allGTCastingValues.b8_s = MpcCore.setPublic8(b);
186
+ allGTCastingValues.a16_s = MpcCore.setPublic16(a);
187
+ allGTCastingValues.b16_s = MpcCore.setPublic16(b);
188
+ allGTCastingValues.a32_s = MpcCore.setPublic32(a);
189
+ allGTCastingValues.b32_s = MpcCore.setPublic32(b);
190
+ allGTCastingValues.a64_s = MpcCore.setPublic64(a);
191
+ allGTCastingValues.b64_s = MpcCore.setPublic64(b);
192
+ allAmountValues.amount8_s = MpcCore.setPublic8(amount);
193
+ allAmountValues.amount16_s = MpcCore.setPublic16(amount);
194
+ allAmountValues.amount32_s = MpcCore.setPublic32(amount);
195
+ allAmountValues.amount64_s = MpcCore.setPublic64(amount);
196
+ allAmountValues.amount = amount;
197
+ allAllowanceValues.allowance8_s = MpcCore.setPublic8(allowance);
198
+ allAllowanceValues.allowance16_s = MpcCore.setPublic16(allowance);
199
+ allAllowanceValues.allowance32_s = MpcCore.setPublic32(allowance);
200
+ allAllowanceValues.allowance64_s = MpcCore.setPublic64(allowance);
201
+ allAllowanceValues.allowance = allowance;
202
+
203
+ // Calculate the expected result
204
+ (gtUint8 newA_s, gtUint8 newB_s, gtBool res_s, gtUint8 newAllowance_s) = MpcCore.transferWithAllowance(allGTCastingValues.a8_s, allGTCastingValues.b8_s, allAmountValues.amount8_s, allAllowanceValues.allowance8_s);
205
+ newA = MpcCore.decrypt(newA_s);
206
+ newB = MpcCore.decrypt(newB_s);
207
+ result = MpcCore.decrypt(res_s);
208
+ newAllowance = MpcCore.decrypt(newAllowance_s);
209
+
210
+ // Calculate the result with casting to 64
211
+ computeAndCheckTransfer64_8_32(allGTCastingValues, allAmountValues, allAllowanceValues, newA, newB, result, newAllowance);
212
+
213
+ computeAndCheckTransfer64_16_32(allGTCastingValues, allAmountValues, allAllowanceValues, newA, newB, result, newAllowance);
214
+
215
+ computeAndCheckTransfer64_32_32(allGTCastingValues, allAmountValues, allAllowanceValues, newA, newB, result, newAllowance);
216
+
217
+ computeAndCheckTransfer64_64_32(allGTCastingValues, allAmountValues, allAllowanceValues, newA, newB, result, newAllowance);
218
+
219
+ return (newA, newB, result, newAllowance);
220
+ }
221
+
222
+ }