From c52a6959130dc2b1a928c3f7373af319cb125680 Mon Sep 17 00:00:00 2001 From: eitanz-coti Date: Tue, 17 Sep 2024 14:45:56 +0300 Subject: [PATCH 1/5] Testnet rampup fix precompile tests and rename on board params. --- contracts/AccountOnboard/AccountOnboard.sol | 6 +- .../PrecompilesArythmeticTestsContract.sol | 381 +- .../PrecompilesBitwiseTestsContract.sol | 268 +- .../PrecompilesComparison1TestsContract.sol | 180 +- .../PrecompilesComparison2TestsContract.sol | 180 +- .../PrecompilesMinMaxTestsContract.sol | 231 +- ...PrecompilesMiscellaneous1TestsContract.sol | 120 +- .../PrecompilesMiscellaneousTestsContract.sol | 374 +- ...ecompilesOffboardToUserKeyTestContract.sol | 64 +- .../PrecompilesShiftTestsContract.sol | 257 +- ...PrecompilesTransferScalarTestsContract.sol | 261 +- .../PrecompilesTransferTestsContract.sol | 800 +-- contracts/lib/MpcCore.sol | 4542 ++++++++++++----- contracts/lib/MpcInterface.sol | 8 +- hardhat.config.ts | 9 +- package.json | 2 +- test-hardhat/precompile.test.ts | 67 +- test-hardhat/util/onboard.ts | 24 +- yarn.lock | 8 +- 19 files changed, 4216 insertions(+), 3566 deletions(-) diff --git a/contracts/AccountOnboard/AccountOnboard.sol b/contracts/AccountOnboard/AccountOnboard.sol index 9a05f65..6f4c75d 100644 --- a/contracts/AccountOnboard/AccountOnboard.sol +++ b/contracts/AccountOnboard/AccountOnboard.sol @@ -5,7 +5,7 @@ import "../lib/MpcCore.sol"; contract AccountOnboard { - event AccountOnboarded(address indexed _from, bytes userKey); + event AccountOnboarded(address indexed _from, bytes userKey1, bytes userKey2); /** * @notice onboards the account and emits the users AES encryption key in encrypted form @@ -14,7 +14,7 @@ contract AccountOnboard { * @param signedEK signed hash of the RSA public key */ function onboardAccount(bytes calldata publicKey, bytes calldata signedEK) public { - bytes memory accountKey = MpcCore.getUserKey(publicKey, signedEK); - emit AccountOnboarded(msg.sender, accountKey); + (bytes memory accountKey1, bytes memory accountKey2)= MpcCore.getUserKey(publicKey, signedEK); + emit AccountOnboarded(msg.sender, accountKey1, accountKey2); } } diff --git a/contracts/examples/precompiles/PrecompilesArythmeticTestsContract.sol b/contracts/examples/precompiles/PrecompilesArythmeticTestsContract.sol index ceb10f1..677d258 100644 --- a/contracts/examples/precompiles/PrecompilesArythmeticTestsContract.sol +++ b/contracts/examples/precompiles/PrecompilesArythmeticTestsContract.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.19; import "../../lib/MpcCore.sol"; contract PrecompilesArythmeticTestsContract { + struct AllGTCastingValues { gtUint8 a8_s; gtUint8 b8_s; @@ -21,12 +22,6 @@ contract PrecompilesArythmeticTestsContract { gtUint16 res16_8; } - struct CheckMul16 { - gtUint32 res16_16; - gtUint32 res8_16; - gtUint32 res16_8; - } - struct Check32 { gtUint32 res32_32; gtUint32 res8_32; @@ -35,14 +30,6 @@ contract PrecompilesArythmeticTestsContract { gtUint32 res32_16; } - struct CheckMul32 { - gtUint64 res32_32; - gtUint64 res8_32; - gtUint64 res32_8; - gtUint64 res16_32; - gtUint64 res32_16; - } - struct Check64 { gtUint64 res64_64; gtUint64 res8_64; @@ -53,78 +40,64 @@ contract PrecompilesArythmeticTestsContract { gtUint64 res64_32; } - uint8 result; - uint16 result16; + uint8 addResult; + uint8 subResult; + uint8 mulResult; - function getResult() public view returns (uint8) { - return result; + function getAddResult() public view returns (uint8) { + return addResult; + } + + function getSubResult() public view returns (uint8) { + return subResult; } - function getResult16() public view returns (uint16) { - return result16; + function getMulResult() public view returns (uint8) { + return mulResult; } - function setPublicValues( - AllGTCastingValues memory castingValues, - uint8 a, - uint8 b - ) public { + function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{ castingValues.a8_s = MpcCore.setPublic8(a); castingValues.b8_s = MpcCore.setPublic8(b); - castingValues.a16_s = MpcCore.setPublic16(a); - castingValues.b16_s = MpcCore.setPublic16(b); - castingValues.a32_s = MpcCore.setPublic32(a); - castingValues.b32_s = MpcCore.setPublic32(b); - castingValues.a64_s = MpcCore.setPublic64(a); - castingValues.b64_s = MpcCore.setPublic64(b); + castingValues.a16_s = MpcCore.setPublic16(a); + castingValues.b16_s = MpcCore.setPublic16(b); + castingValues.a32_s = MpcCore.setPublic32(a); + castingValues.b32_s = MpcCore.setPublic32(b); + castingValues.a64_s = MpcCore.setPublic64(a); + castingValues.b64_s = MpcCore.setPublic64(b); } - function decryptAndCompareResults16( - Check16 memory check16 - ) public returns (uint16) { + function decryptAndCompareResults16(Check16 memory check16) public returns (uint16){ + // Calculate the result uint16 result = MpcCore.decrypt(check16.res16_16); - require( - result == MpcCore.decrypt(check16.res8_16) && - result == MpcCore.decrypt(check16.res16_8), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function decryptAndCompareResults32( - Check32 memory check32 - ) public returns (uint32) { + function decryptAndCompareResults32(Check32 memory check32) public returns (uint32){ + // Calculate the result uint32 result = MpcCore.decrypt(check32.res32_32); - require( - result == MpcCore.decrypt(check32.res8_32) && - result == MpcCore.decrypt(check32.res32_8) && - result == MpcCore.decrypt(check32.res32_16) && - result == MpcCore.decrypt(check32.res16_32), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check32.res8_32) && result == MpcCore.decrypt(check32.res32_8) + && result == MpcCore.decrypt(check32.res32_16) && result == MpcCore.decrypt(check32.res16_32), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function decryptAndCompareResults64( - Check64 memory check64 - ) public returns (uint64) { + function decryptAndCompareResults64(Check64 memory check64) public returns (uint64){ + // Calculate the result uint64 result = MpcCore.decrypt(check64.res64_64); - require( - result == MpcCore.decrypt(check64.res8_64) && - result == MpcCore.decrypt(check64.res64_8) && - result == MpcCore.decrypt(check64.res64_16) && - result == MpcCore.decrypt(check64.res16_64) && - result == MpcCore.decrypt(check64.res64_32) && - result == MpcCore.decrypt(check64.res32_64), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check64.res8_64) && result == MpcCore.decrypt(check64.res64_8) + && result == MpcCore.decrypt(check64.res64_16) && result == MpcCore.decrypt(check64.res16_64) + && result == MpcCore.decrypt(check64.res64_32) && result == MpcCore.decrypt(check64.res32_64), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } @@ -137,85 +110,45 @@ contract PrecompilesArythmeticTestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.add(castingValues.a8_s, castingValues.b8_s) - ); + uint8 result = MpcCore.decrypt(MpcCore.add(castingValues.a8_s, castingValues.b8_s)); + addResult = result; // Calculate the results with casting to 16 - check16.res16_16 = MpcCore.add( - castingValues.a16_s, - castingValues.b16_s - ); + check16.res16_16 = MpcCore.add(castingValues.a16_s, castingValues.b16_s); check16.res8_16 = MpcCore.add(castingValues.a8_s, castingValues.b16_s); check16.res16_8 = MpcCore.add(castingValues.a16_s, castingValues.b8_s); uint16 res16 = decryptAndCompareResults16(check16); require(res16 == result, "addTest: cast 16 failed"); // Calculate the result with casting to 32 - check32.res32_32 = MpcCore.add( - castingValues.a32_s, - castingValues.b32_s - ); + check32.res32_32 = MpcCore.add(castingValues.a32_s, castingValues.b32_s); check32.res8_32 = MpcCore.add(castingValues.a8_s, castingValues.b32_s); check32.res32_8 = MpcCore.add(castingValues.a32_s, castingValues.b8_s); - check32.res16_32 = MpcCore.add( - castingValues.a16_s, - castingValues.b32_s - ); - check32.res32_16 = MpcCore.add( - castingValues.a32_s, - castingValues.b16_s - ); + check32.res16_32 = MpcCore.add(castingValues.a16_s, castingValues.b32_s); + check32.res32_16 = MpcCore.add(castingValues.a32_s, castingValues.b16_s); uint32 res32 = decryptAndCompareResults32(check32); require(result == res32, "addTest: cast 32 failed"); // Calculate the result with casting to 64 - check64.res64_64 = MpcCore.add( - castingValues.a64_s, - castingValues.b64_s - ); + check64.res64_64 = MpcCore.add(castingValues.a64_s, castingValues.b64_s); check64.res8_64 = MpcCore.add(castingValues.a8_s, castingValues.b64_s); check64.res64_8 = MpcCore.add(castingValues.a64_s, castingValues.b8_s); - check64.res16_64 = MpcCore.add( - castingValues.a16_s, - castingValues.b64_s - ); - check64.res64_16 = MpcCore.add( - castingValues.a64_s, - castingValues.b16_s - ); - check64.res32_64 = MpcCore.add( - castingValues.a32_s, - castingValues.b64_s - ); - check64.res64_32 = MpcCore.add( - castingValues.a64_s, - castingValues.b32_s - ); + check64.res16_64 = MpcCore.add(castingValues.a16_s, castingValues.b64_s); + check64.res64_16 = MpcCore.add(castingValues.a64_s, castingValues.b16_s); + check64.res32_64 = MpcCore.add(castingValues.a32_s, castingValues.b64_s); + check64.res64_32 = MpcCore.add(castingValues.a64_s, castingValues.b32_s); uint64 res64 = decryptAndCompareResults64(check64); require(result == res64, "addTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.add(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.add(castingValues.a8_s, b)), - "addTest: test 8 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.add(a, castingValues.b16_s)) && - result == MpcCore.decrypt(MpcCore.add(castingValues.a16_s, b)), - "addTest: test 16 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.add(a, castingValues.b32_s)) && - result == MpcCore.decrypt(MpcCore.add(castingValues.a32_s, b)), - "addTest: test 32 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.add(a, castingValues.b64_s)) && - result == MpcCore.decrypt(MpcCore.add(castingValues.a64_s, b)), - "addTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.add(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.add(castingValues.a8_s, b)), + "addTest: test 8 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.add(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.add(castingValues.a16_s, b)), + "addTest: test 16 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.add(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.add(castingValues.a32_s, b)), + "addTest: test 32 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.add(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.add(castingValues.a64_s, b)), + "addTest: test 64 bits with scalar failed"); return result; } @@ -228,202 +161,96 @@ contract PrecompilesArythmeticTestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.sub(castingValues.a8_s, castingValues.b8_s) - ); + uint8 result = MpcCore.decrypt(MpcCore.sub(castingValues.a8_s, castingValues.b8_s)); + subResult = result; // Calculate the results with casting to 16 - check16.res16_16 = MpcCore.sub( - castingValues.a16_s, - castingValues.b16_s - ); + check16.res16_16 = MpcCore.sub(castingValues.a16_s, castingValues.b16_s); check16.res8_16 = MpcCore.sub(castingValues.a8_s, castingValues.b16_s); check16.res16_8 = MpcCore.sub(castingValues.a16_s, castingValues.b8_s); uint16 res16 = decryptAndCompareResults16(check16); require(res16 == result, "subTest: cast 16 failed"); // Calculate the result with casting to 32 - check32.res32_32 = MpcCore.sub( - castingValues.a32_s, - castingValues.b32_s - ); + check32.res32_32 = MpcCore.sub(castingValues.a32_s, castingValues.b32_s); check32.res8_32 = MpcCore.sub(castingValues.a8_s, castingValues.b32_s); check32.res32_8 = MpcCore.sub(castingValues.a32_s, castingValues.b8_s); - check32.res16_32 = MpcCore.sub( - castingValues.a16_s, - castingValues.b32_s - ); - check32.res32_16 = MpcCore.sub( - castingValues.a32_s, - castingValues.b16_s - ); + check32.res16_32 = MpcCore.sub(castingValues.a16_s, castingValues.b32_s); + check32.res32_16 = MpcCore.sub(castingValues.a32_s, castingValues.b16_s); uint32 res32 = decryptAndCompareResults32(check32); require(result == res32, "subTest: cast 32 failed"); // Calculate the result with casting to 64 - check64.res64_64 = MpcCore.sub( - castingValues.a64_s, - castingValues.b64_s - ); + check64.res64_64 = MpcCore.sub(castingValues.a64_s, castingValues.b64_s); check64.res8_64 = MpcCore.sub(castingValues.a8_s, castingValues.b64_s); check64.res64_8 = MpcCore.sub(castingValues.a64_s, castingValues.b8_s); - check64.res16_64 = MpcCore.sub( - castingValues.a16_s, - castingValues.b64_s - ); - check64.res64_16 = MpcCore.sub( - castingValues.a64_s, - castingValues.b16_s - ); - check64.res32_64 = MpcCore.sub( - castingValues.a32_s, - castingValues.b64_s - ); - check64.res64_32 = MpcCore.sub( - castingValues.a64_s, - castingValues.b32_s - ); + check64.res16_64 = MpcCore.sub(castingValues.a16_s, castingValues.b64_s); + check64.res64_16 = MpcCore.sub(castingValues.a64_s, castingValues.b16_s); + check64.res32_64 = MpcCore.sub(castingValues.a32_s, castingValues.b64_s); + check64.res64_32 = MpcCore.sub(castingValues.a64_s, castingValues.b32_s); uint64 res64 = decryptAndCompareResults64(check64); require(result == res64, "subTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.sub(castingValues.a8_s, b)), - "subTest: test 8 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b16_s)) && - result == MpcCore.decrypt(MpcCore.sub(castingValues.a16_s, b)), - "subTest: test 16 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b32_s)) && - result == MpcCore.decrypt(MpcCore.sub(castingValues.a32_s, b)), - "subTest: test 32 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b64_s)) && - result == MpcCore.decrypt(MpcCore.sub(castingValues.a64_s, b)), - "subTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.sub(castingValues.a8_s, b)), + "subTest: test 8 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.sub(castingValues.a16_s, b)), + "subTest: test 16 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.sub(castingValues.a32_s, b)), + "subTest: test 32 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.sub(castingValues.a64_s, b)), + "subTest: test 64 bits with scalar failed"); return result; } - function mulTest(uint8 a, uint8 b) public returns (uint16) { + function mulTest(uint8 a, uint8 b) public returns (uint8) { AllGTCastingValues memory castingValues; - CheckMul16 memory checkMul16; - CheckMul32 memory checkMul32; + Check16 memory check16; + Check32 memory check32; Check64 memory check64; setPublicValues(castingValues, a, b); // Calculate the expected result - result16 = MpcCore.decrypt( - MpcCore.mul(castingValues.a8_s, castingValues.b8_s) - ); + mulResult = MpcCore.decrypt(MpcCore.mul(castingValues.a8_s, castingValues.b8_s)); // Calculate the result with casting to 16 - checkMul16.res16_16 = MpcCore.mul( - castingValues.a16_s, - castingValues.b16_s - ); - checkMul16.res8_16 = MpcCore.mul( - castingValues.a8_s, - castingValues.b16_s - ); - checkMul16.res16_8 = MpcCore.mul( - castingValues.a16_s, - castingValues.b8_s - ); - require( - result16 == MpcCore.decrypt(checkMul16.res16_16) && - result16 == MpcCore.decrypt(checkMul16.res8_16) && - result16 == MpcCore.decrypt(checkMul16.res16_8), - "mulTest: cast 16 failed" - ); + check16.res16_16 = MpcCore.mul(castingValues.a16_s, castingValues.b16_s); + check16.res8_16 = MpcCore.mul(castingValues.a8_s, castingValues.b16_s); + check16.res16_8 = MpcCore.mul(castingValues.a16_s, castingValues.b8_s); + uint16 res16 = decryptAndCompareResults16(check16); + require(mulResult == res16, "mulTest: cast 16 failed"); // Calculate the result with casting to 32 - checkMul32.res32_32 = MpcCore.mul( - castingValues.a32_s, - castingValues.b32_s - ); - checkMul32.res8_32 = MpcCore.mul( - castingValues.a8_s, - castingValues.b32_s - ); - checkMul32.res32_8 = MpcCore.mul( - castingValues.a32_s, - castingValues.b8_s - ); - checkMul32.res16_32 = MpcCore.mul( - castingValues.a16_s, - castingValues.b32_s - ); - checkMul32.res32_16 = MpcCore.mul( - castingValues.a32_s, - castingValues.b16_s - ); - require( - result16 == MpcCore.decrypt(checkMul32.res32_32) && - result16 == MpcCore.decrypt(checkMul32.res8_32) && - result16 == MpcCore.decrypt(checkMul32.res32_8) && - result16 == MpcCore.decrypt(checkMul32.res32_16) && - result16 == MpcCore.decrypt(checkMul32.res16_32), - "mulTest: cast 32 failed" - ); + check32.res32_32 = MpcCore.mul(castingValues.a32_s, castingValues.b32_s); + check32.res8_32 = MpcCore.mul(castingValues.a8_s, castingValues.b32_s); + check32.res32_8 = MpcCore.mul(castingValues.a32_s, castingValues.b8_s); + check32.res16_32 = MpcCore.mul(castingValues.a16_s, castingValues.b32_s); + check32.res32_16 = MpcCore.mul(castingValues.a32_s, castingValues.b16_s); + uint32 res32 = decryptAndCompareResults32(check32); + require(mulResult == res32, "mulTest: cast 32 failed"); // Calculate the result with casting to 64 - check64.res64_64 = MpcCore.mul( - castingValues.a64_s, - castingValues.b64_s - ); + check64.res64_64 = MpcCore.mul(castingValues.a64_s, castingValues.b64_s); check64.res8_64 = MpcCore.mul(castingValues.a8_s, castingValues.b64_s); check64.res64_8 = MpcCore.mul(castingValues.a64_s, castingValues.b8_s); - check64.res16_64 = MpcCore.mul( - castingValues.a16_s, - castingValues.b64_s - ); - check64.res64_16 = MpcCore.mul( - castingValues.a64_s, - castingValues.b16_s - ); - check64.res32_64 = MpcCore.mul( - castingValues.a32_s, - castingValues.b64_s - ); - check64.res64_32 = MpcCore.mul( - castingValues.a64_s, - castingValues.b32_s - ); + check64.res16_64 = MpcCore.mul(castingValues.a16_s, castingValues.b64_s); + check64.res64_16 = MpcCore.mul(castingValues.a64_s, castingValues.b16_s); + check64.res32_64 = MpcCore.mul(castingValues.a32_s, castingValues.b64_s); + check64.res64_32 = MpcCore.mul(castingValues.a64_s, castingValues.b32_s); uint64 res64 = decryptAndCompareResults64(check64); - require(result16 == res64, "mulTest: cast 64 failed"); + require(mulResult == res64, "mulTest: cast 64 failed"); // Check the result with scalar - require( - result16 == MpcCore.decrypt(MpcCore.mul(a, castingValues.b8_s)) && - result16 == MpcCore.decrypt(MpcCore.mul(castingValues.a8_s, b)), - "mulTest: test 8 bits with scalar failed" - ); - require( - result16 == MpcCore.decrypt(MpcCore.mul(a, castingValues.b16_s)) && - result16 == - MpcCore.decrypt(MpcCore.mul(castingValues.a16_s, b)), - "mulTest: test 16 bits with scalar failed" - ); - require( - result16 == MpcCore.decrypt(MpcCore.mul(a, castingValues.b32_s)) && - result16 == - MpcCore.decrypt(MpcCore.mul(castingValues.a32_s, b)), - "mulTest: test 32 bits with scalar failed" - ); - require( - result16 == MpcCore.decrypt(MpcCore.mul(a, castingValues.b64_s)) && - result16 == - MpcCore.decrypt(MpcCore.mul(castingValues.a64_s, b)), - "mulTest: test 64 bits with scalar failed" - ); - - return result16; + require(mulResult == MpcCore.decrypt(MpcCore.mul(a, castingValues.b8_s)) && mulResult == MpcCore.decrypt(MpcCore.mul(castingValues.a8_s, b)), + "mulTest: test 8 bits with scalar failed"); + require(mulResult == MpcCore.decrypt(MpcCore.mul(a, castingValues.b16_s)) && mulResult == MpcCore.decrypt(MpcCore.mul(castingValues.a16_s, b)), + "mulTest: test 16 bits with scalar failed"); + require(mulResult == MpcCore.decrypt(MpcCore.mul(a, castingValues.b32_s)) && mulResult == MpcCore.decrypt(MpcCore.mul(castingValues.a32_s, b)), + "mulTest: test 32 bits with scalar failed"); + require(mulResult == MpcCore.decrypt(MpcCore.mul(a, castingValues.b64_s)) && mulResult == MpcCore.decrypt(MpcCore.mul(castingValues.a64_s, b)), + "mulTest: test 64 bits with scalar failed"); + + return mulResult; } } diff --git a/contracts/examples/precompiles/PrecompilesBitwiseTestsContract.sol b/contracts/examples/precompiles/PrecompilesBitwiseTestsContract.sol index 3a4c4ce..cb0dd09 100644 --- a/contracts/examples/precompiles/PrecompilesBitwiseTestsContract.sol +++ b/contracts/examples/precompiles/PrecompilesBitwiseTestsContract.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.19; import "../../lib/MpcCore.sol"; contract PrecompilesBitwiseTestsContract { + struct AllGTCastingValues { gtUint8 a8_s; gtUint8 b8_s; @@ -39,74 +40,63 @@ contract PrecompilesBitwiseTestsContract { gtUint64 res64_32; } - uint8 result; + uint8 andResult; + uint8 orResult; + uint8 xorResult; - function getResult() public view returns (uint8) { - return result; + function getAndResult() public view returns (uint8) { + return andResult; + } + function getOrResult() public view returns (uint8) { + return orResult; + } + function getXorResult() public view returns (uint8) { + return xorResult; } - function setPublicValues( - AllGTCastingValues memory castingValues, - uint8 a, - uint8 b - ) public { + function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{ castingValues.a8_s = MpcCore.setPublic8(a); castingValues.b8_s = MpcCore.setPublic8(b); - castingValues.a16_s = MpcCore.setPublic16(a); - castingValues.b16_s = MpcCore.setPublic16(b); - castingValues.a32_s = MpcCore.setPublic32(a); - castingValues.b32_s = MpcCore.setPublic32(b); - castingValues.a64_s = MpcCore.setPublic64(a); - castingValues.b64_s = MpcCore.setPublic64(b); + castingValues.a16_s = MpcCore.setPublic16(a); + castingValues.b16_s = MpcCore.setPublic16(b); + castingValues.a32_s = MpcCore.setPublic32(a); + castingValues.b32_s = MpcCore.setPublic32(b); + castingValues.a64_s = MpcCore.setPublic64(a); + castingValues.b64_s = MpcCore.setPublic64(b); } - function decryptAndCompareResults16( - Check16 memory check16 - ) public returns (uint16) { + function decryptAndCompareResults16(Check16 memory check16) public returns (uint16){ + // Calculate the result uint16 result = MpcCore.decrypt(check16.res16_16); - require( - result == MpcCore.decrypt(check16.res8_16) && - result == MpcCore.decrypt(check16.res16_8), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function decryptAndCompareResults32( - Check32 memory check32 - ) public returns (uint32) { + function decryptAndCompareResults32(Check32 memory check32) public returns (uint32){ + // Calculate the result uint32 result = MpcCore.decrypt(check32.res32_32); - require( - result == MpcCore.decrypt(check32.res8_32) && - result == MpcCore.decrypt(check32.res32_8) && - result == MpcCore.decrypt(check32.res32_16) && - result == MpcCore.decrypt(check32.res16_32), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check32.res8_32) && result == MpcCore.decrypt(check32.res32_8) + && result == MpcCore.decrypt(check32.res32_16) && result == MpcCore.decrypt(check32.res16_32), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function decryptAndCompareResults64( - Check64 memory check64 - ) public returns (uint64) { + function decryptAndCompareResults64(Check64 memory check64) public returns (uint64){ + // Calculate the result uint64 result = MpcCore.decrypt(check64.res64_64); - require( - result == MpcCore.decrypt(check64.res8_64) && - result == MpcCore.decrypt(check64.res64_8) && - result == MpcCore.decrypt(check64.res64_16) && - result == MpcCore.decrypt(check64.res16_64) && - result == MpcCore.decrypt(check64.res64_32) && - result == MpcCore.decrypt(check64.res32_64), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check64.res8_64) && result == MpcCore.decrypt(check64.res64_8) + && result == MpcCore.decrypt(check64.res64_16) && result == MpcCore.decrypt(check64.res16_64) + && result == MpcCore.decrypt(check64.res64_32) && result == MpcCore.decrypt(check64.res32_64), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } @@ -119,85 +109,45 @@ contract PrecompilesBitwiseTestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.and(castingValues.a8_s, castingValues.b8_s) - ); + uint8 result = MpcCore.decrypt(MpcCore.and(castingValues.a8_s, castingValues.b8_s)); + andResult = result; // Calculate the results with casting to 16 - check16.res16_16 = MpcCore.and( - castingValues.a16_s, - castingValues.b16_s - ); + check16.res16_16 = MpcCore.and(castingValues.a16_s, castingValues.b16_s); check16.res8_16 = MpcCore.and(castingValues.a8_s, castingValues.b16_s); check16.res16_8 = MpcCore.and(castingValues.a16_s, castingValues.b8_s); uint16 res16 = decryptAndCompareResults16(check16); require(res16 == result, "andTest: cast 16 failed"); // Calculate the result with casting to 32 - check32.res32_32 = MpcCore.and( - castingValues.a32_s, - castingValues.b32_s - ); + check32.res32_32 = MpcCore.and(castingValues.a32_s, castingValues.b32_s); check32.res8_32 = MpcCore.and(castingValues.a8_s, castingValues.b32_s); check32.res32_8 = MpcCore.and(castingValues.a32_s, castingValues.b8_s); - check32.res16_32 = MpcCore.and( - castingValues.a16_s, - castingValues.b32_s - ); - check32.res32_16 = MpcCore.and( - castingValues.a32_s, - castingValues.b16_s - ); + check32.res16_32 = MpcCore.and(castingValues.a16_s, castingValues.b32_s); + check32.res32_16 = MpcCore.and(castingValues.a32_s, castingValues.b16_s); uint32 res32 = decryptAndCompareResults32(check32); require(result == res32, "andTest: cast 32 failed"); // Calculate the result with casting to 64 - check64.res64_64 = MpcCore.and( - castingValues.a64_s, - castingValues.b64_s - ); + check64.res64_64 = MpcCore.and(castingValues.a64_s, castingValues.b64_s); check64.res8_64 = MpcCore.and(castingValues.a8_s, castingValues.b64_s); check64.res64_8 = MpcCore.and(castingValues.a64_s, castingValues.b8_s); - check64.res16_64 = MpcCore.and( - castingValues.a16_s, - castingValues.b64_s - ); - check64.res64_16 = MpcCore.and( - castingValues.a64_s, - castingValues.b16_s - ); - check64.res32_64 = MpcCore.and( - castingValues.a32_s, - castingValues.b64_s - ); - check64.res64_32 = MpcCore.and( - castingValues.a64_s, - castingValues.b32_s - ); + check64.res16_64 = MpcCore.and(castingValues.a16_s, castingValues.b64_s); + check64.res64_16 = MpcCore.and(castingValues.a64_s, castingValues.b16_s); + check64.res32_64 = MpcCore.and(castingValues.a32_s, castingValues.b64_s); + check64.res64_32 = MpcCore.and(castingValues.a64_s, castingValues.b32_s); uint64 res64 = decryptAndCompareResults64(check64); require(result == res64, "andTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.and(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.and(castingValues.a8_s, b)), - "andTest: test 8 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.and(a, castingValues.b16_s)) && - result == MpcCore.decrypt(MpcCore.and(castingValues.a16_s, b)), - "andTest: test 16 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.and(a, castingValues.b32_s)) && - result == MpcCore.decrypt(MpcCore.and(castingValues.a32_s, b)), - "andTest: test 32 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.and(a, castingValues.b64_s)) && - result == MpcCore.decrypt(MpcCore.and(castingValues.a64_s, b)), - "andTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.and(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.and(castingValues.a8_s, b)), + "andTest: test 8 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.and(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.and(castingValues.a16_s, b)), + "andTest: test 16 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.and(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.and(castingValues.a32_s, b)), + "andTest: test 32 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.and(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.and(castingValues.a64_s, b)), + "andTest: test 64 bits with scalar failed"); return result; } @@ -210,9 +160,8 @@ contract PrecompilesBitwiseTestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.or(castingValues.a8_s, castingValues.b8_s) - ); + uint8 result = MpcCore.decrypt(MpcCore.or(castingValues.a8_s, castingValues.b8_s)); + orResult = result; // Calculate the results with casting to 16 check16.res16_16 = MpcCore.or(castingValues.a16_s, castingValues.b16_s); @@ -242,26 +191,14 @@ contract PrecompilesBitwiseTestsContract { require(result == res64, "orTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.or(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.or(castingValues.a8_s, b)), - "orTest: test 8 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.or(a, castingValues.b16_s)) && - result == MpcCore.decrypt(MpcCore.or(castingValues.a16_s, b)), - "orTest: test 16 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.or(a, castingValues.b32_s)) && - result == MpcCore.decrypt(MpcCore.or(castingValues.a32_s, b)), - "orTest: test 32 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.or(a, castingValues.b64_s)) && - result == MpcCore.decrypt(MpcCore.or(castingValues.a64_s, b)), - "orTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.or(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.or(castingValues.a8_s, b)), + "orTest: test 8 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.or(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.or(castingValues.a16_s, b)), + "orTest: test 16 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.or(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.or(castingValues.a32_s, b)), + "orTest: test 32 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.or(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.or(castingValues.a64_s, b)), + "orTest: test 64 bits with scalar failed"); return result; } @@ -274,86 +211,47 @@ contract PrecompilesBitwiseTestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.xor(castingValues.a8_s, castingValues.b8_s) - ); + uint8 result = MpcCore.decrypt(MpcCore.xor(castingValues.a8_s, castingValues.b8_s)); + xorResult = result; // Calculate the results with casting to 16 - check16.res16_16 = MpcCore.xor( - castingValues.a16_s, - castingValues.b16_s - ); + check16.res16_16 = MpcCore.xor(castingValues.a16_s, castingValues.b16_s); check16.res8_16 = MpcCore.xor(castingValues.a8_s, castingValues.b16_s); check16.res16_8 = MpcCore.xor(castingValues.a16_s, castingValues.b8_s); uint16 res16 = decryptAndCompareResults16(check16); require(res16 == result, "xorTest: cast 16 failed"); // Calculate the result with casting to 32 - check32.res32_32 = MpcCore.xor( - castingValues.a32_s, - castingValues.b32_s - ); + check32.res32_32 = MpcCore.xor(castingValues.a32_s, castingValues.b32_s); check32.res8_32 = MpcCore.xor(castingValues.a8_s, castingValues.b32_s); check32.res32_8 = MpcCore.xor(castingValues.a32_s, castingValues.b8_s); - check32.res16_32 = MpcCore.xor( - castingValues.a16_s, - castingValues.b32_s - ); - check32.res32_16 = MpcCore.xor( - castingValues.a32_s, - castingValues.b16_s - ); + check32.res16_32 = MpcCore.xor(castingValues.a16_s, castingValues.b32_s); + check32.res32_16 = MpcCore.xor(castingValues.a32_s, castingValues.b16_s); uint32 res32 = decryptAndCompareResults32(check32); require(result == res32, "xorTest: cast 32 failed"); // Calculate the result with casting to 64 - check64.res64_64 = MpcCore.xor( - castingValues.a64_s, - castingValues.b64_s - ); + check64.res64_64 = MpcCore.xor(castingValues.a64_s, castingValues.b64_s); check64.res8_64 = MpcCore.xor(castingValues.a8_s, castingValues.b64_s); check64.res64_8 = MpcCore.xor(castingValues.a64_s, castingValues.b8_s); - check64.res16_64 = MpcCore.xor( - castingValues.a16_s, - castingValues.b64_s - ); - check64.res64_16 = MpcCore.xor( - castingValues.a64_s, - castingValues.b16_s - ); - check64.res32_64 = MpcCore.xor( - castingValues.a32_s, - castingValues.b64_s - ); - check64.res64_32 = MpcCore.xor( - castingValues.a64_s, - castingValues.b32_s - ); + check64.res16_64 = MpcCore.xor(castingValues.a16_s, castingValues.b64_s); + check64.res64_16 = MpcCore.xor(castingValues.a64_s, castingValues.b16_s); + check64.res32_64 = MpcCore.xor(castingValues.a32_s, castingValues.b64_s); + check64.res64_32 = MpcCore.xor(castingValues.a64_s, castingValues.b32_s); uint64 res64 = decryptAndCompareResults64(check64); require(result == res64, "xorTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.xor(castingValues.a8_s, b)), - "xorTest: test 8 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b16_s)) && - result == MpcCore.decrypt(MpcCore.xor(castingValues.a16_s, b)), - "xorTest: test 16 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b32_s)) && - result == MpcCore.decrypt(MpcCore.xor(castingValues.a32_s, b)), - "xorTest: test 32 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b64_s)) && - result == MpcCore.decrypt(MpcCore.xor(castingValues.a64_s, b)), - "xorTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.xor(castingValues.a8_s, b)), + "xorTest: test 8 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.xor(castingValues.a16_s, b)), + "xorTest: test 16 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.xor(castingValues.a32_s, b)), + "xorTest: test 32 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.xor(castingValues.a64_s, b)), + "xorTest: test 64 bits with scalar failed"); return result; } + } diff --git a/contracts/examples/precompiles/PrecompilesComparison1TestsContract.sol b/contracts/examples/precompiles/PrecompilesComparison1TestsContract.sol index d6e5f3f..4de9193 100644 --- a/contracts/examples/precompiles/PrecompilesComparison1TestsContract.sol +++ b/contracts/examples/precompiles/PrecompilesComparison1TestsContract.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.19; import "../../lib/MpcCore.sol"; contract PrecompilesComparison1TestsContract { + struct AllGTCastingValues { gtUint8 a8_s; gtUint8 b8_s; @@ -39,74 +40,63 @@ contract PrecompilesComparison1TestsContract { gtBool res64_32; } - bool result; + bool gtResult; + bool leResult; + bool ltResult; - function getResult() public view returns (bool) { - return result; + function getGtResult() public view returns (bool) { + return gtResult; + } + function getLeResult() public view returns (bool) { + return leResult; + } + function getLtResult() public view returns (bool) { + return ltResult; } - function setPublicValues( - AllGTCastingValues memory castingValues, - uint8 a, - uint8 b - ) public { + function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{ castingValues.a8_s = MpcCore.setPublic8(a); castingValues.b8_s = MpcCore.setPublic8(b); - castingValues.a16_s = MpcCore.setPublic16(a); - castingValues.b16_s = MpcCore.setPublic16(b); - castingValues.a32_s = MpcCore.setPublic32(a); - castingValues.b32_s = MpcCore.setPublic32(b); - castingValues.a64_s = MpcCore.setPublic64(a); - castingValues.b64_s = MpcCore.setPublic64(b); + castingValues.a16_s = MpcCore.setPublic16(a); + castingValues.b16_s = MpcCore.setPublic16(b); + castingValues.a32_s = MpcCore.setPublic32(a); + castingValues.b32_s = MpcCore.setPublic32(b); + castingValues.a64_s = MpcCore.setPublic64(a); + castingValues.b64_s = MpcCore.setPublic64(b); } - function decryptAndCompareResults16( - Check16 memory check16 - ) public returns (bool) { + function decryptAndCompareResults16(Check16 memory check16) public returns (bool){ + // Calculate the result bool result = MpcCore.decrypt(check16.res16_16); - require( - result == MpcCore.decrypt(check16.res8_16) && - result == MpcCore.decrypt(check16.res16_8), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function decryptAndCompareResults32( - Check32 memory check32 - ) public returns (bool) { + function decryptAndCompareResults32(Check32 memory check32) public returns (bool){ + // Calculate the result bool result = MpcCore.decrypt(check32.res32_32); - require( - result == MpcCore.decrypt(check32.res8_32) && - result == MpcCore.decrypt(check32.res32_8) && - result == MpcCore.decrypt(check32.res32_16) && - result == MpcCore.decrypt(check32.res16_32), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check32.res8_32) && result == MpcCore.decrypt(check32.res32_8) + && result == MpcCore.decrypt(check32.res32_16) && result == MpcCore.decrypt(check32.res16_32), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function decryptAndCompareResults64( - Check64 memory check64 - ) public returns (bool) { + function decryptAndCompareResults64(Check64 memory check64) public returns (bool){ + // Calculate the result bool result = MpcCore.decrypt(check64.res64_64); - require( - result == MpcCore.decrypt(check64.res8_64) && - result == MpcCore.decrypt(check64.res64_8) && - result == MpcCore.decrypt(check64.res64_16) && - result == MpcCore.decrypt(check64.res16_64) && - result == MpcCore.decrypt(check64.res64_32) && - result == MpcCore.decrypt(check64.res32_64), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check64.res8_64) && result == MpcCore.decrypt(check64.res64_8) + && result == MpcCore.decrypt(check64.res64_16) && result == MpcCore.decrypt(check64.res16_64) + && result == MpcCore.decrypt(check64.res64_32) && result == MpcCore.decrypt(check64.res32_64), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } @@ -119,9 +109,8 @@ contract PrecompilesComparison1TestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.gt(castingValues.a8_s, castingValues.b8_s) - ); + bool result = MpcCore.decrypt(MpcCore.gt(castingValues.a8_s, castingValues.b8_s)); + gtResult = result; // Calculate the results with cating to 16 check16.res16_16 = MpcCore.gt(castingValues.a16_s, castingValues.b16_s); @@ -151,26 +140,14 @@ contract PrecompilesComparison1TestsContract { require(result == res64, "gtTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.gt(castingValues.a8_s, b)), - "gtTest: test 8 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b16_s)) && - result == MpcCore.decrypt(MpcCore.gt(castingValues.a16_s, b)), - "gtTest: test 16 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b32_s)) && - result == MpcCore.decrypt(MpcCore.gt(castingValues.a32_s, b)), - "gtTest: test 32 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b64_s)) && - result == MpcCore.decrypt(MpcCore.gt(castingValues.a64_s, b)), - "gtTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.gt(castingValues.a8_s, b)), + "gtTest: test 8 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.gt(castingValues.a16_s, b)), + "gtTest: test 16 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.gt(castingValues.a32_s, b)), + "gtTest: test 32 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.gt(castingValues.a64_s, b)), + "gtTest: test 64 bits with scalar failed"); return result; } @@ -183,9 +160,8 @@ contract PrecompilesComparison1TestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.le(castingValues.a8_s, castingValues.b8_s) - ); + bool result = MpcCore.decrypt(MpcCore.le(castingValues.a8_s, castingValues.b8_s)); + leResult = result; // Calculate the results with cating to 16 check16.res16_16 = MpcCore.le(castingValues.a16_s, castingValues.b16_s); @@ -215,26 +191,14 @@ contract PrecompilesComparison1TestsContract { require(result == res64, "leTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.le(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.le(castingValues.a8_s, b)), - "leTest: test 8 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.le(a, castingValues.b16_s)) && - result == MpcCore.decrypt(MpcCore.le(castingValues.a16_s, b)), - "leTest: test 16 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.le(a, castingValues.b32_s)) && - result == MpcCore.decrypt(MpcCore.le(castingValues.a32_s, b)), - "leTest: test 32 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.le(a, castingValues.b64_s)) && - result == MpcCore.decrypt(MpcCore.le(castingValues.a64_s, b)), - "leTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.le(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.le(castingValues.a8_s, b)), + "leTest: test 8 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.le(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.le(castingValues.a16_s, b)), + "leTest: test 16 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.le(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.le(castingValues.a32_s, b)), + "leTest: test 32 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.le(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.le(castingValues.a64_s, b)), + "leTest: test 64 bits with scalar failed"); return result; } @@ -247,9 +211,8 @@ contract PrecompilesComparison1TestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.lt(castingValues.a8_s, castingValues.b8_s) - ); + bool result = MpcCore.decrypt(MpcCore.lt(castingValues.a8_s, castingValues.b8_s)); + ltResult = result; // Calculate the results with cating to 16 check16.res16_16 = MpcCore.lt(castingValues.a16_s, castingValues.b16_s); @@ -279,27 +242,18 @@ contract PrecompilesComparison1TestsContract { require(result == res64, "letTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.lt(castingValues.a8_s, b)), - "letTest: test 8 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b16_s)) && - result == MpcCore.decrypt(MpcCore.lt(castingValues.a16_s, b)), - "letTest: test 16 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b32_s)) && - result == MpcCore.decrypt(MpcCore.lt(castingValues.a32_s, b)), - "letTest: test 32 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b64_s)) && - result == MpcCore.decrypt(MpcCore.lt(castingValues.a64_s, b)), - "letTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.lt(castingValues.a8_s, b)), + "letTest: test 8 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.lt(castingValues.a16_s, b)), + "letTest: test 16 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.lt(castingValues.a32_s, b)), + "letTest: test 32 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.lt(castingValues.a64_s, b)), + "letTest: test 64 bits with scalar failed"); return result; } + + + } diff --git a/contracts/examples/precompiles/PrecompilesComparison2TestsContract.sol b/contracts/examples/precompiles/PrecompilesComparison2TestsContract.sol index d840836..40a0cac 100644 --- a/contracts/examples/precompiles/PrecompilesComparison2TestsContract.sol +++ b/contracts/examples/precompiles/PrecompilesComparison2TestsContract.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.19; import "../../lib/MpcCore.sol"; contract PrecompilesComparison2TestsContract { + struct AllGTCastingValues { gtUint8 a8_s; gtUint8 b8_s; @@ -39,74 +40,65 @@ contract PrecompilesComparison2TestsContract { gtBool res64_32; } - function setPublicValues( - AllGTCastingValues memory castingValues, - uint8 a, - uint8 b - ) public { + function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{ castingValues.a8_s = MpcCore.setPublic8(a); castingValues.b8_s = MpcCore.setPublic8(b); - castingValues.a16_s = MpcCore.setPublic16(a); - castingValues.b16_s = MpcCore.setPublic16(b); - castingValues.a32_s = MpcCore.setPublic32(a); - castingValues.b32_s = MpcCore.setPublic32(b); - castingValues.a64_s = MpcCore.setPublic64(a); - castingValues.b64_s = MpcCore.setPublic64(b); + castingValues.a16_s = MpcCore.setPublic16(a); + castingValues.b16_s = MpcCore.setPublic16(b); + castingValues.a32_s = MpcCore.setPublic32(a); + castingValues.b32_s = MpcCore.setPublic32(b); + castingValues.a64_s = MpcCore.setPublic64(a); + castingValues.b64_s = MpcCore.setPublic64(b); } - bool result; + bool eqResult; + bool neResult; + bool geResult; - function getResult() public view returns (bool) { - return result; + function getEqResult() public view returns (bool) { + return eqResult; + } + + function getNeResult() public view returns (bool) { + return neResult; + } + + function getGeResult() public view returns (bool) { + return geResult; } - function decryptAndCompareResults16( - Check16 memory check16 - ) public returns (bool) { + function decryptAndCompareResults16(Check16 memory check16) public returns (bool){ + // Calculate the result bool result = MpcCore.decrypt(check16.res16_16); - require( - result == MpcCore.decrypt(check16.res8_16) && - result == MpcCore.decrypt(check16.res16_8), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function decryptAndCompareResults32( - Check32 memory check32 - ) public returns (bool) { + function decryptAndCompareResults32(Check32 memory check32) public returns (bool){ + // Calculate the result bool result = MpcCore.decrypt(check32.res32_32); - require( - result == MpcCore.decrypt(check32.res8_32) && - result == MpcCore.decrypt(check32.res32_8) && - result == MpcCore.decrypt(check32.res32_16) && - result == MpcCore.decrypt(check32.res16_32), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check32.res8_32) && result == MpcCore.decrypt(check32.res32_8) + && result == MpcCore.decrypt(check32.res32_16) && result == MpcCore.decrypt(check32.res16_32), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function decryptAndCompareResults64( - Check64 memory check64 - ) public returns (bool) { + function decryptAndCompareResults64(Check64 memory check64) public returns (bool){ + // Calculate the result bool result = MpcCore.decrypt(check64.res64_64); - require( - result == MpcCore.decrypt(check64.res8_64) && - result == MpcCore.decrypt(check64.res64_8) && - result == MpcCore.decrypt(check64.res64_16) && - result == MpcCore.decrypt(check64.res16_64) && - result == MpcCore.decrypt(check64.res64_32) && - result == MpcCore.decrypt(check64.res32_64), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check64.res8_64) && result == MpcCore.decrypt(check64.res64_8) + && result == MpcCore.decrypt(check64.res64_16) && result == MpcCore.decrypt(check64.res16_64) + && result == MpcCore.decrypt(check64.res64_32) && result == MpcCore.decrypt(check64.res32_64), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } @@ -119,9 +111,8 @@ contract PrecompilesComparison2TestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.eq(castingValues.a8_s, castingValues.b8_s) - ); + bool result = MpcCore.decrypt(MpcCore.eq(castingValues.a8_s, castingValues.b8_s)); + eqResult = result; // Calculate the results with casting to 16 check16.res16_16 = MpcCore.eq(castingValues.a16_s, castingValues.b16_s); @@ -151,26 +142,14 @@ contract PrecompilesComparison2TestsContract { require(result == res64, "eqTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.eq(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.eq(castingValues.a8_s, b)), - "eqTest: test 8 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.eq(a, castingValues.b16_s)) && - result == MpcCore.decrypt(MpcCore.eq(castingValues.a16_s, b)), - "eqTest: test 16 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.eq(a, castingValues.b32_s)) && - result == MpcCore.decrypt(MpcCore.eq(castingValues.a32_s, b)), - "eqTest: test 32 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.eq(a, castingValues.b64_s)) && - result == MpcCore.decrypt(MpcCore.eq(castingValues.a64_s, b)), - "eqTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.eq(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.eq(castingValues.a8_s, b)), + "eqTest: test 8 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.eq(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.eq(castingValues.a16_s, b)), + "eqTest: test 16 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.eq(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.eq(castingValues.a32_s, b)), + "eqTest: test 32 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.eq(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.eq(castingValues.a64_s, b)), + "eqTest: test 64 bits with scalar failed"); return result; } @@ -183,9 +162,8 @@ contract PrecompilesComparison2TestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.ne(castingValues.a8_s, castingValues.b8_s) - ); + bool result = MpcCore.decrypt(MpcCore.ne(castingValues.a8_s, castingValues.b8_s)); + neResult = result; // Calculate the results with casting to 16 check16.res16_16 = MpcCore.ne(castingValues.a16_s, castingValues.b16_s); @@ -215,26 +193,14 @@ contract PrecompilesComparison2TestsContract { require(result == res64, "neTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.ne(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.ne(castingValues.a8_s, b)), - "neTest: test 8 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.ne(a, castingValues.b16_s)) && - result == MpcCore.decrypt(MpcCore.ne(castingValues.a16_s, b)), - "neTest: test 16 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.ne(a, castingValues.b32_s)) && - result == MpcCore.decrypt(MpcCore.ne(castingValues.a32_s, b)), - "neTest: test 32 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.ne(a, castingValues.b64_s)) && - result == MpcCore.decrypt(MpcCore.ne(castingValues.a64_s, b)), - "neTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.ne(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.ne(castingValues.a8_s, b)), + "neTest: test 8 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.ne(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.ne(castingValues.a16_s, b)), + "neTest: test 16 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.ne(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.ne(castingValues.a32_s, b)), + "neTest: test 32 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.ne(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.ne(castingValues.a64_s, b)), + "neTest: test 64 bits with scalar failed"); return result; } @@ -247,9 +213,8 @@ contract PrecompilesComparison2TestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.ge(castingValues.a8_s, castingValues.b8_s) - ); + bool result = MpcCore.decrypt(MpcCore.ge(castingValues.a8_s, castingValues.b8_s)); + geResult = result; // Calculate the results with casting to 16 check16.res16_16 = MpcCore.ge(castingValues.a16_s, castingValues.b16_s); @@ -279,27 +244,16 @@ contract PrecompilesComparison2TestsContract { require(result == res64, "geTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.ge(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.ge(castingValues.a8_s, b)), - "geTest: test 8 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.ge(a, castingValues.b16_s)) && - result == MpcCore.decrypt(MpcCore.ge(castingValues.a16_s, b)), - "geTest: test 16 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.ge(a, castingValues.b32_s)) && - result == MpcCore.decrypt(MpcCore.ge(castingValues.a32_s, b)), - "geTest: test 32 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.ge(a, castingValues.b64_s)) && - result == MpcCore.decrypt(MpcCore.ge(castingValues.a64_s, b)), - "geTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.ge(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.ge(castingValues.a8_s, b)), + "geTest: test 8 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.ge(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.ge(castingValues.a16_s, b)), + "geTest: test 16 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.ge(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.ge(castingValues.a32_s, b)), + "geTest: test 32 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.ge(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.ge(castingValues.a64_s, b)), + "geTest: test 64 bits with scalar failed"); return result; } + } diff --git a/contracts/examples/precompiles/PrecompilesMinMaxTestsContract.sol b/contracts/examples/precompiles/PrecompilesMinMaxTestsContract.sol index a42a425..756e7b1 100644 --- a/contracts/examples/precompiles/PrecompilesMinMaxTestsContract.sol +++ b/contracts/examples/precompiles/PrecompilesMinMaxTestsContract.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.19; import "../../lib/MpcCore.sol"; contract PrecompilesMinMaxTestsContract { + struct AllGTCastingValues { gtUint8 a8_s; gtUint8 b8_s; @@ -39,74 +40,59 @@ contract PrecompilesMinMaxTestsContract { gtUint64 res64_32; } - function setPublicValues( - AllGTCastingValues memory castingValues, - uint8 a, - uint8 b - ) public { + function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{ castingValues.a8_s = MpcCore.setPublic8(a); castingValues.b8_s = MpcCore.setPublic8(b); - castingValues.a16_s = MpcCore.setPublic16(a); - castingValues.b16_s = MpcCore.setPublic16(b); - castingValues.a32_s = MpcCore.setPublic32(a); - castingValues.b32_s = MpcCore.setPublic32(b); - castingValues.a64_s = MpcCore.setPublic64(a); - castingValues.b64_s = MpcCore.setPublic64(b); + castingValues.a16_s = MpcCore.setPublic16(a); + castingValues.b16_s = MpcCore.setPublic16(b); + castingValues.a32_s = MpcCore.setPublic32(a); + castingValues.b32_s = MpcCore.setPublic32(b); + castingValues.a64_s = MpcCore.setPublic64(a); + castingValues.b64_s = MpcCore.setPublic64(b); } - uint8 result; + uint8 minResult; + uint8 maxResult; - function getResult() public view returns (uint8) { - return result; + function getMinResult() public view returns (uint8) { + return minResult; } + function getMaxResult() public view returns (uint8) { + return maxResult; + } + + function decryptAndCompareResults16(Check16 memory check16) public returns (uint16){ - function decryptAndCompareResults16( - Check16 memory check16 - ) public returns (uint16) { // Calculate the result uint16 result = MpcCore.decrypt(check16.res16_16); - require( - result == MpcCore.decrypt(check16.res8_16) && - result == MpcCore.decrypt(check16.res16_8), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function decryptAndCompareResults32( - Check32 memory check32 - ) public returns (uint32) { + function decryptAndCompareResults32(Check32 memory check32) public returns (uint32){ + // Calculate the result uint32 result = MpcCore.decrypt(check32.res32_32); - require( - result == MpcCore.decrypt(check32.res8_32) && - result == MpcCore.decrypt(check32.res32_8) && - result == MpcCore.decrypt(check32.res32_16) && - result == MpcCore.decrypt(check32.res16_32), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check32.res8_32) && result == MpcCore.decrypt(check32.res32_8) + && result == MpcCore.decrypt(check32.res32_16) && result == MpcCore.decrypt(check32.res16_32), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function decryptAndCompareResults64( - Check64 memory check64 - ) public returns (uint64) { + function decryptAndCompareResults64(Check64 memory check64) public returns (uint64){ + // Calculate the result uint64 result = MpcCore.decrypt(check64.res64_64); - require( - result == MpcCore.decrypt(check64.res8_64) && - result == MpcCore.decrypt(check64.res64_8) && - result == MpcCore.decrypt(check64.res64_16) && - result == MpcCore.decrypt(check64.res16_64) && - result == MpcCore.decrypt(check64.res64_32) && - result == MpcCore.decrypt(check64.res32_64), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check64.res8_64) && result == MpcCore.decrypt(check64.res64_8) + && result == MpcCore.decrypt(check64.res64_16) && result == MpcCore.decrypt(check64.res16_64) + && result == MpcCore.decrypt(check64.res64_32) && result == MpcCore.decrypt(check64.res32_64), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } @@ -119,85 +105,45 @@ contract PrecompilesMinMaxTestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.min(castingValues.a8_s, castingValues.b8_s) - ); + uint8 result = MpcCore.decrypt(MpcCore.min(castingValues.a8_s, castingValues.b8_s)); + minResult = result; // Calculate the results with casting to 16 - check16.res16_16 = MpcCore.min( - castingValues.a16_s, - castingValues.b16_s - ); + check16.res16_16 = MpcCore.min(castingValues.a16_s, castingValues.b16_s); check16.res8_16 = MpcCore.min(castingValues.a8_s, castingValues.b16_s); check16.res16_8 = MpcCore.min(castingValues.a16_s, castingValues.b8_s); uint16 res16 = decryptAndCompareResults16(check16); require(res16 == result, "minTest: cast 16 failed"); // Calculate the result with casting to 32 - check32.res32_32 = MpcCore.min( - castingValues.a32_s, - castingValues.b32_s - ); + check32.res32_32 = MpcCore.min(castingValues.a32_s, castingValues.b32_s); check32.res8_32 = MpcCore.min(castingValues.a8_s, castingValues.b32_s); check32.res32_8 = MpcCore.min(castingValues.a32_s, castingValues.b8_s); - check32.res16_32 = MpcCore.min( - castingValues.a16_s, - castingValues.b32_s - ); - check32.res32_16 = MpcCore.min( - castingValues.a32_s, - castingValues.b16_s - ); + check32.res16_32 = MpcCore.min(castingValues.a16_s, castingValues.b32_s); + check32.res32_16 = MpcCore.min(castingValues.a32_s, castingValues.b16_s); uint32 res32 = decryptAndCompareResults32(check32); require(result == res32, "minTest: cast 32 failed"); // Calculate the result with casting to 64 - check64.res64_64 = MpcCore.min( - castingValues.a64_s, - castingValues.b64_s - ); + check64.res64_64 = MpcCore.min(castingValues.a64_s, castingValues.b64_s); check64.res8_64 = MpcCore.min(castingValues.a8_s, castingValues.b64_s); check64.res64_8 = MpcCore.min(castingValues.a64_s, castingValues.b8_s); - check64.res16_64 = MpcCore.min( - castingValues.a16_s, - castingValues.b64_s - ); - check64.res64_16 = MpcCore.min( - castingValues.a64_s, - castingValues.b16_s - ); - check64.res32_64 = MpcCore.min( - castingValues.a32_s, - castingValues.b64_s - ); - check64.res64_32 = MpcCore.min( - castingValues.a64_s, - castingValues.b32_s - ); + check64.res16_64 = MpcCore.min(castingValues.a16_s, castingValues.b64_s); + check64.res64_16 = MpcCore.min(castingValues.a64_s, castingValues.b16_s); + check64.res32_64 = MpcCore.min(castingValues.a32_s, castingValues.b64_s); + check64.res64_32 = MpcCore.min(castingValues.a64_s, castingValues.b32_s); uint64 res64 = decryptAndCompareResults64(check64); require(result == res64, "minTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.min(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.min(castingValues.a8_s, b)), - "minTest: test 8 bits with scalar failed" - ); - require( - res16 == MpcCore.decrypt(MpcCore.min(a, castingValues.b16_s)) && - res16 == MpcCore.decrypt(MpcCore.min(castingValues.a16_s, b)), - "minTest: test 16 bits with scalar failed" - ); - require( - res32 == MpcCore.decrypt(MpcCore.min(a, castingValues.b32_s)) && - res32 == MpcCore.decrypt(MpcCore.min(castingValues.a32_s, b)), - "minTest: test 32 bits with scalar failed" - ); - require( - res64 == MpcCore.decrypt(MpcCore.min(a, castingValues.b64_s)) && - res64 == MpcCore.decrypt(MpcCore.min(castingValues.a64_s, b)), - "minTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.min(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.min(castingValues.a8_s, b)), + "minTest: test 8 bits with scalar failed"); + require(res16 == MpcCore.decrypt(MpcCore.min(a, castingValues.b16_s)) && res16 == MpcCore.decrypt(MpcCore.min(castingValues.a16_s, b)), + "minTest: test 16 bits with scalar failed"); + require(res32 == MpcCore.decrypt(MpcCore.min(a, castingValues.b32_s)) && res32 == MpcCore.decrypt(MpcCore.min(castingValues.a32_s, b)), + "minTest: test 32 bits with scalar failed"); + require(res64 == MpcCore.decrypt(MpcCore.min(a, castingValues.b64_s)) && res64 == MpcCore.decrypt(MpcCore.min(castingValues.a64_s, b)), + "minTest: test 64 bits with scalar failed"); return result; } @@ -210,86 +156,47 @@ contract PrecompilesMinMaxTestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.max(castingValues.a8_s, castingValues.b8_s) - ); + uint8 result = MpcCore.decrypt(MpcCore.max(castingValues.a8_s, castingValues.b8_s)); + maxResult = result; // Calculate the results with casting to 16 - check16.res16_16 = MpcCore.max( - castingValues.a16_s, - castingValues.b16_s - ); + check16.res16_16 = MpcCore.max(castingValues.a16_s, castingValues.b16_s); check16.res8_16 = MpcCore.max(castingValues.a8_s, castingValues.b16_s); check16.res16_8 = MpcCore.max(castingValues.a16_s, castingValues.b8_s); uint16 res16 = decryptAndCompareResults16(check16); require(res16 == result, "maxTest: cast 16 failed"); // Calculate the result with casting to 32 - check32.res32_32 = MpcCore.max( - castingValues.a32_s, - castingValues.b32_s - ); + check32.res32_32 = MpcCore.max(castingValues.a32_s, castingValues.b32_s); check32.res8_32 = MpcCore.max(castingValues.a8_s, castingValues.b32_s); check32.res32_8 = MpcCore.max(castingValues.a32_s, castingValues.b8_s); - check32.res16_32 = MpcCore.max( - castingValues.a16_s, - castingValues.b32_s - ); - check32.res32_16 = MpcCore.max( - castingValues.a32_s, - castingValues.b16_s - ); + check32.res16_32 = MpcCore.max(castingValues.a16_s, castingValues.b32_s); + check32.res32_16 = MpcCore.max(castingValues.a32_s, castingValues.b16_s); uint32 res32 = decryptAndCompareResults32(check32); require(result == res32, "maxTest: cast 32 failed"); // Calculate the result with casting to 64 - check64.res64_64 = MpcCore.max( - castingValues.a64_s, - castingValues.b64_s - ); + check64.res64_64 = MpcCore.max(castingValues.a64_s, castingValues.b64_s); check64.res8_64 = MpcCore.max(castingValues.a8_s, castingValues.b64_s); check64.res64_8 = MpcCore.max(castingValues.a64_s, castingValues.b8_s); - check64.res16_64 = MpcCore.max( - castingValues.a16_s, - castingValues.b64_s - ); - check64.res64_16 = MpcCore.max( - castingValues.a64_s, - castingValues.b16_s - ); - check64.res32_64 = MpcCore.max( - castingValues.a32_s, - castingValues.b64_s - ); - check64.res64_32 = MpcCore.max( - castingValues.a64_s, - castingValues.b32_s - ); + check64.res16_64 = MpcCore.max(castingValues.a16_s, castingValues.b64_s); + check64.res64_16 = MpcCore.max(castingValues.a64_s, castingValues.b16_s); + check64.res32_64 = MpcCore.max(castingValues.a32_s, castingValues.b64_s); + check64.res64_32 = MpcCore.max(castingValues.a64_s, castingValues.b32_s); uint64 res64 = decryptAndCompareResults64(check64); require(result == res64, "maxTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.max(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.max(castingValues.a8_s, b)), - "minTest: test 8 bits with scalar failed" - ); - require( - res16 == MpcCore.decrypt(MpcCore.max(a, castingValues.b16_s)) && - res16 == MpcCore.decrypt(MpcCore.max(castingValues.a16_s, b)), - "minTest: test 16 bits with scalar failed" - ); - require( - res32 == MpcCore.decrypt(MpcCore.max(a, castingValues.b32_s)) && - res32 == MpcCore.decrypt(MpcCore.max(castingValues.a32_s, b)), - "minTest: test 32 bits with scalar failed" - ); - require( - res64 == MpcCore.decrypt(MpcCore.max(a, castingValues.b64_s)) && - res64 == MpcCore.decrypt(MpcCore.max(castingValues.a64_s, b)), - "minTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.max(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.max(castingValues.a8_s, b)), + "minTest: test 8 bits with scalar failed"); + require(res16 == MpcCore.decrypt(MpcCore.max(a, castingValues.b16_s)) && res16 == MpcCore.decrypt(MpcCore.max(castingValues.a16_s, b)), + "minTest: test 16 bits with scalar failed"); + require(res32 == MpcCore.decrypt(MpcCore.max(a, castingValues.b32_s)) && res32 == MpcCore.decrypt(MpcCore.max(castingValues.a32_s, b)), + "minTest: test 32 bits with scalar failed"); + require(res64 == MpcCore.decrypt(MpcCore.max(a, castingValues.b64_s)) && res64 == MpcCore.decrypt(MpcCore.max(castingValues.a64_s, b)), + "minTest: test 64 bits with scalar failed"); return result; } + } diff --git a/contracts/examples/precompiles/PrecompilesMiscellaneous1TestsContract.sol b/contracts/examples/precompiles/PrecompilesMiscellaneous1TestsContract.sol index 78e9497..6713a11 100644 --- a/contracts/examples/precompiles/PrecompilesMiscellaneous1TestsContract.sol +++ b/contracts/examples/precompiles/PrecompilesMiscellaneous1TestsContract.sol @@ -4,7 +4,9 @@ pragma solidity ^0.8.19; import "../../lib/MpcCore.sol"; contract PrecompilesMiscellaneous1TestsContract { + uint64 random = 0; + uint64 randomBounded = 0; bool andRes; bool orRes; bool xorRes; @@ -14,25 +16,22 @@ contract PrecompilesMiscellaneous1TestsContract { bool muxRes; bool onboardRes; + uint8 validateCiphertextRes; + function getRandom() public view returns (uint64) { return random; } - function getBooleanResults() - public - view - returns (bool, bool, bool, bool, bool, bool, bool, bool) - { - return ( - andRes, - orRes, - xorRes, - notRes, - eqRes, - neqRes, - muxRes, - onboardRes - ); + function getRandomBounded() public view returns (uint64) { + return randomBounded; + } + + function getBooleanResults() public view returns (bool, bool, bool, bool, bool, bool, bool, bool) { + return (andRes, orRes, xorRes, notRes, eqRes, neqRes, muxRes, onboardRes); + } + + function getValidateCiphertextResult() public view returns (uint8) { + return validateCiphertextRes; } uint constant MAX_SIZE_8_BITS = 10; @@ -41,37 +40,24 @@ contract PrecompilesMiscellaneous1TestsContract { uint constant MAX_SIZE_64_BITS = 2; uint constant MAX_BOOL_SIZE = 40; - function checkNotAllEqual( - uint64[MAX_SIZE_8_BITS] memory randoms, - uint size - ) private { + function checkNotAllEqual(uint64[MAX_SIZE_8_BITS] memory randoms, uint size) private { // Count how many randoms are equal uint numEqual = 1; for (uint i = 1; i < size; i++) { - if (randoms[0] == randoms[i]) { + if (randoms[0] == randoms[i]){ numEqual++; } } - require( - numEqual != size, - "randomTest: random failed, all values are the same" - ); + require(numEqual != size, "randomTest: random failed, all values are the same"); } function randomTest() public returns (uint64) { return randTest_(false, 0); } - function checkBound( - uint64[MAX_SIZE_8_BITS] memory randoms, - uint size, - uint8 numBits - ) public { + function checkBound(uint64[MAX_SIZE_8_BITS] memory randoms, uint size, uint8 numBits) public { for (uint i = 0; i < size; i++) { - require( - randoms[i] < (1 << numBits), - "randomTest: random failed, out of bounds" - ); + require(randoms[i] < (1 << numBits), "randomTest: random failed, out of bounds"); } } @@ -84,13 +70,13 @@ contract PrecompilesMiscellaneous1TestsContract { uint64[MAX_SIZE_8_BITS] memory randoms; // Generate gtUint8 randoms for (uint i = 0; i < size; i++) { - if (!isBounded) { + if(!isBounded){ randoms[i] = MpcCore.decrypt(MpcCore.rand8()); } else { randoms[i] = MpcCore.decrypt(MpcCore.randBoundedBits8(numBits)); } } - random = randoms[0]; + if (isBounded) { // Check that all randoms are in bounds checkBound(randoms, size, numBits); @@ -101,17 +87,15 @@ contract PrecompilesMiscellaneous1TestsContract { // In case of bounded random, the bit size does not matter because the bounded bits can be small. // So the max size remain as in 8 bits. // In case of unbounded random, max size can be reduced. - if (!isBounded) { + if (!isBounded){ size = MAX_SIZE_16_BITS; } // Generate gtUint16 randoms for (uint i = 0; i < size; i++) { - if (!isBounded) { + if(!isBounded){ randoms[i] = MpcCore.decrypt(MpcCore.rand16()); } else { - randoms[i] = MpcCore.decrypt( - MpcCore.randBoundedBits16(numBits) - ); + randoms[i] = MpcCore.decrypt(MpcCore.randBoundedBits16(numBits)); } } if (isBounded) { @@ -122,16 +106,14 @@ contract PrecompilesMiscellaneous1TestsContract { checkNotAllEqual(randoms, size); // Generate gtUint32 randoms - if (!isBounded) { + if (!isBounded){ size = MAX_SIZE_32_BITS; } for (uint i = 0; i < size; i++) { - if (!isBounded) { + if(!isBounded){ randoms[i] = MpcCore.decrypt(MpcCore.rand32()); } else { - randoms[i] = MpcCore.decrypt( - MpcCore.randBoundedBits32(numBits) - ); + randoms[i] = MpcCore.decrypt(MpcCore.randBoundedBits32(numBits)); } } if (isBounded) { @@ -142,21 +124,23 @@ contract PrecompilesMiscellaneous1TestsContract { checkNotAllEqual(randoms, size); // Generate gtUint64 randoms - if (!isBounded) { + if (!isBounded){ size = MAX_SIZE_64_BITS; } for (uint i = 0; i < size; i++) { - if (!isBounded) { + if(!isBounded){ randoms[i] = MpcCore.decrypt(MpcCore.rand64()); } else { - randoms[i] = MpcCore.decrypt( - MpcCore.randBoundedBits64(numBits) - ); + randoms[i] = MpcCore.decrypt(MpcCore.randBoundedBits64(numBits)); } } + if (isBounded) { // Check that all randoms are in bounds checkBound(randoms, size, numBits); + randomBounded = randoms[0]; + } else { + random = randoms[0]; } // Check that not all the generated random values are the same checkNotAllEqual(randoms, size); @@ -180,4 +164,40 @@ contract PrecompilesMiscellaneous1TestsContract { ctBool cipher = MpcCore.offBoard(aGT); onboardRes = MpcCore.decrypt(MpcCore.onBoard(cipher)); } + + // When invoking this test function, all ciphertexts share the same value but are + // cast to four different types: ctUint8, ctUint16, ctUint32, and ctUint64. + // Consequently, there is a single signature covering all these ciphertexts. + function validateCiphertextTest(ctUint8 ct8, ctUint16 ct16, ctUint32 ct32, ctUint64 ct64, bytes calldata signature) public returns (uint8){ + // Create ITs from ciphertext and signature + itUint8 memory it8; + it8.ciphertext = ct8; + it8.signature = signature; + + itUint16 memory it16; + it16.ciphertext = ct16; + it16.signature = signature; + + itUint32 memory it32; + it32.ciphertext = ct32; + it32.signature = signature; + + itUint64 memory it64; + it64.ciphertext = ct64; + it64.signature = signature; + + validateCiphertextRes = MpcCore.decrypt(MpcCore.validateCiphertext(it8)); + + uint16 result16 = MpcCore.decrypt(MpcCore.validateCiphertext(it16)); + require(result16 == validateCiphertextRes, "validateCiphertextTest: validateCiphertext with 16 bits failed"); + + uint32 result32 = MpcCore.decrypt(MpcCore.validateCiphertext(it32)); + require(result32 == validateCiphertextRes, "validateCiphertextTest: validateCiphertext with 32 bits failed"); + + uint64 result64 = MpcCore.decrypt(MpcCore.validateCiphertext(it64)); + require(result64 == validateCiphertextRes, "validateCiphertextTest: validateCiphertext with 64 bits failed"); + + return validateCiphertextRes; + } + } diff --git a/contracts/examples/precompiles/PrecompilesMiscellaneousTestsContract.sol b/contracts/examples/precompiles/PrecompilesMiscellaneousTestsContract.sol index a61198f..42d838b 100644 --- a/contracts/examples/precompiles/PrecompilesMiscellaneousTestsContract.sol +++ b/contracts/examples/precompiles/PrecompilesMiscellaneousTestsContract.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.19; import "../../lib/MpcCore.sol"; contract PrecompilesMiscellaneousTestsContract { + struct AllGTCastingValues { gtUint8 a8_s; gtUint8 b8_s; @@ -39,79 +40,67 @@ contract PrecompilesMiscellaneousTestsContract { gtUint64 res64_32; } - function setPublicValues( - AllGTCastingValues memory castingValues, - uint8 a, - uint8 b - ) public { + function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{ castingValues.a8_s = MpcCore.setPublic8(a); castingValues.b8_s = MpcCore.setPublic8(b); - castingValues.a16_s = MpcCore.setPublic16(a); - castingValues.b16_s = MpcCore.setPublic16(b); - castingValues.a32_s = MpcCore.setPublic32(a); - castingValues.b32_s = MpcCore.setPublic32(b); - castingValues.a64_s = MpcCore.setPublic64(a); - castingValues.b64_s = MpcCore.setPublic64(b); + castingValues.a16_s = MpcCore.setPublic16(a); + castingValues.b16_s = MpcCore.setPublic16(b); + castingValues.a32_s = MpcCore.setPublic32(a); + castingValues.b32_s = MpcCore.setPublic32(b); + castingValues.a64_s = MpcCore.setPublic64(a); + castingValues.b64_s = MpcCore.setPublic64(b); } - uint8 result; + uint8 divResult; + uint8 remResult; + uint8 muxResult; bool boolResult; - function getResult() public view returns (uint8) { - return result; + function getDivResult() public view returns (uint8) { + return divResult; + } + function getRemResult() public view returns (uint8) { + return remResult; + } + function getMuxResult() public view returns (uint8) { + return muxResult; } function getBoolResult() public view returns (bool) { return boolResult; } - function decryptAndCompareResults16( - Check16 memory check16 - ) public returns (uint16) { + function decryptAndCompareResults16(Check16 memory check16) public returns (uint16){ + // Calculate the result uint16 result = MpcCore.decrypt(check16.res16_16); - require( - result == MpcCore.decrypt(check16.res8_16) && - result == MpcCore.decrypt(check16.res16_8), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function decryptAndCompareResults32( - Check32 memory check32 - ) public returns (uint32) { + function decryptAndCompareResults32(Check32 memory check32) public returns (uint32){ + // Calculate the result uint32 result = MpcCore.decrypt(check32.res32_32); - require( - result == MpcCore.decrypt(check32.res8_32) && - result == MpcCore.decrypt(check32.res32_8) && - result == MpcCore.decrypt(check32.res32_16) && - result == MpcCore.decrypt(check32.res16_32), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check32.res8_32) && result == MpcCore.decrypt(check32.res32_8) + && result == MpcCore.decrypt(check32.res32_16) && result == MpcCore.decrypt(check32.res16_32), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function decryptAndCompareResults64( - Check64 memory check64 - ) public returns (uint64) { + function decryptAndCompareResults64(Check64 memory check64) public returns (uint64){ // Calculate the result uint64 result = MpcCore.decrypt(check64.res64_64); - require( - result == MpcCore.decrypt(check64.res8_64) && - result == MpcCore.decrypt(check64.res64_8) && - result == MpcCore.decrypt(check64.res64_16) && - result == MpcCore.decrypt(check64.res16_64) && - result == MpcCore.decrypt(check64.res64_32) && - result == MpcCore.decrypt(check64.res32_64), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check64.res8_64) && result == MpcCore.decrypt(check64.res64_8) + && result == MpcCore.decrypt(check64.res64_16) && result == MpcCore.decrypt(check64.res16_64) + && result == MpcCore.decrypt(check64.res64_32) && result == MpcCore.decrypt(check64.res32_64), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } @@ -124,85 +113,45 @@ contract PrecompilesMiscellaneousTestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.div(castingValues.a8_s, castingValues.b8_s) - ); + uint8 result = MpcCore.decrypt(MpcCore.div(castingValues.a8_s, castingValues.b8_s)); + divResult = result; // Calculate the results with casting to 16 - check16.res16_16 = MpcCore.div( - castingValues.a16_s, - castingValues.b16_s - ); + check16.res16_16 = MpcCore.div(castingValues.a16_s, castingValues.b16_s); check16.res8_16 = MpcCore.div(castingValues.a8_s, castingValues.b16_s); check16.res16_8 = MpcCore.div(castingValues.a16_s, castingValues.b8_s); uint16 res16 = decryptAndCompareResults16(check16); require(res16 == result, "divTest: cast 16 failed"); // Calculate the result with casting to 32 - check32.res32_32 = MpcCore.div( - castingValues.a32_s, - castingValues.b32_s - ); + check32.res32_32 = MpcCore.div(castingValues.a32_s, castingValues.b32_s); check32.res8_32 = MpcCore.div(castingValues.a8_s, castingValues.b32_s); check32.res32_8 = MpcCore.div(castingValues.a32_s, castingValues.b8_s); - check32.res16_32 = MpcCore.div( - castingValues.a16_s, - castingValues.b32_s - ); - check32.res32_16 = MpcCore.div( - castingValues.a32_s, - castingValues.b16_s - ); + check32.res16_32 = MpcCore.div(castingValues.a16_s, castingValues.b32_s); + check32.res32_16 = MpcCore.div(castingValues.a32_s, castingValues.b16_s); uint32 res32 = decryptAndCompareResults32(check32); require(result == res32, "divTest: cast 32 failed"); // Calculate the result with casting to 64 - check64.res64_64 = MpcCore.div( - castingValues.a64_s, - castingValues.b64_s - ); + check64.res64_64 = MpcCore.div(castingValues.a64_s, castingValues.b64_s); check64.res8_64 = MpcCore.div(castingValues.a8_s, castingValues.b64_s); check64.res64_8 = MpcCore.div(castingValues.a64_s, castingValues.b8_s); - check64.res16_64 = MpcCore.div( - castingValues.a16_s, - castingValues.b64_s - ); - check64.res64_16 = MpcCore.div( - castingValues.a64_s, - castingValues.b16_s - ); - check64.res32_64 = MpcCore.div( - castingValues.a32_s, - castingValues.b64_s - ); - check64.res64_32 = MpcCore.div( - castingValues.a64_s, - castingValues.b32_s - ); + check64.res16_64 = MpcCore.div(castingValues.a16_s, castingValues.b64_s); + check64.res64_16 = MpcCore.div(castingValues.a64_s, castingValues.b16_s); + check64.res32_64 = MpcCore.div(castingValues.a32_s, castingValues.b64_s); + check64.res64_32 = MpcCore.div(castingValues.a64_s, castingValues.b32_s); uint64 res64 = decryptAndCompareResults64(check64); require(result == res64, "divTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.div(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.div(castingValues.a8_s, b)), - "divTest: test 8 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.div(a, castingValues.b16_s)) && - result == MpcCore.decrypt(MpcCore.div(castingValues.a16_s, b)), - "divTest: test 16 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.div(a, castingValues.b32_s)) && - result == MpcCore.decrypt(MpcCore.div(castingValues.a32_s, b)), - "divTest: test 32 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.div(a, castingValues.b64_s)) && - result == MpcCore.decrypt(MpcCore.div(castingValues.a64_s, b)), - "divTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.div(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.div(castingValues.a8_s, b)), + "divTest: test 8 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.div(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.div(castingValues.a16_s, b)), + "divTest: test 16 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.div(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.div(castingValues.a32_s, b)), + "divTest: test 32 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.div(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.div(castingValues.a64_s, b)), + "divTest: test 64 bits with scalar failed"); return result; } @@ -215,94 +164,50 @@ contract PrecompilesMiscellaneousTestsContract { setPublicValues(castingValues, a, b); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.rem(castingValues.a8_s, castingValues.b8_s) - ); + uint8 result = MpcCore.decrypt(MpcCore.rem(castingValues.a8_s, castingValues.b8_s)); + remResult = result; // Calculate the results with casting to 16 - check16.res16_16 = MpcCore.rem( - castingValues.a16_s, - castingValues.b16_s - ); + check16.res16_16 = MpcCore.rem(castingValues.a16_s, castingValues.b16_s); check16.res8_16 = MpcCore.rem(castingValues.a8_s, castingValues.b16_s); check16.res16_8 = MpcCore.rem(castingValues.a16_s, castingValues.b8_s); uint16 res16 = decryptAndCompareResults16(check16); require(res16 == result, "remTest: cast 16 failed"); // Calculate the result with casting to 32 - check32.res32_32 = MpcCore.rem( - castingValues.a32_s, - castingValues.b32_s - ); + check32.res32_32 = MpcCore.rem(castingValues.a32_s, castingValues.b32_s); check32.res8_32 = MpcCore.rem(castingValues.a8_s, castingValues.b32_s); check32.res32_8 = MpcCore.rem(castingValues.a32_s, castingValues.b8_s); - check32.res16_32 = MpcCore.rem( - castingValues.a16_s, - castingValues.b32_s - ); - check32.res32_16 = MpcCore.rem( - castingValues.a32_s, - castingValues.b16_s - ); + check32.res16_32 = MpcCore.rem(castingValues.a16_s, castingValues.b32_s); + check32.res32_16 = MpcCore.rem(castingValues.a32_s, castingValues.b16_s); uint32 res32 = decryptAndCompareResults32(check32); require(result == res32, "remTest: cast 32 failed"); // Calculate the result with casting to 64 - check64.res64_64 = MpcCore.rem( - castingValues.a64_s, - castingValues.b64_s - ); + check64.res64_64 = MpcCore.rem(castingValues.a64_s, castingValues.b64_s); check64.res8_64 = MpcCore.rem(castingValues.a8_s, castingValues.b64_s); check64.res64_8 = MpcCore.rem(castingValues.a64_s, castingValues.b8_s); - check64.res16_64 = MpcCore.rem( - castingValues.a16_s, - castingValues.b64_s - ); - check64.res64_16 = MpcCore.rem( - castingValues.a64_s, - castingValues.b16_s - ); - check64.res32_64 = MpcCore.rem( - castingValues.a32_s, - castingValues.b64_s - ); - check64.res64_32 = MpcCore.rem( - castingValues.a64_s, - castingValues.b32_s - ); + check64.res16_64 = MpcCore.rem(castingValues.a16_s, castingValues.b64_s); + check64.res64_16 = MpcCore.rem(castingValues.a64_s, castingValues.b16_s); + check64.res32_64 = MpcCore.rem(castingValues.a32_s, castingValues.b64_s); + check64.res64_32 = MpcCore.rem(castingValues.a64_s, castingValues.b32_s); uint64 res64 = decryptAndCompareResults64(check64); require(result == res64, "remTest: cast 64 failed"); // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.rem(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.rem(castingValues.a8_s, b)), - "remTest: test 8 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.rem(a, castingValues.b16_s)) && - result == MpcCore.decrypt(MpcCore.rem(castingValues.a16_s, b)), - "remTest: test 16 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.rem(a, castingValues.b32_s)) && - result == MpcCore.decrypt(MpcCore.rem(castingValues.a32_s, b)), - "remTest: test 32 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.rem(a, castingValues.b64_s)) && - result == MpcCore.decrypt(MpcCore.rem(castingValues.a64_s, b)), - "remTest: test 64 bits with scalar failed" - ); + require(result == MpcCore.decrypt(MpcCore.rem(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.rem(castingValues.a8_s, b)), + "remTest: test 8 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.rem(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.rem(castingValues.a16_s, b)), + "remTest: test 16 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.rem(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.rem(castingValues.a32_s, b)), + "remTest: test 32 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.rem(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.rem(castingValues.a64_s, b)), + "remTest: test 64 bits with scalar failed"); return result; } - function muxTest( - bool selectionBit, - uint8 a, - uint8 b - ) public returns (uint8) { + function muxTest(bool selectionBit, uint8 a, uint8 b) public returns (uint8) { AllGTCastingValues memory castingValues; Check16 memory check16; Check32 memory check32; @@ -311,127 +216,45 @@ contract PrecompilesMiscellaneousTestsContract { gtBool selectionBit_s = MpcCore.setPublic(selectionBit); // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.mux(selectionBit_s, castingValues.a8_s, castingValues.b8_s) - ); + uint8 result = MpcCore.decrypt(MpcCore.mux(selectionBit_s, castingValues.a8_s, castingValues.b8_s)); + muxResult = result; // Calculate the result with casting to 16 - check16.res16_16 = MpcCore.mux( - selectionBit_s, - castingValues.a16_s, - castingValues.b16_s - ); - check16.res8_16 = MpcCore.mux( - selectionBit_s, - castingValues.a8_s, - castingValues.b16_s - ); - check16.res16_8 = MpcCore.mux( - selectionBit_s, - castingValues.a16_s, - castingValues.b8_s - ); + check16.res16_16 = MpcCore.mux(selectionBit_s, castingValues.a16_s, castingValues.b16_s); + check16.res8_16 = MpcCore.mux(selectionBit_s, castingValues.a8_s, castingValues.b16_s); + check16.res16_8 = MpcCore.mux(selectionBit_s, castingValues.a16_s, castingValues.b8_s); uint16 res16 = decryptAndCompareResults16(check16); require(res16 == result, "muxTest: cast 16 failed"); // Calculate the result with casting to 32 - check32.res32_32 = MpcCore.mux( - selectionBit_s, - castingValues.a32_s, - castingValues.b32_s - ); - check32.res8_32 = MpcCore.mux( - selectionBit_s, - castingValues.a8_s, - castingValues.b32_s - ); - check32.res32_8 = MpcCore.mux( - selectionBit_s, - castingValues.a32_s, - castingValues.b8_s - ); - check32.res16_32 = MpcCore.mux( - selectionBit_s, - castingValues.a16_s, - castingValues.b32_s - ); - check32.res32_16 = MpcCore.mux( - selectionBit_s, - castingValues.a32_s, - castingValues.b16_s - ); + check32.res32_32 = MpcCore.mux(selectionBit_s, castingValues.a32_s, castingValues.b32_s); + check32.res8_32 = MpcCore.mux(selectionBit_s, castingValues.a8_s, castingValues.b32_s); + check32.res32_8 = MpcCore.mux(selectionBit_s, castingValues.a32_s, castingValues.b8_s); + check32.res16_32 = MpcCore.mux(selectionBit_s, castingValues.a16_s, castingValues.b32_s); + check32.res32_16 = MpcCore.mux(selectionBit_s, castingValues.a32_s, castingValues.b16_s); uint32 res32 = decryptAndCompareResults32(check32); require(result == res32, "muxTest: cast 32 failed"); // Calculate the result with casting to 64 - check64.res64_64 = MpcCore.mux( - selectionBit_s, - castingValues.a64_s, - castingValues.b64_s - ); - check64.res8_64 = MpcCore.mux( - selectionBit_s, - castingValues.a8_s, - castingValues.b64_s - ); - check64.res64_8 = MpcCore.mux( - selectionBit_s, - castingValues.a64_s, - castingValues.b8_s - ); - check64.res16_64 = MpcCore.mux( - selectionBit_s, - castingValues.a16_s, - castingValues.b64_s - ); - check64.res64_16 = MpcCore.mux( - selectionBit_s, - castingValues.a64_s, - castingValues.b16_s - ); - check64.res32_64 = MpcCore.mux( - selectionBit_s, - castingValues.a32_s, - castingValues.b64_s - ); - check64.res64_32 = MpcCore.mux( - selectionBit_s, - castingValues.a64_s, - castingValues.b32_s - ); + check64.res64_64 = MpcCore.mux(selectionBit_s, castingValues.a64_s, castingValues.b64_s); + check64.res8_64 = MpcCore.mux(selectionBit_s, castingValues.a8_s, castingValues.b64_s); + check64.res64_8 = MpcCore.mux(selectionBit_s, castingValues.a64_s, castingValues.b8_s); + check64.res16_64 = MpcCore.mux(selectionBit_s, castingValues.a16_s, castingValues.b64_s); + check64.res64_16 = MpcCore.mux(selectionBit_s, castingValues.a64_s, castingValues.b16_s); + check64.res32_64 = MpcCore.mux(selectionBit_s, castingValues.a32_s, castingValues.b64_s); + check64.res64_32 = MpcCore.mux(selectionBit_s, castingValues.a64_s, castingValues.b32_s); uint64 res64 = decryptAndCompareResults64(check64); require(result == res64, "muxTest: cast 64 failed"); - return result; - } - - function offboardOnboardTest( - uint8 a8, - uint16 a16, - uint32 a32, - uint32 a64 - ) public returns (uint8) { - gtUint8 a8_s = MpcCore.setPublic8(a8); - gtUint16 a16_s = MpcCore.setPublic16(a16); - gtUint32 a32_s = MpcCore.setPublic32(a32); - gtUint64 a64_s = MpcCore.setPublic64(a64); - - ctUint8 cipher8 = MpcCore.offBoard(a8_s); - result = MpcCore.decrypt(MpcCore.onBoard(cipher8)); - - ctUint16 cipher16 = MpcCore.offBoard(a16_s); - uint16 result16 = MpcCore.decrypt(MpcCore.onBoard(cipher16)); - - ctUint32 cipher32 = MpcCore.offBoard(a32_s); - uint32 result32 = MpcCore.decrypt(MpcCore.onBoard(cipher32)); - - ctUint64 cipher64 = MpcCore.offBoard(a64_s); - uint64 result64 = MpcCore.decrypt(MpcCore.onBoard(cipher64)); - - require( - result == result16 && result == result32 && result == result64, - "Failed to offboard and onboard all values" - ); + // Check the result with scalar + require(result == MpcCore.decrypt(MpcCore.mux(selectionBit_s, a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.mux(selectionBit_s, castingValues.a8_s, b)), + "muxTest: test 8 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.mux(selectionBit_s, a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.mux(selectionBit_s, castingValues.a16_s, b)), + "muxTest: test 16 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.mux(selectionBit_s, a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.mux(selectionBit_s, castingValues.a32_s, b)), + "muxTest: test 32 bits with scalar failed"); + require(result == MpcCore.decrypt(MpcCore.mux(selectionBit_s, a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.mux(selectionBit_s, castingValues.a64_s, b)), + "muxTest: test 64 bits with scalar failed"); return result; } @@ -443,4 +266,5 @@ contract PrecompilesMiscellaneousTestsContract { return boolResult; } + } diff --git a/contracts/examples/precompiles/PrecompilesOffboardToUserKeyTestContract.sol b/contracts/examples/precompiles/PrecompilesOffboardToUserKeyTestContract.sol index ccf7d64..b48c29e 100644 --- a/contracts/examples/precompiles/PrecompilesOffboardToUserKeyTestContract.sol +++ b/contracts/examples/precompiles/PrecompilesOffboardToUserKeyTestContract.sol @@ -1,10 +1,13 @@ + // SPDX-License-Identifier: MIT pragma solidity ^0.8.19; import "../../lib/MpcCore.sol"; contract PrecompilesOffboardToUserKeyTestContract { - bytes userKey; + + bytes keyShare0; + bytes keyShare1; uint8 x; ctUint8 ctUserKey; @@ -13,20 +16,21 @@ contract PrecompilesOffboardToUserKeyTestContract { uint256 ct32; uint256 ct64; - event AccountOnboarded(address indexed _from, bytes userKey); + uint8 onboardOffboardResult; + + function getOnboardOffboardResult() public view returns (uint8) { + return onboardOffboardResult; + } function getCTs() public view returns (uint256, uint256, uint256, uint256) { return (ct8, ct16, ct32, ct64); } - function getUserKeyTest( - bytes calldata signedEK, - bytes calldata signature, - address addr - ) public returns (uint8) { + function getUserKeyTest(bytes calldata signedEK, bytes calldata signature, address addr) public returns (uint8) { + gtUint8 a = MpcCore.setPublic8(uint8(5)); gtUint8 c = MpcCore.add(a, uint8(5)); // 10 - userKey = MpcCore.getUserKey(signedEK, signature); + (keyShare0, keyShare1) = MpcCore.getUserKey(signedEK, signature); ctUserKey = MpcCore.offBoardToUser(c, addr); ctUint8 ctSystemKey = MpcCore.offBoard(c); gtUint8 c1 = MpcCore.onBoard(ctSystemKey); @@ -38,26 +42,21 @@ contract PrecompilesOffboardToUserKeyTestContract { return x; } - function getUserKey() public view returns (bytes memory) { - return userKey; + function getUserKeyShares() public view returns (bytes memory, bytes memory) { + return (keyShare0, keyShare1); } function getCt() public view returns (ctUint8) { return ctUserKey; } - function userKeyTest( - bytes calldata signedEK, - bytes calldata signature - ) public { - bytes memory encryptedKey = MpcCore.getUserKey(signedEK, signature); - emit AccountOnboarded(msg.sender, encryptedKey); + function userKeyTest(bytes calldata signedEK, bytes calldata signature) public returns (bytes memory, bytes memory) { + + (keyShare0, keyShare1) = MpcCore.getUserKey(signedEK, signature); + return (keyShare0, keyShare1); } - function offboardToUserTest( - uint8 a, - address addr - ) public returns (uint256, uint256, uint256, uint256) { + function offboardToUserTest(uint8 a, address addr) public returns (uint256, uint256, uint256, uint256) { gtUint8 a8_s = MpcCore.setPublic8(a); gtUint16 a16_s = MpcCore.setPublic16(a); gtUint32 a32_s = MpcCore.setPublic32(a); @@ -75,4 +74,29 @@ contract PrecompilesOffboardToUserKeyTestContract { return (ct8, ct16, ct32, ct64); } + + function offboardOnboardTest(uint8 a8, uint16 a16, uint32 a32, uint32 a64) public returns (uint8) { + gtUint8 a8_s = MpcCore.setPublic8(a8); + gtUint16 a16_s = MpcCore.setPublic16(a16); + gtUint32 a32_s = MpcCore.setPublic32(a32); + gtUint64 a64_s = MpcCore.setPublic64(a64); + + ctUint8 cipher8 = MpcCore.offBoard(a8_s); + uint8 result = MpcCore.decrypt(MpcCore.onBoard(cipher8)); + onboardOffboardResult = result; + + ctUint16 cipher16 = MpcCore.offBoard(a16_s); + uint16 result16 = MpcCore.decrypt(MpcCore.onBoard(cipher16)); + + ctUint32 cipher32 = MpcCore.offBoard(a32_s); + uint32 result32 = MpcCore.decrypt(MpcCore.onBoard(cipher32)); + + ctUint64 cipher64 = MpcCore.offBoard(a64_s); + uint64 result64 = MpcCore.decrypt(MpcCore.onBoard(cipher64)); + + require(result == result16 && result == result32 && result == result64, + "Failed to offboard and onboard all values"); + + return result; + } } diff --git a/contracts/examples/precompiles/PrecompilesShiftTestsContract.sol b/contracts/examples/precompiles/PrecompilesShiftTestsContract.sol index 9d69f1b..97a346a 100644 --- a/contracts/examples/precompiles/PrecompilesShiftTestsContract.sol +++ b/contracts/examples/precompiles/PrecompilesShiftTestsContract.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.19; import "../../lib/MpcCore.sol"; contract PrecompilesShiftTestsContract { + struct AllGTCastingValues { gtUint8 a8_s; gtUint8 b8_s; @@ -40,6 +41,7 @@ contract PrecompilesShiftTestsContract { } uint8 result; + uint8 result8; uint16 result16; uint32 result32; uint64 result64; @@ -48,262 +50,77 @@ contract PrecompilesShiftTestsContract { return result; } - function getAllShiftResults() - public - view - returns (uint8, uint16, uint32, uint64) - { - return (result, result16, result32, result64); + function getAllShiftResults() public view returns (uint8, uint16, uint32, uint64) { + return (result8, result16, result32, result64); } - function setPublicValues( - AllGTCastingValues memory castingValues, - uint8 a, - uint8 b - ) public { + function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{ castingValues.a8_s = MpcCore.setPublic8(a); castingValues.b8_s = MpcCore.setPublic8(b); - castingValues.a16_s = MpcCore.setPublic16(a); - castingValues.b16_s = MpcCore.setPublic16(b); - castingValues.a32_s = MpcCore.setPublic32(a); - castingValues.b32_s = MpcCore.setPublic32(b); - castingValues.a64_s = MpcCore.setPublic64(a); - castingValues.b64_s = MpcCore.setPublic64(b); + castingValues.a16_s = MpcCore.setPublic16(a); + castingValues.b16_s = MpcCore.setPublic16(b); + castingValues.a32_s = MpcCore.setPublic32(a); + castingValues.b32_s = MpcCore.setPublic32(b); + castingValues.a64_s = MpcCore.setPublic64(a); + castingValues.b64_s = MpcCore.setPublic64(b); } - function decryptAndCompareResults16( - Check16 memory check16 - ) public returns (uint16) { + function decryptAndCompareResults16(Check16 memory check16) public returns (uint16){ + // Calculate the result uint16 result = MpcCore.decrypt(check16.res16_16); - require( - result == MpcCore.decrypt(check16.res8_16) && - result == MpcCore.decrypt(check16.res16_8), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function decryptAndCompareResults32( - Check32 memory check32 - ) public returns (uint32) { + function decryptAndCompareResults32(Check32 memory check32) public returns (uint32){ + // Calculate the result uint32 result = MpcCore.decrypt(check32.res32_32); - require( - result == MpcCore.decrypt(check32.res8_32) && - result == MpcCore.decrypt(check32.res32_8) && - result == MpcCore.decrypt(check32.res32_16) && - result == MpcCore.decrypt(check32.res16_32), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check32.res8_32) && result == MpcCore.decrypt(check32.res32_8) + && result == MpcCore.decrypt(check32.res32_16) && result == MpcCore.decrypt(check32.res16_32), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function decryptAndCompareResults64( - Check64 memory check64 - ) public returns (uint64) { + function decryptAndCompareResults64(Check64 memory check64) public returns (uint64){ + // Calculate the result uint64 result = MpcCore.decrypt(check64.res64_64); - require( - result == MpcCore.decrypt(check64.res8_64) && - result == MpcCore.decrypt(check64.res64_8) && - result == MpcCore.decrypt(check64.res64_16) && - result == MpcCore.decrypt(check64.res16_64) && - result == MpcCore.decrypt(check64.res64_32) && - result == MpcCore.decrypt(check64.res32_64), - "decryptAndCompareAllResults: Failed to decrypt and compare all results" - ); + require(result == MpcCore.decrypt(check64.res8_64) && result == MpcCore.decrypt(check64.res64_8) + && result == MpcCore.decrypt(check64.res64_16) && result == MpcCore.decrypt(check64.res16_64) + && result == MpcCore.decrypt(check64.res64_32) && result == MpcCore.decrypt(check64.res32_64), + "decryptAndCompareAllResults: Failed to decrypt and compare all results"); return result; } - function shlTest( - uint8 a, - uint8 b - ) public returns (uint8, uint16, uint32, uint64) { + function shlTest(uint8 a, uint8 b) public returns (uint8, uint16, uint32, uint64) { AllGTCastingValues memory castingValues; - Check16 memory check16; - Check32 memory check32; - Check64 memory check64; setPublicValues(castingValues, a, b); - // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.shl(castingValues.a8_s, castingValues.b8_s) - ); - - // Calculate the result with casting to 16 - check16.res16_16 = MpcCore.shl( - castingValues.a16_s, - castingValues.b16_s - ); - check16.res8_16 = MpcCore.shl(castingValues.a8_s, castingValues.b16_s); - check16.res16_8 = MpcCore.shl(castingValues.a16_s, castingValues.b8_s); - result16 = decryptAndCompareResults16(check16); - - // Calculate the result with casting to 32 - check32.res32_32 = MpcCore.shl( - castingValues.a32_s, - castingValues.b32_s - ); - check32.res8_32 = MpcCore.shl(castingValues.a8_s, castingValues.b32_s); - check32.res32_8 = MpcCore.shl(castingValues.a32_s, castingValues.b8_s); - check32.res16_32 = MpcCore.shl( - castingValues.a16_s, - castingValues.b32_s - ); - check32.res32_16 = MpcCore.shl( - castingValues.a32_s, - castingValues.b16_s - ); - result32 = decryptAndCompareResults32(check32); - - // Calculate the result with casting to 64 - check64.res64_64 = MpcCore.shl( - castingValues.a64_s, - castingValues.b64_s - ); - check64.res8_64 = MpcCore.shl(castingValues.a8_s, castingValues.b64_s); - check64.res64_8 = MpcCore.shl(castingValues.a64_s, castingValues.b8_s); - check64.res16_64 = MpcCore.shl( - castingValues.a16_s, - castingValues.b64_s - ); - check64.res64_16 = MpcCore.shl( - castingValues.a64_s, - castingValues.b16_s - ); - check64.res32_64 = MpcCore.shl( - castingValues.a32_s, - castingValues.b64_s - ); - check64.res64_32 = MpcCore.shl( - castingValues.a64_s, - castingValues.b32_s - ); - result64 = decryptAndCompareResults64(check64); - - // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.shl(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.shl(castingValues.a8_s, b)), - "shlTest: test 8 bits with scalar failed" - ); - require( - result16 == MpcCore.decrypt(MpcCore.shl(a, castingValues.b16_s)) && - result16 == - MpcCore.decrypt(MpcCore.shl(castingValues.a16_s, b)), - "shlTest: test 16 bits with scalar failed" - ); - require( - result32 == MpcCore.decrypt(MpcCore.shl(a, castingValues.b32_s)) && - result32 == - MpcCore.decrypt(MpcCore.shl(castingValues.a32_s, b)), - "shlTest: test 32 bits with scalar failed" - ); - require( - result64 == MpcCore.decrypt(MpcCore.shl(a, castingValues.b64_s)) && - result64 == - MpcCore.decrypt(MpcCore.shl(castingValues.a64_s, b)), - "shlTest: test 64 bits with scalar failed" - ); - - return (result, result16, result32, result64); + result8 = MpcCore.decrypt(MpcCore.shl(castingValues.a8_s, b)); + result16 = MpcCore.decrypt(MpcCore.shl(castingValues.a16_s, b)); + result32 = MpcCore.decrypt(MpcCore.shl(castingValues.a32_s, b)); + result64 = MpcCore.decrypt(MpcCore.shl(castingValues.a64_s, b)); + return (result8, result16, result32, result64); } function shrTest(uint8 a, uint8 b) public returns (uint8) { AllGTCastingValues memory castingValues; - Check16 memory check16; - Check32 memory check32; - Check64 memory check64; setPublicValues(castingValues, a, b); - // Calculate the expected result - result = MpcCore.decrypt( - MpcCore.shr(castingValues.a8_s, castingValues.b8_s) - ); - - // Calculate the results with casting to 16 - check16.res16_16 = MpcCore.shr( - castingValues.a16_s, - castingValues.b16_s - ); - check16.res8_16 = MpcCore.shr(castingValues.a8_s, castingValues.b16_s); - check16.res16_8 = MpcCore.shr(castingValues.a16_s, castingValues.b8_s); - uint16 res16 = decryptAndCompareResults16(check16); - require(res16 == result, "shrTest: cast 16 failed"); - - // Calculate the result with casting to 32 - check32.res32_32 = MpcCore.shr( - castingValues.a32_s, - castingValues.b32_s - ); - check32.res8_32 = MpcCore.shr(castingValues.a8_s, castingValues.b32_s); - check32.res32_8 = MpcCore.shr(castingValues.a32_s, castingValues.b8_s); - check32.res16_32 = MpcCore.shr( - castingValues.a16_s, - castingValues.b32_s - ); - check32.res32_16 = MpcCore.shr( - castingValues.a32_s, - castingValues.b16_s - ); - uint32 res32 = decryptAndCompareResults32(check32); - require(result == res32, "shrTest: cast 32 failed"); - - // Calculate the result with casting to 64 - check64.res64_64 = MpcCore.shr( - castingValues.a64_s, - castingValues.b64_s - ); - check64.res8_64 = MpcCore.shr(castingValues.a8_s, castingValues.b64_s); - check64.res64_8 = MpcCore.shr(castingValues.a64_s, castingValues.b8_s); - check64.res16_64 = MpcCore.shr( - castingValues.a16_s, - castingValues.b64_s - ); - check64.res64_16 = MpcCore.shr( - castingValues.a64_s, - castingValues.b16_s - ); - check64.res32_64 = MpcCore.shr( - castingValues.a32_s, - castingValues.b64_s - ); - check64.res64_32 = MpcCore.shr( - castingValues.a64_s, - castingValues.b32_s - ); - uint64 res64 = decryptAndCompareResults64(check64); - require(result == res64, "shrTest: cast 64 failed"); - - // Check the result with scalar - require( - result == MpcCore.decrypt(MpcCore.shr(a, castingValues.b8_s)) && - result == MpcCore.decrypt(MpcCore.shr(castingValues.a8_s, b)), - "shrTest: test 8 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.shr(a, castingValues.b16_s)) && - result == MpcCore.decrypt(MpcCore.shr(castingValues.a16_s, b)), - "shrTest: test 16 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.shr(a, castingValues.b32_s)) && - result == MpcCore.decrypt(MpcCore.shr(castingValues.a32_s, b)), - "shrTest: test 32 bits with scalar failed" - ); - require( - result == MpcCore.decrypt(MpcCore.shr(a, castingValues.b64_s)) && - result == MpcCore.decrypt(MpcCore.shr(castingValues.a64_s, b)), - "shrTest: test 64 bits with scalar failed" - ); - + result = MpcCore.decrypt(MpcCore.shr(castingValues.a8_s, b)); + require(result == MpcCore.decrypt(MpcCore.shr(castingValues.a16_s, b)) && result == MpcCore.decrypt(MpcCore.shr(castingValues.a32_s, b)) + && result == MpcCore.decrypt(MpcCore.shr(castingValues.a64_s, b)), + "shrTest failed"); return result; } + } diff --git a/contracts/examples/precompiles/PrecompilesTransferScalarTestsContract.sol b/contracts/examples/precompiles/PrecompilesTransferScalarTestsContract.sol index 241f2f4..89064f6 100644 --- a/contracts/examples/precompiles/PrecompilesTransferScalarTestsContract.sol +++ b/contracts/examples/precompiles/PrecompilesTransferScalarTestsContract.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.19; import "../../lib/MpcCore.sol"; contract PrecompilesTransferScalarTestsContract { + struct AllGTCastingValues { gtUint8 a8_s; gtUint8 b8_s; @@ -23,247 +24,91 @@ contract PrecompilesTransferScalarTestsContract { return (new_a, new_b, res); } - function computeAndChekTransfer16( - AllGTCastingValues memory allGTCastingValues, - uint8 new_a, - uint8 new_b, - bool res, - uint8 amount - ) public { + function computeAndCheckTransfer16(AllGTCastingValues memory allGTCastingValues, uint8 new_a, uint8 new_b, bool res, uint8 amount) public { + // Check all options for casting to 16 while amount is scalar - (gtUint16 newA_s, gtUint16 newB_s, gtBool res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b16_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (gtUint16 newA_s, gtUint16 newB_s, gtBool res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b16_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a8_s, - allGTCastingValues.b16_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a8_s, allGTCastingValues.b16_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b8_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b8_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); } - function computeAndChekTransfer32( - AllGTCastingValues memory allGTCastingValues, - uint8 new_a, - uint8 new_b, - bool res, - uint8 amount - ) public { + function computeAndCheckTransfer32(AllGTCastingValues memory allGTCastingValues, uint8 new_a, uint8 new_b, bool res, uint8 amount) public { + // Check all options for casting to 32 while amount is scalar - (gtUint32 newA_s, gtUint32 newB_s, gtBool res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b32_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (gtUint32 newA_s, gtUint32 newB_s, gtBool res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b32_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a8_s, - allGTCastingValues.b32_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a8_s, allGTCastingValues.b32_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b8_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b8_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b32_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b32_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b16_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b16_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); } - function computeAndChekTransfer64( - AllGTCastingValues memory allGTCastingValues, - uint8 new_a, - uint8 new_b, - bool res, - uint8 amount - ) public { + function computeAndCheckTransfer64(AllGTCastingValues memory allGTCastingValues, uint8 new_a, uint8 new_b, bool res, uint8 amount) public { + // Check all options for casting to 64 while amount is scalar - (gtUint64 newA_s, gtUint64 newB_s, gtBool res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b64_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (gtUint64 newA_s, gtUint64 newB_s, gtBool res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b64_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a8_s, - allGTCastingValues.b64_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a8_s, allGTCastingValues.b64_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b8_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b8_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b64_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b64_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b16_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b16_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b64_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b64_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b32_s, - amount - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: check scalar failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b32_s, amount); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: check scalar failed"); } - function transferScalarTest( - uint8 a, - uint8 b, - uint8 amount - ) public returns (uint8, uint8, bool) { + + function transferScalarTest(uint8 a, uint8 b, uint8 amount) public returns (uint8, uint8, bool) { AllGTCastingValues memory allGTCastingValues; allGTCastingValues.a8_s = MpcCore.setPublic8(a); allGTCastingValues.b8_s = MpcCore.setPublic8(b); - allGTCastingValues.a16_s = MpcCore.setPublic16(a); - allGTCastingValues.b16_s = MpcCore.setPublic16(b); - allGTCastingValues.a32_s = MpcCore.setPublic32(a); - allGTCastingValues.b32_s = MpcCore.setPublic32(b); - allGTCastingValues.a64_s = MpcCore.setPublic64(a); - allGTCastingValues.b64_s = MpcCore.setPublic64(b); + allGTCastingValues.a16_s = MpcCore.setPublic16(a); + allGTCastingValues.b16_s = MpcCore.setPublic16(b); + allGTCastingValues.a32_s = MpcCore.setPublic32(a); + allGTCastingValues.b32_s = MpcCore.setPublic32(b); + allGTCastingValues.a64_s = MpcCore.setPublic64(a); + allGTCastingValues.b64_s = MpcCore.setPublic64(b); // Calculate the expected result - (gtUint8 newA_s, gtUint8 newB_s, gtBool res_s) = MpcCore.transfer( - allGTCastingValues.a8_s, - allGTCastingValues.b8_s, - amount - ); - new_a = MpcCore.decrypt(newA_s); - new_b = MpcCore.decrypt(newB_s); - res = MpcCore.decrypt(res_s); + (gtUint8 newA_s, gtUint8 newB_s, gtBool res_s) = MpcCore.transfer(allGTCastingValues.a8_s, allGTCastingValues.b8_s, amount); + new_a = MpcCore.decrypt(newA_s); + new_b = MpcCore.decrypt(newB_s); + res = MpcCore.decrypt(res_s); // Calculate the result with casting to 16 - computeAndChekTransfer16(allGTCastingValues, new_a, new_b, res, amount); + computeAndCheckTransfer16(allGTCastingValues, new_a, new_b, res, amount); // Calculate the result with casting to 32 - computeAndChekTransfer32(allGTCastingValues, new_a, new_b, res, amount); + computeAndCheckTransfer32(allGTCastingValues, new_a, new_b, res, amount); // Calculate the result with casting to 64 - computeAndChekTransfer64(allGTCastingValues, new_a, new_b, res, amount); + computeAndCheckTransfer64(allGTCastingValues, new_a, new_b, res, amount); return (new_a, new_b, res); } + } diff --git a/contracts/examples/precompiles/PrecompilesTransferTestsContract.sol b/contracts/examples/precompiles/PrecompilesTransferTestsContract.sol index 60a7b8a..2af7cf2 100644 --- a/contracts/examples/precompiles/PrecompilesTransferTestsContract.sol +++ b/contracts/examples/precompiles/PrecompilesTransferTestsContract.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.19; import "../../lib/MpcCore.sol"; contract PrecompilesTransferTestsContract { + struct AllGTCastingValues { gtUint8 a8_s; gtUint8 b8_s; @@ -31,640 +32,184 @@ contract PrecompilesTransferTestsContract { return (newA, newB, result); } - function computeAndChekTransfer16( - AllGTCastingValues memory allGTCastingValues, - AllAmountValues memory allAmountValues, - uint8 new_a, - uint8 new_b, - bool res - ) public { - (gtUint16 newA_s, gtUint16 newB_s, gtBool res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b16_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 16 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a8_s, - allGTCastingValues.b16_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 16 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b8_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 16 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b16_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 16 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a8_s, - allGTCastingValues.b16_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 16 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b8_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 16 failed" - ); + + function computeAndCheckTransfer16(AllGTCastingValues memory allGTCastingValues, AllAmountValues memory allAmountValues, uint8 new_a, uint8 new_b, bool res) public { + (gtUint16 newA_s, gtUint16 newB_s, gtBool res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b16_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a8_s, allGTCastingValues.b16_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b8_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b16_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a8_s, allGTCastingValues.b16_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b8_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed"); } - function computeAndChekTransfer32( - AllGTCastingValues memory allGTCastingValues, - AllAmountValues memory allAmountValues, - uint8 new_a, - uint8 new_b, - bool res - ) public { + function computeAndCheckTransfer32(AllGTCastingValues memory allGTCastingValues, AllAmountValues memory allAmountValues, uint8 new_a, uint8 new_b, bool res) public { + // Check all options for casting to 32 while amount is 32 - (gtUint32 newA_s, gtUint32 newB_s, gtBool res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b32_s, - allAmountValues.amount32_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a8_s, - allGTCastingValues.b32_s, - allAmountValues.amount32_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b8_s, - allAmountValues.amount32_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b32_s, - allAmountValues.amount32_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b16_s, - allAmountValues.amount32_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); + (gtUint32 newA_s, gtUint32 newB_s, gtBool res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b32_s, allAmountValues.amount32_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a8_s, allGTCastingValues.b32_s, allAmountValues.amount32_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b8_s, allAmountValues.amount32_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b32_s, allAmountValues.amount32_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b16_s, allAmountValues.amount32_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + // Check all options for casting to 32 while amount is 8 - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b32_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a8_s, - allGTCastingValues.b32_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b8_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b32_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b16_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b32_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a8_s, allGTCastingValues.b32_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b8_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b32_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b16_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); // Check all options for casting to 32 while amount is 16 - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b32_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a8_s, - allGTCastingValues.b32_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b8_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b32_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b16_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b32_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a8_s, allGTCastingValues.b32_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b8_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b32_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b16_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); } - function computeAndChekTransfer64( - AllGTCastingValues memory allGTCastingValues, - AllAmountValues memory allAmountValues, - uint8 new_a, - uint8 new_b, - bool res - ) public { + function computeAndCheckTransfer64(AllGTCastingValues memory allGTCastingValues, AllAmountValues memory allAmountValues, uint8 new_a, uint8 new_b, bool res) public { + // Check all options for casting to 64 while amount is 64 - (gtUint64 newA_s, gtUint64 newB_s, gtBool res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b64_s, - allAmountValues.amount64_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 64 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a8_s, - allGTCastingValues.b64_s, - allAmountValues.amount64_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 64 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b8_s, - allAmountValues.amount64_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 64 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b64_s, - allAmountValues.amount64_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 64 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b16_s, - allAmountValues.amount64_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 64 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b64_s, - allAmountValues.amount64_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 64 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b32_s, - allAmountValues.amount64_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 64 failed" - ); + (gtUint64 newA_s, gtUint64 newB_s, gtBool res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b64_s, allAmountValues.amount64_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 64 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a8_s, allGTCastingValues.b64_s, allAmountValues.amount64_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 64 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b8_s, allAmountValues.amount64_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 64 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b64_s, allAmountValues.amount64_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 64 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b16_s, allAmountValues.amount64_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 64 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b64_s, allAmountValues.amount64_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 64 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b32_s, allAmountValues.amount64_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 64 failed"); + // Check all options for casting to 64 while amount is 32 - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b64_s, - allAmountValues.amount32_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a8_s, - allGTCastingValues.b64_s, - allAmountValues.amount32_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b8_s, - allAmountValues.amount32_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b64_s, - allAmountValues.amount32_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b16_s, - allAmountValues.amount32_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b64_s, - allAmountValues.amount32_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b32_s, - allAmountValues.amount32_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 32 failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b64_s, allAmountValues.amount32_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a8_s, allGTCastingValues.b64_s, allAmountValues.amount32_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b8_s, allAmountValues.amount32_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b64_s, allAmountValues.amount32_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b16_s, allAmountValues.amount32_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b64_s, allAmountValues.amount32_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b32_s, allAmountValues.amount32_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 32 failed"); + // Check all options for casting to 64 while amount is 8 - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b64_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 8 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a8_s, - allGTCastingValues.b64_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 8 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b8_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 8 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b64_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 8 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b16_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 8 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b64_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 8 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b32_s, - allAmountValues.amount8_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 8 failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b64_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 8 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a8_s, allGTCastingValues.b64_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 8 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b8_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 8 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b64_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 8 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b16_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 8 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b64_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 8 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b32_s, allAmountValues.amount8_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 8 failed"); // Check all options for casting to 64 while amount is 16 - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b64_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 16 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a8_s, - allGTCastingValues.b64_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 16 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b8_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 16 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a16_s, - allGTCastingValues.b64_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 16 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b16_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 16 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a32_s, - allGTCastingValues.b64_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 16 failed" - ); - - (newA_s, newB_s, res_s) = MpcCore.transfer( - allGTCastingValues.a64_s, - allGTCastingValues.b32_s, - allAmountValues.amount16_s - ); - require( - new_a == MpcCore.decrypt(newA_s) && - new_b == MpcCore.decrypt(newB_s) && - res == MpcCore.decrypt(res_s), - "transferTest: cast 16 failed" - ); + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b64_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a8_s, allGTCastingValues.b64_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b8_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b64_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b16_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a32_s, allGTCastingValues.b64_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed"); + + (newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a64_s, allGTCastingValues.b32_s, allAmountValues.amount16_s); + require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed"); } - function transferTest( - uint8 a, - uint8 b, - uint8 amount - ) public returns (uint8, uint8, bool) { + + function transferTest(uint8 a, uint8 b, uint8 amount) public returns (uint8, uint8, bool) { AllGTCastingValues memory allGTCastingValues; AllAmountValues memory allAmountValues; allGTCastingValues.a8_s = MpcCore.setPublic8(a); allGTCastingValues.b8_s = MpcCore.setPublic8(b); - allGTCastingValues.a16_s = MpcCore.setPublic16(a); - allGTCastingValues.b16_s = MpcCore.setPublic16(b); - allGTCastingValues.a32_s = MpcCore.setPublic32(a); - allGTCastingValues.b32_s = MpcCore.setPublic32(b); - allGTCastingValues.a64_s = MpcCore.setPublic64(a); - allGTCastingValues.b64_s = MpcCore.setPublic64(b); + allGTCastingValues.a16_s = MpcCore.setPublic16(a); + allGTCastingValues.b16_s = MpcCore.setPublic16(b); + allGTCastingValues.a32_s = MpcCore.setPublic32(a); + allGTCastingValues.b32_s = MpcCore.setPublic32(b); + allGTCastingValues.a64_s = MpcCore.setPublic64(a); + allGTCastingValues.b64_s = MpcCore.setPublic64(b); allAmountValues.amount8_s = MpcCore.setPublic8(amount); allAmountValues.amount16_s = MpcCore.setPublic16(amount); allAmountValues.amount32_s = MpcCore.setPublic32(amount); @@ -672,42 +217,21 @@ contract PrecompilesTransferTestsContract { allAmountValues.amount = amount; // Calculate the expected result - (gtUint8 newA_s, gtUint8 newB_s, gtBool res_s) = MpcCore.transfer( - allGTCastingValues.a8_s, - allGTCastingValues.b8_s, - allAmountValues.amount8_s - ); + (gtUint8 newA_s, gtUint8 newB_s, gtBool res_s) = MpcCore.transfer(allGTCastingValues.a8_s, allGTCastingValues.b8_s, allAmountValues.amount8_s); newA = MpcCore.decrypt(newA_s); newB = MpcCore.decrypt(newB_s); result = MpcCore.decrypt(res_s); // Calculate the result with casting to 16 - computeAndChekTransfer16( - allGTCastingValues, - allAmountValues, - newA, - newB, - result - ); + computeAndCheckTransfer16(allGTCastingValues, allAmountValues, newA, newB, result); // Calculate the result with casting to 32 - computeAndChekTransfer32( - allGTCastingValues, - allAmountValues, - newA, - newB, - result - ); + computeAndCheckTransfer32(allGTCastingValues, allAmountValues, newA, newB, result); // Calculate the result with casting to 64 - computeAndChekTransfer64( - allGTCastingValues, - allAmountValues, - newA, - newB, - result - ); + computeAndCheckTransfer64(allGTCastingValues, allAmountValues, newA, newB, result); return (newA, newB, result); } + } diff --git a/contracts/lib/MpcCore.sol b/contracts/lib/MpcCore.sol index c9a0f22..0c34b39 100644 --- a/contracts/lib/MpcCore.sol +++ b/contracts/lib/MpcCore.sol @@ -2,60 +2,59 @@ pragma solidity ^0.8.19; -type gtBool is uint256; -type gtUint8 is uint256; -type gtUint16 is uint256; -type gtUint32 is uint256; -type gtUint64 is uint256; - -type ctBool is uint256; -type ctUint8 is uint256; -type ctUint16 is uint256; -type ctUint32 is uint256; -type ctUint64 is uint256; - -struct itBool { - ctBool ciphertext; - bytes signature; -} -struct itUint8 { - ctUint8 ciphertext; - bytes signature; -} -struct itUint16 { - ctUint16 ciphertext; - bytes signature; -} -struct itUint32 { - ctUint32 ciphertext; - bytes signature; -} -struct itUint64 { - ctUint64 ciphertext; - bytes signature; -} + type gtBool is uint256; + type gtUint8 is uint256; + type gtUint16 is uint256; + type gtUint32 is uint256; + type gtUint64 is uint256; -struct utBool { - ctBool ciphertext; - ctBool userCiphertext; -} -struct utUint8 { - ctUint8 ciphertext; - ctUint8 userCiphertext; -} -struct utUint16 { - ctUint16 ciphertext; - ctUint16 userCiphertext; -} -struct utUint32 { - ctUint32 ciphertext; - ctUint32 userCiphertext; -} -struct utUint64 { - ctUint64 ciphertext; - ctUint64 userCiphertext; -} + type ctBool is uint256; + type ctUint8 is uint256; + type ctUint16 is uint256; + type ctUint32 is uint256; + type ctUint64 is uint256; + + struct itBool { + ctBool ciphertext; + bytes signature; + } + struct itUint8 { + ctUint8 ciphertext; + bytes signature; + } + struct itUint16 { + ctUint16 ciphertext; + bytes signature; + } + struct itUint32 { + ctUint32 ciphertext; + bytes signature; + } + struct itUint64 { + ctUint64 ciphertext; + bytes signature; + } + struct utBool { + ctBool ciphertext; + ctBool userCiphertext; + } + struct utUint8 { + ctUint8 ciphertext; + ctUint8 userCiphertext; + } + struct utUint16 { + ctUint16 ciphertext; + ctUint16 userCiphertext; + } + struct utUint32 { + ctUint32 ciphertext; + ctUint32 userCiphertext; + } + struct utUint64 { + ctUint64 ciphertext; + ctUint64 userCiphertext; + } import "./MpcInterface.sol"; @@ -64,6 +63,7 @@ library MpcCore { enum MPC_TYPE {SBOOL_T , SUINT8_T , SUINT16_T, SUINT32_T ,SUINT64_T } enum ARGS {BOTH_SECRET , LHS_PUBLIC, RHS_PUBLIC } + uint public constant RSA_SIZE = 256; function combineEnumsToBytes2(MPC_TYPE mpcType, ARGS argsType) internal pure returns (bytes2) { return bytes2(uint16(mpcType) << 8 | uint8(argsType)); @@ -77,8 +77,48 @@ library MpcCore { return bytes4(uint32(mpcType1) << 24 | uint24(mpcType2) << 16 | uint16(mpcType3) << 8 | uint8(argsType)); } - function getUserKey(bytes calldata signedEK, bytes calldata signature) internal view returns (bytes memory encryptedKey) { - // Combine array from signedEK and signature + function combineEnumsToBytes5(MPC_TYPE mpcType1, MPC_TYPE mpcType2, MPC_TYPE mpcType3, MPC_TYPE mpcType4, ARGS argsType) internal pure returns (bytes5) { + return bytes5(uint40(mpcType1) << 32 | uint32(mpcType2) << 24 | uint24(mpcType3) << 16 | uint16(mpcType4) << 8 | uint8(argsType)); + } + + function checkOverflow(gtBool bit) private { + // revert on overflow + require(decrypt(bit) == false, "overflow error"); + } + + function checkRes8(gtBool bit, gtUint8 res) private returns (gtUint8) { + // revert on overflow + checkOverflow(bit); + + // return the output if there is no overflow + return res; + } + + function checkRes16(gtBool bit, gtUint16 res) private returns (gtUint16) { + // revert on overflow + checkOverflow(bit); + + // return the output if there is no overflow + return res; + } + + function checkRes32(gtBool bit, gtUint32 res) private returns (gtUint32) { + // revert on overflow + checkOverflow(bit); + + // return the output if there is no overflow + return res; + } + + function checkRes64(gtBool bit, gtUint64 res) private returns (gtUint64) { + // revert on overflow + checkOverflow(bit); + + // return the output if there is no overflow + return res; + } + + function getUserKey(bytes calldata signedEK, bytes calldata signature) internal returns (bytes memory keyShare0, bytes memory keyShare1) { bytes memory combined = new bytes(signature.length + signedEK.length); // Copy contents of signature into combined @@ -90,2970 +130,4980 @@ library MpcCore { for (uint j = 0; j < signedEK.length; j++) { combined[signature.length + j] = signedEK[j]; } - return ExtendedOperations(MPC_PRECOMPILE).GetUserKey(combined); + bytes memory bothKeys = ExtendedOperations(address(MPC_PRECOMPILE)).GetUserKey(combined); + bytes memory share0 = new bytes(RSA_SIZE); + bytes memory share1 = new bytes(RSA_SIZE); + + // Copy the first key to the first share array + for (uint i = 0; i < share0.length; i++) { + share0[i] = bothKeys[i]; + } + + // Copy the second key to the second share array + for (uint i = 0; i < share1.length; i++) { + share1[i] = bothKeys[i + RSA_SIZE]; + } + return (share0, share1); + } + + function deleteUserKey(bytes calldata signature) internal{ + ExtendedOperations(address(MPC_PRECOMPILE)).DeleteUserKey(signature); } - + // =========== 1 bit operations ============== function validateCiphertext(itBool memory input) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - ValidateCiphertext(bytes1(uint8(MPC_TYPE.SBOOL_T)), ctBool.unwrap(input.ciphertext), input.signature)); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + ValidateCiphertext(bytes1(uint8(MPC_TYPE.SBOOL_T)), ctBool.unwrap(input.ciphertext), input.signature)); } function onBoard(ctBool ct) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - OnBoard(bytes1(uint8(MPC_TYPE.SBOOL_T)), ctBool.unwrap(ct))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OnBoard(bytes1(uint8(MPC_TYPE.SBOOL_T)), ctBool.unwrap(ct))); } function offBoard(gtBool pt) internal returns (ctBool) { - return ctBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - OffBoard(bytes1(uint8(MPC_TYPE.SBOOL_T)), gtBool.unwrap(pt))); + return ctBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OffBoard(bytes1(uint8(MPC_TYPE.SBOOL_T)), gtBool.unwrap(pt))); } function offBoardToUser(gtBool pt, address addr) internal returns (ctBool) { - return ctBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - OffBoardToUser(bytes1(uint8(MPC_TYPE.SBOOL_T)), gtBool.unwrap(pt), abi.encodePacked(addr))); + return ctBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OffBoardToUser(bytes1(uint8(MPC_TYPE.SBOOL_T)), gtBool.unwrap(pt), abi.encodePacked(addr))); } function offBoardCombined(gtBool pt, address addr) internal returns (utBool memory ut) { ut.ciphertext = offBoard(pt); ut.userCiphertext = offBoardToUser(pt, addr); } - function setPublic(bool pt) internal returns (gtBool) { uint256 temp; - temp = pt ? 1 : 0; - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - SetPublic(bytes1(uint8(MPC_TYPE.SBOOL_T)), temp)); + temp = pt ? 1 : 0; + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + SetPublic(bytes1(uint8(MPC_TYPE.SBOOL_T)), temp)); } function rand() internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE).Rand(bytes1(uint8(MPC_TYPE.SBOOL_T)))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)).Rand(bytes1(uint8(MPC_TYPE.SBOOL_T)))); } function and(gtBool a, gtBool b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SBOOL_T, MPC_TYPE.SBOOL_T, ARGS.BOTH_SECRET), gtBool.unwrap(a), gtBool.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SBOOL_T, MPC_TYPE.SBOOL_T, ARGS.BOTH_SECRET), gtBool.unwrap(a), gtBool.unwrap(b))); } function or(gtBool a, gtBool b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SBOOL_T, MPC_TYPE.SBOOL_T, ARGS.BOTH_SECRET), gtBool.unwrap(a), gtBool.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SBOOL_T, MPC_TYPE.SBOOL_T, ARGS.BOTH_SECRET), gtBool.unwrap(a), gtBool.unwrap(b))); } function xor(gtBool a, gtBool b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SBOOL_T, MPC_TYPE.SBOOL_T, ARGS.BOTH_SECRET), gtBool.unwrap(a), gtBool.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SBOOL_T, MPC_TYPE.SBOOL_T, ARGS.BOTH_SECRET), gtBool.unwrap(a), gtBool.unwrap(b))); } - + function eq(gtBool a, gtBool b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SBOOL_T, MPC_TYPE.SBOOL_T, ARGS.BOTH_SECRET), gtBool.unwrap(a), gtBool.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SBOOL_T, MPC_TYPE.SBOOL_T, ARGS.BOTH_SECRET), gtBool.unwrap(a), gtBool.unwrap(b))); } function ne(gtBool a, gtBool b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SBOOL_T, MPC_TYPE.SBOOL_T, ARGS.BOTH_SECRET), gtBool.unwrap(a), gtBool.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SBOOL_T, MPC_TYPE.SBOOL_T, ARGS.BOTH_SECRET), gtBool.unwrap(a), gtBool.unwrap(b))); } function decrypt(gtBool ct) internal returns (bool){ - uint256 temp = ExtendedOperations(MPC_PRECOMPILE). + uint256 temp = ExtendedOperations(address(MPC_PRECOMPILE)). Decrypt(bytes1(uint8(MPC_TYPE.SBOOL_T)), gtBool.unwrap(ct)); return temp != 0; } function mux(gtBool bit, gtBool a, gtBool b) internal returns (gtBool){ - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SBOOL_T, MPC_TYPE.SBOOL_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtBool.unwrap(a), gtBool.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SBOOL_T, MPC_TYPE.SBOOL_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtBool.unwrap(a), gtBool.unwrap(b))); } function not(gtBool a) internal returns (gtBool){ - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Not(bytes1(uint8(MPC_TYPE.SBOOL_T)), gtBool.unwrap(a))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Not(bytes1(uint8(MPC_TYPE.SBOOL_T)), gtBool.unwrap(a))); } - // =========== Operations with BOTH_SECRET parameter =========== - // =========== 8 bit operations ============== + // =========== Operations with BOTH_SECRET parameter =========== + // =========== 8 bit operations ============== function validateCiphertext(itUint8 memory input) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - ValidateCiphertext(bytes1(uint8(MPC_TYPE.SUINT8_T)), ctUint8.unwrap(input.ciphertext), input.signature)); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + ValidateCiphertext(bytes1(uint8(MPC_TYPE.SUINT8_T)), ctUint8.unwrap(input.ciphertext), input.signature)); } function onBoard(ctUint8 ct) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - OnBoard(bytes1(uint8(MPC_TYPE.SUINT8_T)), ctUint8.unwrap(ct))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OnBoard(bytes1(uint8(MPC_TYPE.SUINT8_T)), ctUint8.unwrap(ct))); } function offBoard(gtUint8 pt) internal returns (ctUint8) { - return ctUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - OffBoard(bytes1(uint8(MPC_TYPE.SUINT8_T)), gtUint8.unwrap(pt))); + return ctUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OffBoard(bytes1(uint8(MPC_TYPE.SUINT8_T)), gtUint8.unwrap(pt))); } function offBoardToUser(gtUint8 pt, address addr) internal returns (ctUint8) { - return ctUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - OffBoardToUser(bytes1(uint8(MPC_TYPE.SUINT8_T)), gtUint8.unwrap(pt), abi.encodePacked(addr))); + return ctUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OffBoardToUser(bytes1(uint8(MPC_TYPE.SUINT8_T)), gtUint8.unwrap(pt), abi.encodePacked(addr))); } function offBoardCombined(gtUint8 pt, address addr) internal returns (utUint8 memory ut) { ut.ciphertext = offBoard(pt); ut.userCiphertext = offBoardToUser(pt, addr); } - function setPublic8(uint8 pt) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - SetPublic(bytes1(uint8(MPC_TYPE.SUINT8_T)), uint256(pt))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + SetPublic(bytes1(uint8(MPC_TYPE.SUINT8_T)), uint256(pt))); } function rand8() internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE).Rand(bytes1(uint8(MPC_TYPE.SUINT8_T)))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)).Rand(bytes1(uint8(MPC_TYPE.SUINT8_T)))); } function randBoundedBits8(uint8 numBits) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE).RandBoundedBits(bytes1(uint8(MPC_TYPE.SUINT8_T)), numBits)); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)).RandBoundedBits(bytes1(uint8(MPC_TYPE.SUINT8_T)), numBits)); } function add(gtUint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + } + + function checkedAdd(gtUint8 a, gtUint8 b) internal returns (gtUint8) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b)); + + return checkRes8(gtBool.wrap(bit), gtUint8.wrap(res)); } function sub(gtUint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + } + + function checkedSub(gtUint8 a, gtUint8 b) internal returns (gtUint8) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b)); + + return checkRes8(gtBool.wrap(bit), gtUint8.wrap(res)); + } + + function mul(gtUint8 a, gtUint8 b) internal returns (gtUint8) { + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } - function mul(gtUint8 a, gtUint8 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + function checkedMul(gtUint8 a, gtUint8 b) internal returns (gtUint8) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b)); + return checkRes8(gtBool.wrap(bit), gtUint8.wrap(res)); } function div(gtUint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } function rem(gtUint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } function and(gtUint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } function or(gtUint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } function xor(gtUint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } function shl(gtUint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } - function shr(gtUint8 a, gtUint8 b) internal returns (gtUint8) { return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } - function eq(gtUint8 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } function ne(gtUint8 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } function ge(gtUint8 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } function gt(gtUint8 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } function le(gtUint8 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } function lt(gtUint8 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } function min(gtUint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } function max(gtUint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b))); } function decrypt(gtUint8 ct) internal returns (uint8){ - return uint8(ExtendedOperations(MPC_PRECOMPILE). - Decrypt(bytes1(uint8(MPC_TYPE.SUINT8_T)), gtUint8.unwrap(ct))); + return uint8(ExtendedOperations(address(MPC_PRECOMPILE)). + Decrypt(bytes1(uint8(MPC_TYPE.SUINT8_T)), gtUint8.unwrap(ct))); } function mux(gtBool bit, gtUint8 a, gtUint8 b) internal returns (gtUint8){ - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint8.unwrap(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint8.unwrap(a), gtUint8.unwrap(b))); } function transfer(gtUint8 a, gtUint8 b, gtUint8 amount) internal returns (gtUint8, gtUint8, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b), gtUint8.unwrap(amount)); return (gtUint8.wrap(new_a), gtUint8.wrap(new_b), gtBool.wrap(res)); } + function transferWithAllowance(gtUint8 a, gtUint8 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint8, gtUint8, gtBool, gtUint8){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint8.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint8.wrap(new_a), gtUint8.wrap(new_b), gtBool.wrap(res), gtUint8.wrap(new_allowance)); + } + - // =========== 16 bit operations ============== + // =========== 16 bit operations ============== function validateCiphertext(itUint16 memory input) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - ValidateCiphertext(bytes1(uint8(MPC_TYPE.SUINT16_T)), ctUint16.unwrap(input.ciphertext), input.signature)); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + ValidateCiphertext(bytes1(uint8(MPC_TYPE.SUINT16_T)), ctUint16.unwrap(input.ciphertext), input.signature)); } function onBoard(ctUint16 ct) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - OnBoard(bytes1(uint8(MPC_TYPE.SUINT16_T)), ctUint16.unwrap(ct))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OnBoard(bytes1(uint8(MPC_TYPE.SUINT16_T)), ctUint16.unwrap(ct))); } function offBoard(gtUint16 pt) internal returns (ctUint16) { - return ctUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - OffBoard(bytes1(uint8(MPC_TYPE.SUINT16_T)), gtUint16.unwrap(pt))); + return ctUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OffBoard(bytes1(uint8(MPC_TYPE.SUINT16_T)), gtUint16.unwrap(pt))); } function offBoardToUser(gtUint16 pt, address addr) internal returns (ctUint16) { - return ctUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - OffBoardToUser(bytes1(uint8(MPC_TYPE.SUINT16_T)), gtUint16.unwrap(pt), abi.encodePacked(addr))); + return ctUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OffBoardToUser(bytes1(uint8(MPC_TYPE.SUINT16_T)), gtUint16.unwrap(pt), abi.encodePacked(addr))); } function offBoardCombined(gtUint16 pt, address addr) internal returns (utUint16 memory ut) { ut.ciphertext = offBoard(pt); ut.userCiphertext = offBoardToUser(pt, addr); } - function setPublic16(uint16 pt) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - SetPublic(bytes1(uint8(MPC_TYPE.SUINT16_T)), uint256(pt))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + SetPublic(bytes1(uint8(MPC_TYPE.SUINT16_T)), uint256(pt))); } function rand16() internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE).Rand(bytes1(uint8(MPC_TYPE.SUINT16_T)))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)).Rand(bytes1(uint8(MPC_TYPE.SUINT16_T)))); } function randBoundedBits16(uint8 numBits) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE).RandBoundedBits(bytes1(uint8(MPC_TYPE.SUINT16_T)), numBits)); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)).RandBoundedBits(bytes1(uint8(MPC_TYPE.SUINT16_T)), numBits)); } function add(gtUint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + } + + function checkedAdd(gtUint16 a, gtUint16 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); } function sub(gtUint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + } + + function checkedSub(gtUint16 a, gtUint16 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); + } + + function mul(gtUint16 a, gtUint16 b) internal returns (gtUint16) { + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } - function mul(gtUint16 a, gtUint16 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + function checkedMul(gtUint16 a, gtUint16 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); } function div(gtUint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } function rem(gtUint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } function and(gtUint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } function or(gtUint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } function xor(gtUint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } function shl(gtUint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } - function shr(gtUint16 a, gtUint16 b) internal returns (gtUint16) { return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } - function eq(gtUint16 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } function ne(gtUint16 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } function ge(gtUint16 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } function gt(gtUint16 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } function le(gtUint16 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } function lt(gtUint16 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } function min(gtUint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } function max(gtUint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b))); } function decrypt(gtUint16 ct) internal returns (uint16){ - return uint16(ExtendedOperations(MPC_PRECOMPILE). - Decrypt(bytes1(uint8(MPC_TYPE.SUINT16_T)), gtUint16.unwrap(ct))); + return uint16(ExtendedOperations(address(MPC_PRECOMPILE)). + Decrypt(bytes1(uint8(MPC_TYPE.SUINT16_T)), gtUint16.unwrap(ct))); } function mux(gtBool bit, gtUint16 a, gtUint16 b) internal returns (gtUint16){ - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint16.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint16.unwrap(a), gtUint16.unwrap(b))); } function transfer(gtUint16 a, gtUint16 b, gtUint16 amount) internal returns (gtUint16, gtUint16, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount)); return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res)); } + function transferWithAllowance(gtUint16 a, gtUint16 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + // =========== 32 bit operations ============== function validateCiphertext(itUint32 memory input) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - ValidateCiphertext(bytes1(uint8(MPC_TYPE.SUINT32_T)), ctUint32.unwrap(input.ciphertext), input.signature)); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + ValidateCiphertext(bytes1(uint8(MPC_TYPE.SUINT32_T)), ctUint32.unwrap(input.ciphertext), input.signature)); } function onBoard(ctUint32 ct) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - OnBoard(bytes1(uint8(MPC_TYPE.SUINT32_T)), ctUint32.unwrap(ct))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OnBoard(bytes1(uint8(MPC_TYPE.SUINT32_T)), ctUint32.unwrap(ct))); } function offBoard(gtUint32 pt) internal returns (ctUint32) { - return ctUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - OffBoard(bytes1(uint8(MPC_TYPE.SUINT32_T)), gtUint32.unwrap(pt))); + return ctUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OffBoard(bytes1(uint8(MPC_TYPE.SUINT32_T)), gtUint32.unwrap(pt))); } function offBoardToUser(gtUint32 pt, address addr) internal returns (ctUint32) { - return ctUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - OffBoardToUser(bytes1(uint8(MPC_TYPE.SUINT32_T)), gtUint32.unwrap(pt), abi.encodePacked(addr))); + return ctUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OffBoardToUser(bytes1(uint8(MPC_TYPE.SUINT32_T)), gtUint32.unwrap(pt), abi.encodePacked(addr))); } - function offBoardCombined(gtUint32 pt, address addr) internal returns (utUint32 memory ut) { ut.ciphertext = offBoard(pt); ut.userCiphertext = offBoardToUser(pt, addr); } function setPublic32(uint32 pt) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - SetPublic(bytes1(uint8(MPC_TYPE.SUINT32_T)), uint256(pt))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + SetPublic(bytes1(uint8(MPC_TYPE.SUINT32_T)), uint256(pt))); } function rand32() internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE).Rand(bytes1(uint8(MPC_TYPE.SUINT32_T)))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)).Rand(bytes1(uint8(MPC_TYPE.SUINT32_T)))); } function randBoundedBits32(uint8 numBits) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE).RandBoundedBits(bytes1(uint8(MPC_TYPE.SUINT32_T)), numBits)); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)).RandBoundedBits(bytes1(uint8(MPC_TYPE.SUINT32_T)), numBits)); } function add(gtUint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + } + + function checkedAdd(gtUint32 a, gtUint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); } function sub(gtUint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + } + + function checkedSub(gtUint32 a, gtUint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); + } + + function mul(gtUint32 a, gtUint32 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } - function mul(gtUint32 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + function checkedMul(gtUint32 a, gtUint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); } function div(gtUint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function rem(gtUint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function and(gtUint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function or(gtUint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function xor(gtUint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function shl(gtUint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } - function shr(gtUint32 a, gtUint32 b) internal returns (gtUint32) { return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function eq(gtUint32 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function ne(gtUint32 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function ge(gtUint32 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function gt(gtUint32 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function le(gtUint32 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function lt(gtUint32 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function min(gtUint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function max(gtUint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function decrypt(gtUint32 ct) internal returns (uint32){ - return uint32(ExtendedOperations(MPC_PRECOMPILE). - Decrypt(bytes1(uint8(MPC_TYPE.SUINT32_T)), gtUint32.unwrap(ct))); + return uint32(ExtendedOperations(address(MPC_PRECOMPILE)). + Decrypt(bytes1(uint8(MPC_TYPE.SUINT32_T)), gtUint32.unwrap(ct))); } function mux(gtBool bit, gtUint32 a, gtUint32 b) internal returns (gtUint32){ - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint32.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint32.unwrap(a), gtUint32.unwrap(b))); } function transfer(gtUint32 a, gtUint32 b, gtUint32 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } + function transferWithAllowance(gtUint32 a, gtUint32 b, gtUint32 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + // =========== 64 bit operations ============== function validateCiphertext(itUint64 memory input) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - ValidateCiphertext(bytes1(uint8(MPC_TYPE.SUINT64_T)), ctUint64.unwrap(input.ciphertext), input.signature)); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + ValidateCiphertext(bytes1(uint8(MPC_TYPE.SUINT64_T)), ctUint64.unwrap(input.ciphertext), input.signature)); } function onBoard(ctUint64 ct) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - OnBoard(bytes1(uint8(MPC_TYPE.SUINT64_T)), ctUint64.unwrap(ct))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OnBoard(bytes1(uint8(MPC_TYPE.SUINT64_T)), ctUint64.unwrap(ct))); } function offBoard(gtUint64 pt) internal returns (ctUint64) { - return ctUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - OffBoard(bytes1(uint8(MPC_TYPE.SUINT64_T)), gtUint64.unwrap(pt))); + return ctUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OffBoard(bytes1(uint8(MPC_TYPE.SUINT64_T)), gtUint64.unwrap(pt))); } function offBoardToUser(gtUint64 pt, address addr) internal returns (ctUint64) { - return ctUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - OffBoardToUser(bytes1(uint8(MPC_TYPE.SUINT64_T)), gtUint64.unwrap(pt), abi.encodePacked(addr))); + return ctUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + OffBoardToUser(bytes1(uint8(MPC_TYPE.SUINT64_T)), gtUint64.unwrap(pt), abi.encodePacked(addr))); } function offBoardCombined(gtUint64 pt, address addr) internal returns (utUint64 memory ut) { ut.ciphertext = offBoard(pt); ut.userCiphertext = offBoardToUser(pt, addr); } - function setPublic64(uint64 pt) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - SetPublic(bytes1(uint8(MPC_TYPE.SUINT64_T)), uint256(pt))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + SetPublic(bytes1(uint8(MPC_TYPE.SUINT64_T)), uint256(pt))); } function rand64() internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE).Rand(bytes1(uint8(MPC_TYPE.SUINT64_T)))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)).Rand(bytes1(uint8(MPC_TYPE.SUINT64_T)))); } function randBoundedBits64(uint8 numBits) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE).RandBoundedBits(bytes1(uint8(MPC_TYPE.SUINT64_T)), numBits)); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)).RandBoundedBits(bytes1(uint8(MPC_TYPE.SUINT64_T)), numBits)); } function add(gtUint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + } + + function checkedAdd(gtUint64 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function sub(gtUint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + } + + function checkedSub(gtUint64 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function mul(gtUint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + } + + function checkedMul(gtUint64 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function div(gtUint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function rem(gtUint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function and(gtUint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function or(gtUint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function xor(gtUint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function shl(gtUint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function shr(gtUint64 a, gtUint64 b) internal returns (gtUint64) { return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } - function eq(gtUint64 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function ne(gtUint64 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function ge(gtUint64 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function gt(gtUint64 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function le(gtUint64 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function lt(gtUint64 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function min(gtUint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function max(gtUint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function decrypt(gtUint64 ct) internal returns (uint64){ - return uint64(ExtendedOperations(MPC_PRECOMPILE). - Decrypt(bytes1(uint8(MPC_TYPE.SUINT64_T)), gtUint64.unwrap(ct))); + return uint64(ExtendedOperations(address(MPC_PRECOMPILE)). + Decrypt(bytes1(uint8(MPC_TYPE.SUINT64_T)), gtUint64.unwrap(ct))); } function mux(gtBool bit, gtUint64 a, gtUint64 b) internal returns (gtUint64){ - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint64.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint64.unwrap(a), gtUint64.unwrap(b))); } function transfer(gtUint64 a, gtUint64 b, gtUint64 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ - (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(MPC_PRECOMPILE). - TransferWithAllowance(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint64.unwrap(allowance)); + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint64.unwrap(allowance)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function transferWithAllowance(gtUint64 a, gtUint64 b, uint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ - (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(MPC_PRECOMPILE). - TransferWithAllowance(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint64.unwrap(allowance)); - return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); - } // =========== Operations with LHS_PUBLIC parameter =========== - // =========== 8 bit operations ============== + // =========== 8 bit operations ============== function add(uint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + } + + function checkedAdd(uint8 a, gtUint8 b) internal returns (gtUint8) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b)); + + return checkRes8(gtBool.wrap(bit), gtUint8.wrap(res)); } function sub(uint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + } + + function checkedSub(uint8 a, gtUint8 b) internal returns (gtUint8) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b)); + + return checkRes8(gtBool.wrap(bit), gtUint8.wrap(res)); + } + + function mul(uint8 a, gtUint8 b) internal returns (gtUint8) { + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } - function mul(uint8 a, gtUint8 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + function checkedMul(uint8 a, gtUint8 b) internal returns (gtUint8) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b)); + + return checkRes8(gtBool.wrap(bit), gtUint8.wrap(res)); } function div(uint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } function rem(uint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } function and(uint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } function or(uint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } function xor(uint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } function shl(uint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } - function shr(uint8 a, gtUint8 b) internal returns (gtUint8) { return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } - function eq(uint8 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } function ne(uint8 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } function ge(uint8 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } function gt(uint8 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } function le(uint8 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } function lt(uint8 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } function min(uint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); } function max(uint8 a, gtUint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), uint256(a), gtUint8.unwrap(b))); + } + + function mux(gtBool bit, uint8 a, gtUint8 b) internal returns (gtUint8){ + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtBool.unwrap(bit), uint256(a), gtUint8.unwrap(b))); } - // =========== 16 bit operations ============== + // =========== 16 bit operations ============== function add(uint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + } + + function checkedAdd(uint16 a, gtUint16 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); } function sub(uint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + } + + function checkedSub(uint16 a, gtUint16 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); } - function mul(uint16 a, gtUint16 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + function mul(uint16 a, gtUint16 b) internal returns (gtUint16) { + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + } + + function checkedMul(uint16 a, gtUint16 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); } function div(uint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); } function rem(uint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); } function and(uint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); } function or(uint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); } function xor(uint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); } function shl(uint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); } - function shr(uint16 a, gtUint16 b) internal returns (gtUint16) { return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); } - function eq(uint16 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); } function ne(uint16 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); } function ge(uint16 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); } function gt(uint16 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); } function le(uint16 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); } function lt(uint16 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); } function min(uint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); } function max(uint16 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), uint256(a), gtUint16.unwrap(b))); + } + + function mux(gtBool bit, uint16 a, gtUint16 b) internal returns (gtUint16){ + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtBool.unwrap(bit), uint256(a), gtUint16.unwrap(b))); } // =========== 32 bit operations ============== function add(uint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + } + + function checkedAdd(uint32 a, gtUint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); } function sub(uint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + } + + function checkedSub(uint32 a, gtUint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); + } + + function mul(uint32 a, gtUint32 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } - function mul(uint32 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + function checkedMul(uint32 a, gtUint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); } function div(uint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } function rem(uint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } function and(uint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } function or(uint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } function xor(uint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } function shl(uint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } - function shr(uint32 a, gtUint32 b) internal returns (gtUint32) { return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } - function eq(uint32 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } function ne(uint32 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } function ge(uint32 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } function gt(uint32 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } function le(uint32 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } function lt(uint32 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } function min(uint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); } function max(uint32 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), uint256(a), gtUint32.unwrap(b))); + } + + function mux(gtBool bit, uint32 a, gtUint32 b) internal returns (gtUint32){ + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtBool.unwrap(bit), uint256(a), gtUint32.unwrap(b))); } // =========== 64 bit operations ============== function add(uint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + } + + function checkedAdd(uint64 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function sub(uint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + } + + function checkedSub(uint64 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function mul(uint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + } + + function checkedMul(uint64 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function div(uint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); } function rem(uint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); } function and(uint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); } function or(uint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); } function xor(uint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); } function shl(uint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); } - function shr(uint64 a, gtUint64 b) internal returns (gtUint64) { return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); } - function eq(uint64 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); } function ne(uint64 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); } function ge(uint64 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); } function gt(uint64 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); } function le(uint64 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); } function lt(uint64 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); } function min(uint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); } function max(uint64 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), uint256(a), gtUint64.unwrap(b))); + } + + function mux(gtBool bit, uint64 a, gtUint64 b) internal returns (gtUint64){ + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtBool.unwrap(bit), uint256(a), gtUint64.unwrap(b))); } - - // =========== Operations with RHS_PUBLIC parameter =========== - // =========== 8 bit operations ============== + + // =========== Operations with RHS_PUBLIC parameter =========== + // =========== 8 bit operations ============== function add(gtUint8 a, uint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + } + + function checkedAdd(gtUint8 a, uint8 b) internal returns (gtUint8) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b)); + + return checkRes8(gtBool.wrap(bit), gtUint8.wrap(res)); } function sub(gtUint8 a, uint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } - function mul(gtUint8 a, uint8 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + function checkedSub(gtUint8 a, uint8 b) internal returns (gtUint8) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b)); + + return checkRes8(gtBool.wrap(bit), gtUint8.wrap(res)); + } + + function mul(gtUint8 a, uint8 b) internal returns (gtUint8) { + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + } + + function checkedMul(gtUint8 a, uint8 b) internal returns (gtUint8) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b)); + + return checkRes8(gtBool.wrap(bit), gtUint8.wrap(res)); } function div(gtUint8 a, uint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } function rem(gtUint8 a, uint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } function and(gtUint8 a, uint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } function or(gtUint8 a, uint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } function xor(gtUint8 a, uint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } function shl(gtUint8 a, uint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } function shr(gtUint8 a, uint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } function eq(gtUint8 a, uint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } function ne(gtUint8 a, uint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } - + function ge(gtUint8 a, uint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } function gt(gtUint8 a, uint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } function le(gtUint8 a, uint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } function lt(gtUint8 a, uint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } function min(gtUint8 a, uint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); } function max(gtUint8 a, uint8 b) internal returns (gtUint8) { - return gtUint8.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint8.unwrap(a), uint256(b))); + } + + function mux(gtBool bit, gtUint8 a, uint8 b) internal returns (gtUint8){ + return gtUint8.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtBool.unwrap(bit), gtUint8.unwrap(a), uint256(b))); } - // =========== 16 bit operations ============== + // =========== 16 bit operations ============== function add(gtUint16 a, uint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + } + + function checkedAdd(gtUint16 a, uint16 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); } function sub(gtUint16 a, uint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + } + + function checkedSub(gtUint16 a, uint16 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); } - function mul(gtUint16 a, uint16 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + function mul(gtUint16 a, uint16 b) internal returns (gtUint16) { + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + } + + function checkedMul(gtUint16 a, uint16 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); } function div(gtUint16 a, uint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); } function rem(gtUint16 a, uint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); } function and(gtUint16 a, uint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); } function or(gtUint16 a, uint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); } function xor(gtUint16 a, uint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); } - function shl(gtUint16 a, uint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + function shl(gtUint16 a, uint8 b) internal returns (gtUint16) { + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); } - function shr(gtUint16 a, uint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + function shr(gtUint16 a, uint8 b) internal returns (gtUint16) { + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); } function eq(gtUint16 a, uint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); } function ne(gtUint16 a, uint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); } function ge(gtUint16 a, uint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); } function gt(gtUint16 a, uint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); } function le(gtUint16 a, uint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); } function lt(gtUint16 a, uint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); } function min(gtUint16 a, uint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); } function max(gtUint16 a, uint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtUint16.unwrap(a), uint256(b))); + } + + function mux(gtBool bit, gtUint16 a, uint16 b) internal returns (gtUint16){ + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.RHS_PUBLIC), gtBool.unwrap(bit), gtUint16.unwrap(a), uint256(b))); } // =========== 32 bit operations ============== function add(gtUint32 a, uint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + } + + function checkedAdd(gtUint32 a, uint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); } function sub(gtUint32 a, uint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + } + + function checkedSub(gtUint32 a, uint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); } - function mul(gtUint32 a, uint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + function mul(gtUint32 a, uint32 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + } + + function checkedMul(gtUint32 a, uint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); } function div(gtUint32 a, uint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } function rem(gtUint32 a, uint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } function and(gtUint32 a, uint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } function or(gtUint32 a, uint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } function xor(gtUint32 a, uint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } function shl(gtUint32 a, uint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } function shr(gtUint32 a, uint32 b) internal returns (gtUint32) { return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } function eq(gtUint32 a, uint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } function ne(gtUint32 a, uint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } function ge(gtUint32 a, uint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } function gt(gtUint32 a, uint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } function le(gtUint32 a, uint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } function lt(gtUint32 a, uint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } function min(gtUint32 a, uint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } function max(gtUint32 a, uint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtUint32.unwrap(a), uint256(b))); } + function mux(gtBool bit, gtUint32 a, uint32 b) internal returns (gtUint32){ + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.RHS_PUBLIC), gtBool.unwrap(bit), gtUint32.unwrap(a), uint256(b))); + } // =========== 64 bit operations ============== function add(gtUint64 a, uint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + } + + function checkedAdd(gtUint64 a, uint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function sub(gtUint64 a, uint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + } + + function checkedSub(gtUint64 a, uint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function mul(gtUint64 a, uint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + } + + function checkedMul(gtUint64 a, uint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function div(gtUint64 a, uint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); } function rem(gtUint64 a, uint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); } function and(gtUint64 a, uint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); } function or(gtUint64 a, uint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); } function xor(gtUint64 a, uint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); } function shl(gtUint64 a, uint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); } function shr(gtUint64 a, uint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); } function eq(gtUint64 a, uint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); } function ne(gtUint64 a, uint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); } function ge(gtUint64 a, uint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); } function gt(gtUint64 a, uint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); } function le(gtUint64 a, uint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); } function lt(gtUint64 a, uint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); } function min(gtUint64 a, uint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); } function max(gtUint64 a, uint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtUint64.unwrap(a), uint256(b))); + } + + function mux(gtBool bit, gtUint64 a, uint64 b) internal returns (gtUint64){ + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.RHS_PUBLIC), gtBool.unwrap(bit), gtUint64.unwrap(a), uint256(b))); } // In the context of a transfer, scalar balances are irrelevant; - // The only possibility for a scalar value is within the "amount" parameter. - // Therefore, in this scenario, LHS_PUBLIC signifies a scalar amount, not balance1. + // The only possibility for a scalar value is within the "amount" parameter. + // Therefore, in this scenario, LHS_PUBLIC signifies a scalar amount, not balance1. function transfer(gtUint8 a, gtUint8 b, uint8 amount) internal returns (gtUint8, gtUint8, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint8.unwrap(a), gtUint8.unwrap(b), uint256(amount)); return (gtUint8.wrap(new_a), gtUint8.wrap(new_b), gtBool.wrap(res)); } - + function transfer(gtUint16 a, gtUint16 b, uint16 amount) internal returns (gtUint16, gtUint16, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint16.unwrap(b), uint256(amount)); return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint8 a, gtUint16 b, uint16 amount) internal returns (gtUint16, gtUint16, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint8.unwrap(a), gtUint16.unwrap(b), uint256(amount)); return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint16 a, gtUint8 b, uint16 amount) internal returns (gtUint16, gtUint16, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint8.unwrap(b), uint256(amount)); return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint32 b, uint32 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint32.unwrap(b), uint256(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint8 a, gtUint32 b, uint32 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint8.unwrap(a), gtUint32.unwrap(b), uint256(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint8 b, uint32 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint8.unwrap(b), uint256(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint16 a, gtUint32 b, uint32 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint32.unwrap(b), uint256(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint16 b, uint32 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint16.unwrap(b), uint256(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint64 b, uint64 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint64.unwrap(b), uint256(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint8 a, gtUint64 b, uint64 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint8.unwrap(a), gtUint64.unwrap(b), uint256(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint8 b, uint64 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint8.unwrap(b), uint256(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint16 a, gtUint64 b, uint64 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint64.unwrap(b), uint256(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint16 b, uint64 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint16.unwrap(b), uint256(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint64 b, uint64 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint64.unwrap(b), uint256(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint32 b, uint64 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint32.unwrap(b), uint256(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } - - + function transferWithAllowance(gtUint8 a, gtUint8 b, uint8 amount, gtUint8 allowance) internal returns (gtUint8, gtUint8, gtBool, gtUint8){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint8.unwrap(a), gtUint8.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint8.wrap(new_a), gtUint8.wrap(new_b), gtBool.wrap(res), gtUint8.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint16 b, uint16 amount, gtUint16 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint16.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint8 a, gtUint16 b, uint16 amount, gtUint16 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint8.unwrap(a), gtUint16.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint8 b, uint16 amount, gtUint16 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint8.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + // Allowance with 8 bits + function transferWithAllowance(gtUint16 a, gtUint16 b, uint16 amount, gtUint8 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint16.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint8 a, gtUint16 b, uint16 amount, gtUint8 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint8.unwrap(a), gtUint16.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint8 b, uint16 amount, gtUint8 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint8.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint32 b, uint32 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint32.unwrap(b), uint256(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint8 a, gtUint32 b, uint32 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint8.unwrap(a), gtUint32.unwrap(b), uint256(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint8 b, uint32 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint8.unwrap(b), uint256(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint32 b, uint32 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint32.unwrap(b), uint256(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint16 b, uint32 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint16.unwrap(b), uint256(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + // Allowance with 8 bits + function transferWithAllowance(gtUint32 a, gtUint32 b, uint32 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint32.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint8 a, gtUint32 b, uint32 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint8.unwrap(a), gtUint32.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint8 b, uint32 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint8.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint32 b, uint32 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint32.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint16 b, uint32 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint16.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + // Allowance with 16 bits + function transferWithAllowance(gtUint32 a, gtUint32 b, uint32 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint32.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint8 a, gtUint32 b, uint32 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint8.unwrap(a), gtUint32.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint8 b, uint32 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint8.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint32 b, uint32 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint32.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint16 b, uint32 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint16.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint64 b, uint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint8 a, gtUint64 b, uint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint8.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint8 b, uint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint8.unwrap(b), uint256(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, uint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, uint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint16.unwrap(b), uint256(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, uint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, uint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint32.unwrap(b), uint256(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + // Allowance with 8 bits + function transferWithAllowance(gtUint64 a, gtUint64 b, uint64 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint8 a, gtUint64 b, uint64 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint8.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint8 b, uint64 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint8.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, uint64 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, uint64 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint16.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, uint64 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, uint64 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint32.unwrap(b), uint256(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + // Allowance with 16 bits + function transferWithAllowance(gtUint64 a, gtUint64 b, uint64 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint8 a, gtUint64 b, uint64 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint8.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint8 b, uint64 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint8.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, uint64 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, uint64 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint16.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, uint64 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, uint64 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint32.unwrap(b), uint256(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + // Allowance with 32 bits + function transferWithAllowance(gtUint64 a, gtUint64 b, uint64 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint8 a, gtUint64 b, uint64 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint8.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint8 b, uint64 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint8.unwrap(b), uint256(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, uint64 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint16.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, uint64 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint16.unwrap(b), uint256(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, uint64 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint32.unwrap(a), gtUint64.unwrap(b), uint256(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, uint64 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.LHS_PUBLIC), gtUint64.unwrap(a), gtUint32.unwrap(b), uint256(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + - // ================= Cast operation ================= - // =========== 8 - 16 bit operations ============== + // ================= Cast operation ================= + // =========== 8 - 16 bit operations ============== function add(gtUint8 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function add(gtUint16 a, gtUint8 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + } + + function checkedAdd(gtUint8 a, gtUint16 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); + } + + function checkedAdd(gtUint16 a, gtUint8 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); } function sub(gtUint8 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function sub(gtUint16 a, gtUint8 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + } + + function checkedSub(gtUint8 a, gtUint16 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); + } + + function checkedSub(gtUint16 a, gtUint8 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); + } + + function mul(gtUint8 a, gtUint16 b) internal returns (gtUint16) { + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + } + + function mul(gtUint16 a, gtUint8 b) internal returns (gtUint16) { + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } - function mul(gtUint8 a, gtUint16 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + function checkedMul(gtUint8 a, gtUint16 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); } - function mul(gtUint16 a, gtUint8 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + function checkedMul(gtUint16 a, gtUint8 b) internal returns (gtUint16) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b)); + + return checkRes16(gtBool.wrap(bit), gtUint16.wrap(res)); } function div(gtUint8 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function div(gtUint16 a, gtUint8 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function rem(gtUint8 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function rem(gtUint16 a, gtUint8 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function and(gtUint8 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function and(gtUint16 a, gtUint8 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function or(gtUint8 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function or(gtUint16 a, gtUint8 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function xor(gtUint8 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function xor(gtUint16 a, gtUint8 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function shl(gtUint8 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } - function shl(gtUint16 a, gtUint8 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } - function shr(gtUint8 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function shr(gtUint16 a, gtUint8 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function eq(gtUint8 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function eq(gtUint16 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function ne(gtUint8 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function ne(gtUint16 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function ge(gtUint8 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function ge(gtUint16 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function gt(gtUint8 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function gt(gtUint16 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function le(gtUint8 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } - function le(gtUint16 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + function le(gtUint16 a, gtUint8 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function lt(gtUint8 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function lt(gtUint16 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function min(gtUint8 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function min(gtUint16 a, gtUint8 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function max(gtUint8 a, gtUint16 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function max(gtUint16 a, gtUint8 b) internal returns (gtUint16) { - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function mux(gtBool bit, gtUint8 a, gtUint16 b) internal returns (gtUint16){ - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint8.unwrap(a), gtUint16.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint8.unwrap(a), gtUint16.unwrap(b))); } function mux(gtBool bit, gtUint16 a, gtUint8 b) internal returns (gtUint16){ - return gtUint16.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint16.unwrap(a), gtUint8.unwrap(b))); + return gtUint16.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint16.unwrap(a), gtUint8.unwrap(b))); } function transfer(gtUint8 a, gtUint16 b, gtUint16 amount) internal returns (gtUint16, gtUint16, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount)); return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint16 a, gtUint8 b, gtUint16 amount) internal returns (gtUint16, gtUint16, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b), gtUint16.unwrap(amount)); return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint8 a, gtUint16 b, gtUint8 amount) internal returns (gtUint16, gtUint16, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount)); return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint16 a, gtUint8 b, gtUint8 amount) internal returns (gtUint16, gtUint16, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b), gtUint8.unwrap(amount)); return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint16 a, gtUint16 b, gtUint8 amount) internal returns (gtUint16, gtUint16, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount)); return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res)); } + function transferWithAllowance(gtUint16 a, gtUint8 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint8 a, gtUint16 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint8 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint8.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint8 a, gtUint16 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint16 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint16 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + // Allowance with 16 bit + + function transferWithAllowance(gtUint16 a, gtUint8 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint8.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint8 a, gtUint16 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint8 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint8.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint8 a, gtUint16 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint16 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint16, gtUint16, gtBool, gtUint16){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint16.wrap(new_a), gtUint16.wrap(new_b), gtBool.wrap(res), gtUint16.wrap(new_allowance)); + } + // =========== 8- 32 bit operations ============== function add(gtUint8 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function add(gtUint32 a, gtUint8 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + } + + function checkedAdd(gtUint8 a, gtUint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); + } + + function checkedAdd(gtUint32 a, gtUint8 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); } function sub(gtUint8 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function sub(gtUint32 a, gtUint8 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + } + + function checkedSub(gtUint8 a, gtUint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); } - function mul(gtUint8 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + function checkedSub(gtUint32 a, gtUint8 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); + } + + function mul(gtUint8 a, gtUint32 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + } + + function mul(gtUint32 a, gtUint8 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + } + + function checkedMul(gtUint8 a, gtUint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); } - function mul(gtUint32 a, gtUint8 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + function checkedMul(gtUint32 a, gtUint8 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); } function div(gtUint8 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function div(gtUint32 a, gtUint8 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function rem(gtUint8 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function rem(gtUint32 a, gtUint8 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function and(gtUint8 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function and(gtUint32 a, gtUint8 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function or(gtUint8 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function or(gtUint32 a, gtUint8 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function xor(gtUint8 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function xor(gtUint32 a, gtUint8 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function shl(gtUint8 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } - function shl(gtUint32 a, gtUint8 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } - function shr(gtUint8 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function shr(gtUint32 a, gtUint8 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function eq(gtUint8 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function eq(gtUint32 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function ne(gtUint8 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function ne(gtUint32 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function ge(gtUint8 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function ge(gtUint32 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function gt(gtUint8 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function gt(gtUint32 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function le(gtUint8 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function le(gtUint32 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function lt(gtUint8 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function lt(gtUint32 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function min(gtUint8 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function min(gtUint32 a, gtUint8 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function max(gtUint8 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b))); } - function max(gtUint32 a, gtUint8 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); + function max(gtUint32 a, gtUint8 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function mux(gtBool bit, gtUint8 a, gtUint32 b) internal returns (gtUint32){ - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint8.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint8.unwrap(a), gtUint32.unwrap(b))); } function mux(gtBool bit, gtUint32 a, gtUint8 b) internal returns (gtUint32){ - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint32.unwrap(a), gtUint8.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint32.unwrap(a), gtUint8.unwrap(b))); } function transfer(gtUint8 a, gtUint32 b, gtUint32 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint8 b, gtUint32 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b), gtUint32.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint8 a, gtUint32 b, gtUint8 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint8 b, gtUint8 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b), gtUint8.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint8 a, gtUint32 b, gtUint16 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint8 b, gtUint16 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b), gtUint16.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint32 b, gtUint8 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } - - // =========== 16 - 32 bit operations ============== - - function add(gtUint16 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + function transferWithAllowance(gtUint32 a, gtUint8 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function add(gtUint32 a, gtUint16 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint32 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function sub(gtUint16 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + function transferWithAllowance(gtUint32 a, gtUint8 b, gtUint32 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b), gtUint32.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function sub(gtUint32 a, gtUint16 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint32 b, gtUint32 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function mul(gtUint16 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + function transferWithAllowance(gtUint32 a, gtUint32 b, gtUint32 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function mul(gtUint32 a, gtUint16 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint32 a, gtUint8 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint8.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function div(gtUint16 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint32 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function div(gtUint32 a, gtUint16 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint32 a, gtUint32 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function rem(gtUint16 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + // Allowance with 16 bit + function transferWithAllowance(gtUint32 a, gtUint8 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint8.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function rem(gtUint32 a, gtUint16 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint32 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function and(gtUint16 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + function transferWithAllowance(gtUint32 a, gtUint8 b, gtUint32 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint8.unwrap(b), gtUint32.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function and(gtUint32 a, gtUint16 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint32 b, gtUint32 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function or(gtUint16 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + function transferWithAllowance(gtUint32 a, gtUint8 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint8.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function or(gtUint32 a, gtUint16 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint32 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function xor(gtUint16 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + function transferWithAllowance(gtUint32 a, gtUint32 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function xor(gtUint32 a, gtUint16 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + // Allowance with 32 bit + function transferWithAllowance(gtUint32 a, gtUint8 b, gtUint8 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint8.unwrap(b), gtUint8.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function shl(gtUint16 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint32 b, gtUint8 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function shl(gtUint32 a, gtUint16 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint32 a, gtUint8 b, gtUint32 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint8.unwrap(b), gtUint32.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function shr(gtUint16 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint32 b, gtUint32 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function shr(gtUint32 a, gtUint16 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint32 a, gtUint8 b, gtUint16 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint8.unwrap(b), gtUint16.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function eq(gtUint16 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint32 b, gtUint16 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function eq(gtUint32 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint32 a, gtUint32 b, gtUint8 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); } - function ne(gtUint16 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + // =========== 16 - 32 bit operations ============== + + function add(gtUint16 a, gtUint32 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); } - function ne(gtUint32 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + function add(gtUint32 a, gtUint16 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + } + + function checkedAdd(gtUint16 a, gtUint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); + } + + function checkedAdd(gtUint32 a, gtUint16 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); + } + + function sub(gtUint16 a, gtUint32 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + } + + function sub(gtUint32 a, gtUint16 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + } + + function checkedSub(gtUint16 a, gtUint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); + } + + function checkedSub(gtUint32 a, gtUint16 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); + } + + function mul(gtUint16 a, gtUint32 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + } + + function mul(gtUint32 a, gtUint16 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + } + + function checkedMul(gtUint16 a, gtUint32 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); + } + + function checkedMul(gtUint32 a, gtUint16 b) internal returns (gtUint32) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b)); + + return checkRes32(gtBool.wrap(bit), gtUint32.wrap(res)); + } + + function div(gtUint16 a, gtUint32 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + } + + function div(gtUint32 a, gtUint16 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + } + + function rem(gtUint16 a, gtUint32 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + } + + function rem(gtUint32 a, gtUint16 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + } + + function and(gtUint16 a, gtUint32 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + } + + function and(gtUint32 a, gtUint16 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + } + + function or(gtUint16 a, gtUint32 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + } + + function or(gtUint32 a, gtUint16 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + } + + function xor(gtUint16 a, gtUint32 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + } + + function xor(gtUint32 a, gtUint16 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + } + + function shl(gtUint16 a, gtUint32 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + } + function shl(gtUint32 a, gtUint16 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + } + function shr(gtUint16 a, gtUint32 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + } + + function shr(gtUint32 a, gtUint16 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + } + + function eq(gtUint16 a, gtUint32 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + } + + function eq(gtUint32 a, gtUint16 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + } + + function ne(gtUint16 a, gtUint32 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + } + + function ne(gtUint32 a, gtUint16 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); } function ge(gtUint16 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); } function ge(gtUint32 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); } function gt(gtUint16 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); } function gt(gtUint32 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); } function le(gtUint16 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); } function le(gtUint32 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); } function lt(gtUint16 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); } function lt(gtUint32 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); } function min(gtUint16 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); } function min(gtUint32 a, gtUint16 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); } function max(gtUint16 a, gtUint32 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b))); } - function max(gtUint32 a, gtUint16 b) internal returns (gtUint32) { - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); + function max(gtUint32 a, gtUint16 b) internal returns (gtUint32) { + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b))); } function mux(gtBool bit, gtUint16 a, gtUint32 b) internal returns (gtUint32){ - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint16.unwrap(a), gtUint32.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint16.unwrap(a), gtUint32.unwrap(b))); } function mux(gtBool bit, gtUint32 a, gtUint16 b) internal returns (gtUint32){ - return gtUint32.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint32.unwrap(a), gtUint16.unwrap(b))); + return gtUint32.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint32.unwrap(a), gtUint16.unwrap(b))); } function transfer(gtUint16 a, gtUint32 b, gtUint32 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint16 b, gtUint32 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b), gtUint32.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint16 a, gtUint32 b, gtUint8 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint16 b, gtUint8 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint16 a, gtUint32 b, gtUint16 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint16 b, gtUint16 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint32 b, gtUint16 amount) internal returns (gtUint32, gtUint32, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount)); return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res)); } + function transferWithAllowance(gtUint16 a, gtUint32 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint16 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint32 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint16 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint32 b, gtUint32 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint16 b, gtUint32 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint16.unwrap(b), gtUint32.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint32 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + // Allowance with 16 bit + function transferWithAllowance(gtUint16 a, gtUint32 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint16 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint32 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint16 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint32 b, gtUint32 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint16 b, gtUint32 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint16.unwrap(b), gtUint32.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint32 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint32 b, gtUint32 amount, gtUint16 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + // Allowance with 32 bit + function transferWithAllowance(gtUint16 a, gtUint32 b, gtUint8 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint16 b, gtUint8 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint32 b, gtUint16 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint16 b, gtUint16 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint32 b, gtUint32 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint16 b, gtUint32 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint16.unwrap(b), gtUint32.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint32 b, gtUint16 amount, gtUint32 allowance) internal returns (gtUint32, gtUint32, gtBool, gtUint32){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint32.wrap(new_a), gtUint32.wrap(new_b), gtBool.wrap(res), gtUint32.wrap(new_allowance)); + } + // =========== 8 - 64 bit operations ============== - + function add(gtUint8 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function add(gtUint64 a, gtUint8 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + } + + function checkedAdd(gtUint8 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); + } + + function checkedAdd(gtUint64 a, gtUint8 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function sub(gtUint8 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function sub(gtUint64 a, gtUint8 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + } + + function checkedSub(gtUint8 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); + } + + function checkedSub(gtUint64 a, gtUint8 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function mul(gtUint8 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function mul(gtUint64 a, gtUint8 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + } + + function checkedMul(gtUint8 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); + } + + function checkedMul(gtUint64 a, gtUint8 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function div(gtUint8 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function div(gtUint64 a, gtUint8 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function rem(gtUint8 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function rem(gtUint64 a, gtUint8 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function and(gtUint8 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function and(gtUint64 a, gtUint8 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function or(gtUint8 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function or(gtUint64 a, gtUint8 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function xor(gtUint8 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function xor(gtUint64 a, gtUint8 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function shl(gtUint8 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } - function shl(gtUint64 a, gtUint8 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } - function shr(gtUint8 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function shr(gtUint64 a, gtUint8 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function eq(gtUint8 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function eq(gtUint64 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function ne(gtUint8 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function ne(gtUint64 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function ge(gtUint8 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function ge(gtUint64 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function gt(gtUint8 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } - + function gt(gtUint64 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function le(gtUint8 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } - + function le(gtUint64 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function lt(gtUint8 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function lt(gtUint64 a, gtUint8 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function min(gtUint8 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function min(gtUint64 a, gtUint8 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function max(gtUint8 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b))); } - function max(gtUint64 a, gtUint8 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); + function max(gtUint64 a, gtUint8 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function mux(gtBool bit, gtUint8 a, gtUint64 b) internal returns (gtUint64){ - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint8.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint8.unwrap(a), gtUint64.unwrap(b))); } function mux(gtBool bit, gtUint64 a, gtUint8 b) internal returns (gtUint64){ - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint64.unwrap(a), gtUint8.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint64.unwrap(a), gtUint8.unwrap(b))); } function transfer(gtUint8 a, gtUint64 b, gtUint64 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint8 b, gtUint64 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint64.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint8 a, gtUint64 b, gtUint8 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint8 b, gtUint8 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint8.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint8 a, gtUint64 b, gtUint16 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint8 b, gtUint16 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint16.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } - function transfer(gtUint8 a, gtUint64 b, gtUint32 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + function transfer(gtUint8 a, gtUint64 b, gtUint32 amount) internal returns (gtUint64, gtUint64, gtBool){ + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint8 b, gtUint32 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint32.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint64 b, gtUint8 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } - // =========== 16 - 64 bit operations ============== - - function add(gtUint16 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function add(gtUint64 a, gtUint16 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function sub(gtUint16 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function sub(gtUint64 a, gtUint16 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function mul(gtUint16 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint32 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function mul(gtUint64 a, gtUint16 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint32 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint32.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function div(gtUint16 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint64 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function div(gtUint64 a, gtUint16 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint64 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint64.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function rem(gtUint16 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function rem(gtUint64 a, gtUint16 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint64 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function and(gtUint16 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + // Allowance with 16 bit + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function and(gtUint64 a, gtUint16 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function or(gtUint16 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function or(gtUint64 a, gtUint16 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function xor(gtUint16 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint32 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function xor(gtUint64 a, gtUint16 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint32 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint32.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function shl(gtUint16 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint64 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function shl(gtUint64 a, gtUint16 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint64 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint64.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function shr(gtUint16 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function shr(gtUint64 a, gtUint16 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint64 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function eq(gtUint16 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + // Allowance with 32 bit + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint8 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function eq(gtUint64 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint8 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint8.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function ne(gtUint16 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint16 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function ne(gtUint64 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint16 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint16.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function ge(gtUint16 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint32 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function ge(gtUint64 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint32 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint32.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function gt(gtUint16 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); - } - - function gt(gtUint64 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint64 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function le(gtUint16 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint64 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint64.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - - function le(gtUint64 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint8 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function lt(gtUint16 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint64 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function lt(gtUint64 a, gtUint16 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + // Allowance with 64 bit + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint8 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function min(gtUint16 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint8 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint8.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function min(gtUint64 a, gtUint16 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint16 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function max(gtUint16 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint16 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint16.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function max(gtUint64 a, gtUint16 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint32 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function mux(gtBool bit, gtUint16 a, gtUint64 b) internal returns (gtUint64){ - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint16.unwrap(a), gtUint64.unwrap(b))); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint32 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint32.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function mux(gtBool bit, gtUint64 a, gtUint16 b) internal returns (gtUint64){ - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint64.unwrap(a), gtUint16.unwrap(b))); + function transferWithAllowance(gtUint8 a, gtUint64 b, gtUint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint8.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); } - function transfer(gtUint16 a, gtUint64 b, gtUint64 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). - Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount)); - return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); + function transferWithAllowance(gtUint64 a, gtUint8 b, gtUint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint8.unwrap(b), gtUint64.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint8 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + + // =========== 16 - 64 bit operations ============== + + function add(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function add(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function checkedAdd(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); + } + + function checkedAdd(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); + } + + function sub(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function sub(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function checkedSub(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); + } + + function checkedSub(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); + } + + function mul(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function mul(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function checkedMul(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); + } + + function checkedMul(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); + } + + function div(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function div(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function rem(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function rem(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function and(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function and(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function or(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function or(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function xor(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function xor(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function shl(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + function shl(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + function shr(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function shr(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function eq(gtUint16 a, gtUint64 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function eq(gtUint64 a, gtUint16 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function ne(gtUint16 a, gtUint64 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function ne(gtUint64 a, gtUint16 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function ge(gtUint16 a, gtUint64 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function ge(gtUint64 a, gtUint16 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function gt(gtUint16 a, gtUint64 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function gt(gtUint64 a, gtUint16 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function le(gtUint16 a, gtUint64 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function le(gtUint64 a, gtUint16 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function lt(gtUint16 a, gtUint64 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function lt(gtUint64 a, gtUint16 b) internal returns (gtBool) { + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function min(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function min(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function max(gtUint16 a, gtUint64 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function max(gtUint64 a, gtUint16 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function mux(gtBool bit, gtUint16 a, gtUint64 b) internal returns (gtUint64){ + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint16.unwrap(a), gtUint64.unwrap(b))); + } + + function mux(gtBool bit, gtUint64 a, gtUint16 b) internal returns (gtUint64){ + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint64.unwrap(a), gtUint16.unwrap(b))); + } + + function transfer(gtUint16 a, gtUint64 b, gtUint64 amount) internal returns (gtUint64, gtUint64, gtBool){ + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint16 b, gtUint64 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint64.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint16 a, gtUint64 b, gtUint8 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint16 b, gtUint8 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint16 a, gtUint64 b, gtUint16 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint16 b, gtUint16 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint16 a, gtUint64 b, gtUint32 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint16 b, gtUint32 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint32.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint64 b, gtUint16 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } - // =========== 32 - 64 bit operations ============== - + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint32 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint32 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint32.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint64 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint64 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint64.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + // Allowance with 16 bit + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint32 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint32 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint32.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint64 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint64 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint64.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + // Allowance with 32 bit + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint8 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint8 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint16 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint16 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint32 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint32 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint32.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint64 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint64 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint64.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint16 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + // Allowance with 64 bit + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint8 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint8 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint8.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint16 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint16 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint16.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint32 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint32 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint32.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint16 a, gtUint64 b, gtUint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint16.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint16 b, gtUint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint16.unwrap(b), gtUint64.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint16 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + + + // =========== 32 - 64 bit operations ============== + function add(gtUint32 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function add(gtUint64 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Add(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Add(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + } + + function checkedAdd(gtUint32 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); + } + + function checkedAdd(gtUint64 a, gtUint32 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedAdd(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function sub(gtUint32 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function sub(gtUint64 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Sub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Sub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + } + + function checkedSub(gtUint32 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); + } + + function checkedSub(gtUint64 a, gtUint32 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedSub(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function mul(gtUint32 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function mul(gtUint64 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + } + + function checkedMul(gtUint32 a, gtUint64 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); + } + + function checkedMul(gtUint64 a, gtUint32 b) internal returns (gtUint64) { + (uint256 bit, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). + CheckedMul(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b)); + + return checkRes64(gtBool.wrap(bit), gtUint64.wrap(res)); } function div(gtUint32 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function div(gtUint64 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Div(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Div(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function rem(gtUint32 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function rem(gtUint64 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Rem(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Rem(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function and(gtUint32 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function and(gtUint64 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - And(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + And(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function or(gtUint32 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function or(gtUint64 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Or(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Or(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function xor(gtUint32 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function xor(gtUint64 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Xor(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Xor(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function shl(gtUint32 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } - function shl(gtUint64 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shl(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). + Shl(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } - function shr(gtUint32 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function shr(gtUint64 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Shr(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Shr(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function eq(gtUint32 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function eq(gtUint64 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Eq(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Eq(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function ne(gtUint32 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function ne(gtUint64 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ne(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ne(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function ge(gtUint32 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function ge(gtUint64 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Ge(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Ge(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function gt(gtUint32 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } - + function gt(gtUint64 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Gt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Gt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function le(gtUint32 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } - + function le(gtUint64 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Le(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Le(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function lt(gtUint32 a, gtUint64 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function lt(gtUint64 a, gtUint32 b) internal returns (gtBool) { - return gtBool.wrap(ExtendedOperations(MPC_PRECOMPILE). - Lt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtBool.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Lt(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function min(gtUint32 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function min(gtUint64 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Min(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Min(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function max(gtUint32 a, gtUint64 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b))); } - function max(gtUint64 a, gtUint32 b) internal returns (gtUint64) { - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Max(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); + function max(gtUint64 a, gtUint32 b) internal returns (gtUint64) { + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Max(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function mux(gtBool bit, gtUint32 a, gtUint64 b) internal returns (gtUint64){ - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint32.unwrap(a), gtUint64.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint32.unwrap(a), gtUint64.unwrap(b))); } function mux(gtBool bit, gtUint64 a, gtUint32 b) internal returns (gtUint64){ - return gtUint64.wrap(ExtendedOperations(MPC_PRECOMPILE). - Mux(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint64.unwrap(a), gtUint32.unwrap(b))); + return gtUint64.wrap(ExtendedOperations(address(MPC_PRECOMPILE)). + Mux(combineEnumsToBytes3(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtBool.unwrap(bit), gtUint64.unwrap(a), gtUint32.unwrap(b))); } function transfer(gtUint32 a, gtUint64 b, gtUint64 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint32 b, gtUint64 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint64.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint64 b, gtUint8 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint32 b, gtUint8 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint64 b, gtUint16 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint32 b, gtUint16 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint32 a, gtUint64 b, gtUint32 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint32 b, gtUint32 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } function transfer(gtUint64 a, gtUint64 b, gtUint32 amount) internal returns (gtUint64, gtUint64, gtBool){ - (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(MPC_PRECOMPILE). + (uint256 new_a, uint256 new_b, uint256 res) = ExtendedOperations(address(MPC_PRECOMPILE)). Transfer(combineEnumsToBytes4(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount)); return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res)); } -} \ No newline at end of file + + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint8 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint16 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint32 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint32 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint64 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint64 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint64.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint32 amount, gtUint8 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint8.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + // Allowance with 16 bit + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint8 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint16 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint32 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint32 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint64 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint64 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint64.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint32 amount, gtUint16 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint16.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + // Allowance with 32 bit + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint8 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint8 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint16 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint16 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint32 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint32 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint64 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint64 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint64.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint32 amount, gtUint32 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint32.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + // Allowance with 64 bit + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint8 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint8.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint8 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT8_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint8.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint16 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint16.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint16 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT16_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint16.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint32 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint32 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint32.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint32 a, gtUint64 b, gtUint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint32.unwrap(a), gtUint64.unwrap(b), gtUint64.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint32 b, gtUint64 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint32.unwrap(b), gtUint64.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } + + function transferWithAllowance(gtUint64 a, gtUint64 b, gtUint32 amount, gtUint64 allowance) internal returns (gtUint64, gtUint64, gtBool, gtUint64){ + (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance) = ExtendedOperations(address(MPC_PRECOMPILE)). + TransferWithAllowance(combineEnumsToBytes5(MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT64_T, MPC_TYPE.SUINT32_T, MPC_TYPE.SUINT64_T, ARGS.BOTH_SECRET), + gtUint64.unwrap(a), gtUint64.unwrap(b), gtUint32.unwrap(amount), gtUint64.unwrap(allowance)); + return (gtUint64.wrap(new_a), gtUint64.wrap(new_b), gtBool.wrap(res), gtUint64.wrap(new_allowance)); + } +} diff --git a/contracts/lib/MpcInterface.sol b/contracts/lib/MpcInterface.sol index 34e5adb..2aeb7ff 100644 --- a/contracts/lib/MpcInterface.sol +++ b/contracts/lib/MpcInterface.sol @@ -11,8 +11,11 @@ interface ExtendedOperations { function RandBoundedBits(bytes1 metaData, uint8 numBits) external returns (uint256 result); function Add(bytes3 metaData, uint256 lhs, uint256 rhs) external returns (uint256 result); + function CheckedAdd(bytes3 metaData, uint256 lhs, uint256 rhs) external returns (uint256 overflowBit, uint256 result); function Sub(bytes3 metaData, uint256 lhs, uint256 rhs) external returns (uint256 result); + function CheckedSub(bytes3 metaData, uint256 lhs, uint256 rhs) external returns (uint256 overflowBit, uint256 result); function Mul(bytes3 metaData, uint256 lhs, uint256 rhs) external returns (uint256 result); + function CheckedMul(bytes3 metaData, uint256 lhs, uint256 rhs) external returns (uint256 overflowBit, uint256 result); function Div(bytes3 metaData, uint256 lhs, uint256 rhs) external returns (uint256 result); function Rem(bytes3 metaData, uint256 lhs, uint256 rhs) external returns (uint256 result); function And(bytes3 metaData, uint256 lhs, uint256 rhs) external returns (uint256 result); @@ -32,9 +35,10 @@ interface ExtendedOperations { function Mux(bytes3 metaData, uint256 bit, uint256 a,uint256 b) external returns (uint256 result); function Not(bytes1 metaData, uint256 a) external returns (uint256 result); function Transfer(bytes4 metaData, uint256 a, uint256 b, uint256 amount) external returns (uint256 new_a, uint256 new_b, uint256 res); - function TransferWithAllowance(bytes4 metaData, uint256 a, uint256 b, uint256 amount, uint256 allowance) external returns (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance); + function TransferWithAllowance(bytes5 metaData, uint256 a, uint256 b, uint256 amount, uint256 allowance) external returns (uint256 new_a, uint256 new_b, uint256 res, uint256 new_allowance); function ValidateCiphertext(bytes1 metaData, uint256 ciphertext, bytes calldata signature) external returns (uint256 result); - function GetUserKey(bytes calldata signedEK) external view returns (bytes memory encryptedKey); + function GetUserKey(bytes calldata signedEK) external returns (bytes memory encryptedKey); + function DeleteUserKey(bytes calldata signature) external returns (bool); } address constant MPC_PRECOMPILE = address(0x0000000000000000000000000000000000000064); diff --git a/hardhat.config.ts b/hardhat.config.ts index 20cc28d..260d0b1 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -4,13 +4,12 @@ import dotenv from "dotenv" dotenv.config() const config: HardhatUserConfig = { - defaultNetwork: "devnet", + defaultNetwork: "testnet", solidity: "0.8.24", networks: { - // hardhat: {}, - devnet: { - url: "https://devnet.coti.io/rpc", - chainId: 13068200, + testnet: { + url: "https://testnet.coti.io/rpc", + chainId: 7082400, }, }, paths:{ diff --git a/package.json b/package.json index 0f96fa0..90fccc9 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "test": "yarn hardhat test" }, "devDependencies": { - "@coti-io/coti-sdk-typescript": "0.6.3", + "@coti-io/coti-sdk-typescript": "1.0.1", "@nomicfoundation/hardhat-chai-matchers": "^2.0.0", "@nomicfoundation/hardhat-ethers": "^3.0.0", "@nomicfoundation/hardhat-ignition": "^0.15.0", diff --git a/test-hardhat/precompile.test.ts b/test-hardhat/precompile.test.ts index 29a9886..07bf0bf 100644 --- a/test-hardhat/precompile.test.ts +++ b/test-hardhat/precompile.test.ts @@ -21,7 +21,7 @@ function buildTest( await (await contract.getFunction(func)(...params, { gasLimit })).wait() const result = await contract.getFunction(resFunc)() - if (resFunc === "getRandom") { + if (resFunc === "getRandom" || resFunc === "getRandomBounded") { expect(result).to.not.equal(expectedResults[0]) last_random_value = result } else if (expectedResults.length === 1) { @@ -56,46 +56,35 @@ const bool_a = true const bool_b = false const [a, b] = params describe("Precompile", function () { - buildTest("PrecompilesArythmeticTestsContract", "addTest", "getResult", params, a + b) - buildTest("PrecompilesArythmeticTestsContract", "subTest", "getResult", params, a - b) - buildTest("PrecompilesArythmeticTestsContract", "mulTest", "getResult16", params, a * b) - - buildTest("PrecompilesMiscellaneousTestsContract", "divTest", "getResult", params, a / b) - buildTest("PrecompilesMiscellaneousTestsContract", "remTest", "getResult", params, a % b) - - buildTest("PrecompilesBitwiseTestsContract", "andTest", "getResult", params, a & b) - buildTest("PrecompilesBitwiseTestsContract", "orTest", "getResult", params, a | b) - buildTest("PrecompilesBitwiseTestsContract", "xorTest", "getResult", params, a ^ b) - - buildTest( - "PrecompilesShiftTestsContract", - "shlTest", - "getAllShiftResults", - [a, shift], - ...[2, 4, 8, 16].map((x) => BigInt(a << shift) & BigInt(`0x${"f".repeat(x)}`)) - ) - buildTest("PrecompilesShiftTestsContract", "shrTest", "getResult", params, a >> b) - - buildTest("PrecompilesMinMaxTestsContract", "minTest", "getResult", params, Math.min(a, b)) - buildTest("PrecompilesMinMaxTestsContract", "maxTest", "getResult", params, Math.max(a, b)) - buildTest("PrecompilesComparison2TestsContract", "eqTest", "getResult", params, a == b) - buildTest("PrecompilesComparison2TestsContract", "neTest", "getResult", params, a != b) - buildTest("PrecompilesComparison2TestsContract", "geTest", "getResult", params, a >= b) - buildTest("PrecompilesComparison1TestsContract", "gtTest", "getResult", params, a > b) - buildTest("PrecompilesComparison1TestsContract", "leTest", "getResult", params, a <= b) - buildTest("PrecompilesComparison1TestsContract", "ltTest", "getResult", params, a < b) - buildTest("PrecompilesMiscellaneousTestsContract", "muxTest", "getResult", [bit, a, b], bit === false ? a : b) + buildTest("PrecompilesArythmeticTestsContract", "addTest", "getAddResult", params, a + b) + buildTest("PrecompilesArythmeticTestsContract", "subTest", "getSubResult", params, a - b) + buildTest("PrecompilesArythmeticTestsContract", "mulTest", "getMulResult", params, a * b) + + buildTest("PrecompilesMiscellaneousTestsContract", "divTest", "getDivResult", params, a / b) + buildTest("PrecompilesMiscellaneousTestsContract", "remTest", "getRemResult", params, a % b) + + buildTest("PrecompilesBitwiseTestsContract", "andTest", "getAndResult", params, a & b) + buildTest("PrecompilesBitwiseTestsContract", "orTest", "getOrResult", params, a | b) + buildTest("PrecompilesBitwiseTestsContract", "xorTest", "getXorResult", params, a ^ b) + + buildTest("PrecompilesMinMaxTestsContract", "minTest", "getMinResult", params, Math.min(a, b)) + buildTest("PrecompilesMinMaxTestsContract", "maxTest", "getMaxResult", params, Math.max(a, b)) + buildTest("PrecompilesComparison2TestsContract", "eqTest", "getEqResult", params, a == b) + buildTest("PrecompilesComparison2TestsContract", "neTest", "getNeResult", params, a != b) + buildTest("PrecompilesComparison2TestsContract", "geTest", "getGeResult", params, a >= b) + buildTest("PrecompilesComparison1TestsContract", "gtTest", "getGtResult", params, a > b) + buildTest("PrecompilesComparison1TestsContract", "leTest", "getLeResult", params, a <= b) + buildTest("PrecompilesComparison1TestsContract", "ltTest", "getLtResult", params, a < b) + buildTest("PrecompilesMiscellaneousTestsContract", "muxTest", "getMuxResult", [bit, a, b], bit === false ? a : b) buildTest("PrecompilesTransferTestsContract", "transferTest", "getResults", [a, b, b], a - b, b + b, true) buildTest("PrecompilesTransferScalarTestsContract", "transferScalarTest", "getResults", [a, b, b], a - b, b + b, true) - - buildTest("PrecompilesMiscellaneousTestsContract", "offboardOnboardTest", "getResult", [a, a, a, a], a) + buildTest("PrecompilesOffboardToUserKeyTestContract", "offboardOnboardTest", "getOnboardOffboardResult", [a, a, a, a], a) buildTest("PrecompilesMiscellaneousTestsContract", "notTest", "getBoolResult", [!!a], !a) buildTestWithUser("PrecompilesOffboardToUserKeyTestContract", "offboardToUserTest", "getCTs", a) - buildTest("PrecompilesMiscellaneous1TestsContract", "randomTest", "getRandom", [], last_random_value) - buildTest("PrecompilesMiscellaneous1TestsContract", "randomBoundedTest", "getRandom", [numBits], last_random_value) + buildTest("PrecompilesMiscellaneous1TestsContract", "randomBoundedTest", "getRandomBounded", [numBits], last_random_value) buildTest( "PrecompilesMiscellaneous1TestsContract", "booleanTest", @@ -110,4 +99,14 @@ describe("Precompile", function () { bit ? bool_b : bool_a, bool_a ) + + + // buildTest( + // "PrecompilesShiftTestsContract", + // "shlTest", + // "getAllShiftResults", + // [a, shift], + // ...[2, 4, 8, 16].map((x) => BigInt(a << shift) & BigInt(`0x${"f".repeat(x)}`)) + // ) + // buildTest("PrecompilesShiftTestsContract", "shrTest", "getResult", params, a >> b) }) diff --git a/test-hardhat/util/onboard.ts b/test-hardhat/util/onboard.ts index 9ce5d00..cba8cfe 100644 --- a/test-hardhat/util/onboard.ts +++ b/test-hardhat/util/onboard.ts @@ -1,24 +1,28 @@ import fs from "fs" import hre from "hardhat" -import { Wallet, parseEther } from "ethers" -import { ConfidentialAccount } from "@coti-io/coti-sdk-typescript" +import {Wallet, parseEther, getDefaultProvider} from "ethers" +import {ConfidentialAccount, initEtherProvider, transferNative} from "@coti-io/coti-sdk-typescript" +import dotenv from "dotenv"; let pks = process.env.SIGNING_KEYS ? process.env.SIGNING_KEYS.split(",") : [] export async function setupAccounts() { + dotenv.config(); + const provider = initEtherProvider('https://testnet.coti.io/rpc'); + if (pks.length == 0) { - const key1 = hre.ethers.Wallet.createRandom(hre.ethers.provider) - const key2 = hre.ethers.Wallet.createRandom(hre.ethers.provider) - pks = [key1.privateKey, key2.privateKey] + const wallet1 = hre.ethers.Wallet.createRandom(provider) + const wallet2 = hre.ethers.Wallet.createRandom(provider) + pks = [wallet1.privateKey, wallet2.privateKey] - setEnvValue("PUBLIC_KEYS", `${key1.address},${key2.address}`) - setEnvValue("SIGNING_KEYS", `${key1.privateKey},${key2.privateKey}`) + setEnvValue("PUBLIC_KEYS", `${wallet1.address},${wallet2.address}`) + setEnvValue("SIGNING_KEYS", `${wallet1.privateKey},${wallet2.privateKey}`) - throw new Error(`Created new random accounts ${key1.address} and ${key2.address}. Please use faucet to fund it.`) + throw new Error(`Created new random accounts ${wallet1.address} and ${wallet2.address}. Please use faucet to fund it.`) } - const wallets = pks.map((pk) => new hre.ethers.Wallet(pk, hre.ethers.provider)) - if ((await hre.ethers.provider.getBalance(wallets[0].address)) === BigInt("0")) { + const wallets = pks.map((pk) => new hre.ethers.Wallet(pk, provider)) + if ((await provider.getBalance(wallets[0].address)) === BigInt("0")) { throw new Error(`Please use faucet to fund account ${wallets[0].address}`) } diff --git a/yarn.lock b/yarn.lock index 5198150..248e23b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7,10 +7,10 @@ resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.10.1.tgz#63430d04bd8c5e74f8d7d049338f1cd9d4f02069" integrity sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw== -"@coti-io/coti-sdk-typescript@0.6.2": - version "0.6.2" - resolved "https://registry.yarnpkg.com/@coti-io/coti-sdk-typescript/-/coti-sdk-typescript-0.6.2.tgz#c7cd6836109c8c21f445b40d1e532ceecc2de36c" - integrity sha512-rp/HvHN2VnTMb7OV+ZCBM/yZlAOP32dW3X8irG7txyKb2LrbUKPzfoFlrGfDckgrJ+pOoe4KSC3ZYA5OW2HiVA== +"@coti-io/coti-sdk-typescript@1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@coti-io/coti-sdk-typescript/-/coti-sdk-typescript-1.0.1.tgz#b185b834f9627ffd175876665fb6c211cf23d1f6" + integrity sha512-F397bpW/yPv0KGMq8ZCNSCxAmDfSAj5eaAeQsmljNsctVFHGMctxBM1aK0JBBSU8PnNklmDWeSmS37pm/Uouag== dependencies: node-forge "^1.3.1" From 83a36ffe84e83a05a86d600163f40a53dcf85fe4 Mon Sep 17 00:00:00 2001 From: Daniel Gruesso Date: Tue, 24 Sep 2024 15:25:35 -0400 Subject: [PATCH 2/5] Add new and existing functions of MpcCore to readme --- contracts/lib/lib_readme.md | 43 ++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/contracts/lib/lib_readme.md b/contracts/lib/lib_readme.md index 9cd9845..eb31059 100644 --- a/contracts/lib/lib_readme.md +++ b/contracts/lib/lib_readme.md @@ -1,6 +1,9 @@ # MpcCore.sol -This Solidity library, `MpcCore`, provides core functionalities for secure multi-party computation (MPC) using the COTI protocol. Below is an overview of its components and functions: +This Solidity library, `MpcCore`, provides core functionalities for secure multi-party computation (MPC) using the COTI protocol. + +Below is an overview of its components and functions: + ## Legend @@ -31,11 +34,49 @@ These functions combine enum values into bytes for efficient storage and transfe - `combineEnumsToBytes3(MPC_TYPE mpcType1, MPC_TYPE mpcType2, ARGS argsType)`: Combines two `MPC_TYPE` values and an `ARGS` value into a `bytes3` value. - `combineEnumsToBytes4(MPC_TYPE mpcType1, MPC_TYPE mpcType2, MPC_TYPE mpcType3, ARGS argsType)`: Combines three `MPC_TYPE` values and an `ARGS` value into a `bytes4` value. +### Overflow and Result Validation +- `checkOverflow`: Validates whether an overflow has occurred in a cryptographic operation. +- `checkRes8`, `checkRes16`, `checkRes32`, `checkRes64`: Check the result for different bit sizes (8, 16, 32, and 64 bits). + ### Key Management Functions - `getUserKey(bytes calldata signedEK, bytes calldata signature)`: Retrieves the user's AES encryption key in encrypted format, by using the provided public key to encrypt it - signature is used to validate the account ownership. +- `deleteUserKey`: Deletes a user’s cryptographic key. This library is designed to be used as part of a secure multi-party computation framework, facilitating the handling and combination of encrypted and signed data types. +### Ciphertext Validation and Decryption +- `validateCiphertext`: Validates the integrity of a ciphertext. +- `decrypt`: Decrypts a given ciphertext. + +### Onboarding and Offboarding Users +- `onBoard`: Adds a user to the MPC protocol. +- `offBoard`: Removes a user from the MPC protocol. +- `offBoardToUser`: Transfers data ownership to a user during offboarding. +- `offBoardCombined`: Combines offboarding actions for multiple users. + +### Setting Public Keys +- `setPublic`: Sets a public key for cryptographic operations. +- `setPublic8`, `setPublic16`, `setPublic32`, `setPublic64`: Sets public keys for specific bit sizes (8, 16, 32, and 64 bits). + +### Random Number Generation +- `rand`, `rand8`, `rand16`, `rand32`, `rand64`: Generate random numbers of various bit sizes. +- `randBoundedBits8`, `randBoundedBits16`, `randBoundedBits32`, `randBoundedBits64`: Generates bounded random numbers within a specified range for different bit sizes. + +### Logical and Comparison Operations +- `and`, `or`, `xor`: Perform bitwise operations. +- `eq`, `ne`, `ge`, `gt`, `le`, `lt`: Perform comparison operations (equality, inequality, greater than, less than, etc.). + +### Mathematical Operations +- `add`, `checkedAdd`, `sub`, `checkedSub`, `mul`, `checkedMul`, `div`, `rem`: Perform mathematical operations, with both standard and overflow-checked versions available. +- `min`, `max`: Return the minimum or maximum of two values. + +### Data Transfer Operations +- `transfer`, `transferWithAllowance`: Facilitate data or token transfer operations between accounts. + +### Multiplexer and Logical Negation +- `mux`: Implements a multiplexer operation (conditional value selection). +- `not`: Implements a bitwise NOT operation. + # MpcInterface.sol This Solidity interface, `ExtendedOperations`, defines a set of functions for performing various operations that are essential for secure multi-party computation (MPC) on the COTI network. Below is an overview of its components and functions: From 1eadd283fd18fd8b0695c35688169d64f42a806a Mon Sep 17 00:00:00 2001 From: Daniel Gruesso Date: Tue, 24 Sep 2024 15:48:05 -0400 Subject: [PATCH 3/5] Update contribution guidelines --- CONTRIBUTING.md | 8 ++++---- LICENSE | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5134dd5..ba69c53 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ -# Contributing to COTI SDK TypeScript Examples +# Contributing to COTI Confidentiality Contracts Project -Thank you for your interest in contributing to the COTI SDK TypeScript Examples project! We welcome contributions from the community and appreciate your efforts to improve our project. +Thank you for your interest in contributing to the COTI Confidentiality Contracts project! We welcome contributions from the community and appreciate your efforts to improve our project. ## Table of Contents @@ -38,8 +38,8 @@ We welcome code contributions! To get started, follow these steps: 2. **Clone your fork**: ```sh - git clone https://github.com/your-username/coti-sdk-typescript-examples.git - cd coti-sdk-typescript-examples + git clone https://github.com/your-username/confidentiality-contracts.git + cd confidentiality-contracts ``` 3. **Create a branch**: diff --git a/LICENSE b/LICENSE index f49a4e1..7e559f1 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2024 COTI Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From 9bf3d44596af4a177106d0f597944e4ed7b15646 Mon Sep 17 00:00:00 2001 From: Daniel Gruesso Date: Wed, 25 Sep 2024 18:10:44 -0400 Subject: [PATCH 4/5] Update offboard methods in mpc readme --- contracts/lib/lib_readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/lib/lib_readme.md b/contracts/lib/lib_readme.md index eb31059..3d7142a 100644 --- a/contracts/lib/lib_readme.md +++ b/contracts/lib/lib_readme.md @@ -49,13 +49,13 @@ This library is designed to be used as part of a secure multi-party computation - `decrypt`: Decrypts a given ciphertext. ### Onboarding and Offboarding Users -- `onBoard`: Adds a user to the MPC protocol. -- `offBoard`: Removes a user from the MPC protocol. -- `offBoardToUser`: Transfers data ownership to a user during offboarding. -- `offBoardCombined`: Combines offboarding actions for multiple users. +- `onBoard`: Adds a user to the MPC protocol, loading data from `ct` type to `gt` type. +- `offBoard`: Removes a user from the MPC protocol, transforming data from `gt` type to `ct` type. +- `offBoardToUser`: Transfers data ownership to a user during offboarding; transforms from `gt` type to `ct` type previously prepared by the user's AES key rather than the MPC one. +- `offBoardCombined`: Combines offboarding actions for multiple users, offboarding to both the user's AES key and the network's AES key. ### Setting Public Keys -- `setPublic`: Sets a public key for cryptographic operations. +- `setPublic`: Sets a public key for cryptographic operations, taking data that was sent to the contract in as `ct` and transforming it to `gt`. - `setPublic8`, `setPublic16`, `setPublic32`, `setPublic64`: Sets public keys for specific bit sizes (8, 16, 32, and 64 bits). ### Random Number Generation From fa85a25e8140da0ef246b05a352190cce9ea6f7e Mon Sep 17 00:00:00 2001 From: Daniel Gruesso Date: Wed, 2 Oct 2024 15:25:01 -0400 Subject: [PATCH 5/5] Update onboarding and public key descriptions with more detail --- contracts/lib/lib_readme.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/lib/lib_readme.md b/contracts/lib/lib_readme.md index 3d7142a..595feb7 100644 --- a/contracts/lib/lib_readme.md +++ b/contracts/lib/lib_readme.md @@ -49,14 +49,14 @@ This library is designed to be used as part of a secure multi-party computation - `decrypt`: Decrypts a given ciphertext. ### Onboarding and Offboarding Users -- `onBoard`: Adds a user to the MPC protocol, loading data from `ct` type to `gt` type. -- `offBoard`: Removes a user from the MPC protocol, transforming data from `gt` type to `ct` type. -- `offBoardToUser`: Transfers data ownership to a user during offboarding; transforms from `gt` type to `ct` type previously prepared by the user's AES key rather than the MPC one. -- `offBoardCombined`: Combines offboarding actions for multiple users, offboarding to both the user's AES key and the network's AES key. +- `onBoard`: Operating for loading data from `ct` type to `gt` type. for example loading data saved on-chain so it can be used for computation. +- `offBoard`: Operation for transforming data from `gt` type to `ct` type. for example saving data after a computation operation was done on-chain. +- `offBoardToUser`: Operation to transform from `gt` type to `ct` type, same as `offBoard`. The main difference is that the AES key used for that is from `msg.sender` rather then the network itself. +- `offBoardCombined`: Operation to transform from `gt` type to `ct` type, same as `offBoard` and `offBoardToUser`, so that it returns the `ct` encrypted by the network key and by the `msg.sender` key. ### Setting Public Keys -- `setPublic`: Sets a public key for cryptographic operations, taking data that was sent to the contract in as `ct` and transforming it to `gt`. -- `setPublic8`, `setPublic16`, `setPublic32`, `setPublic64`: Sets public keys for specific bit sizes (8, 16, 32, and 64 bits). +- `setPublic`: Transforms data that was sent as clear value (not encrypted) to the contract and transforms it to `gt` type so that it can be used for computation. +- `setPublic8`, `setPublic16`, `setPublic32`, `setPublic64`: Same as `setPublic`, for specific bit sizes (8, 16, 32, and 64 bits). ### Random Number Generation - `rand`, `rand8`, `rand16`, `rand32`, `rand64`: Generate random numbers of various bit sizes.