Skip to content

Commit

Permalink
fix(style): run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
tremblaythibaultl committed Jun 22, 2023
1 parent af0854a commit f90f268
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 46 deletions.
144 changes: 119 additions & 25 deletions lib/Impl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ library Impl {
// Call the add precompile.
uint256 precompile = Precompiles.Add;
assembly {
if iszero(staticcall(gas(), precompile, input, inputLen, output, outputLen)) {
if iszero(
staticcall(
gas(),
precompile,
input,
inputLen,
output,
outputLen
)
) {
revert(0, 0)
}
}
Expand All @@ -55,7 +64,16 @@ library Impl {
// Call the sub precompile.
uint256 precompile = Precompiles.Subtract;
assembly {
if iszero(staticcall(gas(), precompile, input, inputLen, output, outputLen)) {
if iszero(
staticcall(
gas(),
precompile,
input,
inputLen,
output,
outputLen
)
) {
revert(0, 0)
}
}
Expand All @@ -80,7 +98,16 @@ library Impl {
// Call the mul precompile.
uint256 precompile = Precompiles.Multiply;
assembly {
if iszero(staticcall(gas(), precompile, input, inputLen, output, outputLen)) {
if iszero(
staticcall(
gas(),
precompile,
input,
inputLen,
output,
outputLen
)
) {
revert(0, 0)
}
}
Expand All @@ -90,7 +117,10 @@ library Impl {

// Evaluate `lhs <= rhs` on the given ciphertexts and, if successful, return the resulting ciphertext.
// If successful, the resulting ciphertext is automatically verified.
function lte(uint256 lhs, uint256 rhs) internal view returns (uint256 result) {
function lte(
uint256 lhs,
uint256 rhs
) internal view returns (uint256 result) {
bytes32[2] memory input;
input[0] = bytes32(lhs);
input[1] = bytes32(rhs);
Expand All @@ -102,7 +132,16 @@ library Impl {
// Call the lte precompile.
uint256 precompile = Precompiles.LessThanOrEqual;
assembly {
if iszero(staticcall(gas(), precompile, input, inputLen, output, outputLen)) {
if iszero(
staticcall(
gas(),
precompile,
input,
inputLen,
output,
outputLen
)
) {
revert(0, 0)
}
}
Expand All @@ -112,7 +151,10 @@ library Impl {

// Evaluate `lhs < rhs` on the given ciphertexts and, if successful, return the resulting ciphertext.
// If successful, the resulting ciphertext is automatically verified.
function lt(uint256 lhs, uint256 rhs) internal view returns (uint256 result) {
function lt(
uint256 lhs,
uint256 rhs
) internal view returns (uint256 result) {
bytes32[2] memory input;
input[0] = bytes32(lhs);
input[1] = bytes32(rhs);
Expand All @@ -124,7 +166,16 @@ library Impl {
// Call the lte precompile.
uint256 precompile = Precompiles.LessThan;
assembly {
if iszero(staticcall(gas(), precompile, input, inputLen, output, outputLen)) {
if iszero(
staticcall(
gas(),
precompile,
input,
inputLen,
output,
outputLen
)
) {
revert(0, 0)
}
}
Expand All @@ -135,7 +186,11 @@ library Impl {
// If `control`'s value is 1, the resulting value is the same value as `ifTrue`.
// If `control`'s value is 0, the resulting value is the same value as `ifFalse`.
// If successful, the resulting ciphertext is automatically verified.
function cmux(uint256 control, uint256 ifTrue, uint256 ifFalse) internal view returns (uint256 result) {
function cmux(
uint256 control,
uint256 ifTrue,
uint256 ifFalse
) internal view returns (uint256 result) {
// result = (ifTrue - ifFalse) * control + ifFalse

bytes32[2] memory input;
Expand All @@ -148,7 +203,16 @@ library Impl {
uint256 precompile = Precompiles.Subtract;
bytes32[1] memory subOutput;
assembly {
if iszero(staticcall(gas(), precompile, input, inputLen, subOutput, outputLen)) {
if iszero(
staticcall(
gas(),
precompile,
input,
inputLen,
subOutput,
outputLen
)
) {
revert(0, 0)
}
}
Expand All @@ -159,7 +223,16 @@ library Impl {
precompile = Precompiles.Multiply;
bytes32[1] memory mulOutput;
assembly {
if iszero(staticcall(gas(), precompile, input, inputLen, mulOutput, outputLen)) {
if iszero(
staticcall(
gas(),
precompile,
input,
inputLen,
mulOutput,
outputLen
)
) {
revert(0, 0)
}
}
Expand All @@ -170,14 +243,23 @@ library Impl {
precompile = Precompiles.Add;
bytes32[1] memory addOutput;
assembly {
if iszero(staticcall(gas(), precompile, input, inputLen, addOutput, outputLen)) {
if iszero(
staticcall(
gas(),
precompile,
input,
inputLen,
addOutput,
outputLen
)
) {
revert(0, 0)
}
}

result = uint256(addOutput[0]);
}

// Optimistically requires that the `ciphertext` is true.
//
// This function does not evaluate the given `ciphertext` at the time of the call.
Expand All @@ -204,7 +286,10 @@ library Impl {
}
}

function reencrypt(uint256 ciphertext, bytes32 publicKey) internal view returns (bytes memory reencrypted) {
function reencrypt(
uint256 ciphertext,
bytes32 publicKey
) internal view returns (bytes memory reencrypted) {
bytes32[2] memory input;
input[0] = bytes32(ciphertext);
input[1] = publicKey;
Expand All @@ -215,7 +300,16 @@ library Impl {
// Call the reencrypt precompile.
uint256 precompile = Precompiles.Reencrypt;
assembly {
if iszero(staticcall(gas(), precompile, input, inputLen, reencrypted, reencryptedSize)) {
if iszero(
staticcall(
gas(),
precompile,
input,
inputLen,
reencrypted,
reencryptedSize
)
) {
revert(0, 0)
}
}
Expand All @@ -227,16 +321,7 @@ library Impl {
// Call the fhePubKey precompile.
uint256 precompile = Precompiles.FhePubKey;
assembly {
if iszero(
staticcall(
gas(),
precompile,
0,
0,
key,
fhePubKeySize
)
) {
if iszero(staticcall(gas(), precompile, 0, 0, key, fhePubKeySize)) {
revert(0, 0)
}
}
Expand All @@ -256,7 +341,16 @@ library Impl {
uint256 precompile = Precompiles.Verify;
assembly {
// jump over the 32-bit `size` field of the `bytes` data structure of the `input` to read actual bytes
if iszero(staticcall(gas(), precompile, add(input, 32), inputLen, output, outputLen)) {
if iszero(
staticcall(
gas(),
precompile,
add(input, 32),
inputLen,
output,
outputLen
)
) {
revert(0, 0)
}
}
Expand Down
Loading

0 comments on commit f90f268

Please sign in to comment.