Skip to content

Commit

Permalink
align testnet
Browse files Browse the repository at this point in the history
fix precompile tests and rename on board params.
  • Loading branch information
eitanz-coti committed Sep 17, 2024
1 parent 11998e6 commit 8a1b7ce
Show file tree
Hide file tree
Showing 19 changed files with 4,216 additions and 3,566 deletions.
6 changes: 3 additions & 3 deletions contracts/AccountOnboard/AccountOnboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
381 changes: 104 additions & 277 deletions contracts/examples/precompiles/PrecompilesArythmeticTestsContract.sol

Large diffs are not rendered by default.

268 changes: 83 additions & 185 deletions contracts/examples/precompiles/PrecompilesBitwiseTestsContract.sol

Large diffs are not rendered by default.

180 changes: 67 additions & 113 deletions contracts/examples/precompiles/PrecompilesComparison1TestsContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.19;
import "../../lib/MpcCore.sol";

contract PrecompilesComparison1TestsContract {

struct AllGTCastingValues {
gtUint8 a8_s;
gtUint8 b8_s;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}



}
Loading

0 comments on commit 8a1b7ce

Please sign in to comment.