Address RFCs from @szotov and @tuxxy

pull/947/head
David Núñez 2019-05-16 10:35:26 +02:00
parent a2292b257a
commit ab5599ffff
5 changed files with 38 additions and 38 deletions

View File

@ -92,9 +92,9 @@ contract MiningAdjudicator is Upgradeable {
public
{
require(ReEncryptionValidator.check_serialized_coordinates(_minerPublicKey),
require(ReEncryptionValidator.checkSerializedCoordinates(_minerPublicKey),
"Miner's public key is invalid");
require(ReEncryptionValidator.check_serialized_coordinates(_requesterPublicKey),
require(ReEncryptionValidator.checkSerializedCoordinates(_requesterPublicKey),
"Requester's public key is invalid");
// Check that CFrag is not evaluated yet

View File

@ -70,7 +70,7 @@ library ReEncryptionValidator {
//////
// Input validation: E
require(check_compressed_point(
require(checkCompressedPoint(
_capsule.pointE.sign,
_capsule.pointE.xCoord,
_precomputed.pointEyCoord),
@ -78,7 +78,7 @@ library ReEncryptionValidator {
);
// Input validation: z*E
require(is_on_curve(_precomputed.pointEZxCoord, _precomputed.pointEZyCoord),
require(isOnCurve(_precomputed.pointEZxCoord, _precomputed.pointEZyCoord),
"Point zE is not a valid EC point"
);
require(ecmulVerify(
@ -91,7 +91,7 @@ library ReEncryptionValidator {
);
// Input validation: E1
require(check_compressed_point(
require(checkCompressedPoint(
_cFrag.pointE1.sign, // E1_sign
_cFrag.pointE1.xCoord, // E1_x
_precomputed.pointE1yCoord), // E1_y
@ -99,7 +99,7 @@ library ReEncryptionValidator {
);
// Input validation: h*E1
require(is_on_curve(_precomputed.pointE1HxCoord, _precomputed.pointE1HyCoord),
require(isOnCurve(_precomputed.pointE1HxCoord, _precomputed.pointE1HyCoord),
"Point h*E1 is not a valid EC point"
);
require(ecmulVerify(
@ -112,7 +112,7 @@ library ReEncryptionValidator {
);
// Input validation: E2
require(check_compressed_point(
require(checkCompressedPoint(
_cFrag.proof.pointE2.sign, // E2_sign
_cFrag.proof.pointE2.xCoord, // E2_x
_precomputed.pointE2yCoord), // E2_y
@ -136,7 +136,7 @@ library ReEncryptionValidator {
//////
// Input validation: V
require(check_compressed_point(
require(checkCompressedPoint(
_capsule.pointV.sign,
_capsule.pointV.xCoord,
_precomputed.pointVyCoord),
@ -144,7 +144,7 @@ library ReEncryptionValidator {
);
// Input validation: z*V
require(is_on_curve(_precomputed.pointVZxCoord, _precomputed.pointVZyCoord),
require(isOnCurve(_precomputed.pointVZxCoord, _precomputed.pointVZyCoord),
"Point zV is not a valid EC point"
);
require(ecmulVerify(
@ -157,7 +157,7 @@ library ReEncryptionValidator {
);
// Input validation: V1
require(check_compressed_point(
require(checkCompressedPoint(
_cFrag.pointV1.sign, // V1_sign
_cFrag.pointV1.xCoord, // V1_x
_precomputed.pointV1yCoord), // V1_y
@ -165,7 +165,7 @@ library ReEncryptionValidator {
);
// Input validation: h*V1
require(is_on_curve(_precomputed.pointV1HxCoord, _precomputed.pointV1HyCoord),
require(isOnCurve(_precomputed.pointV1HxCoord, _precomputed.pointV1HyCoord),
"Point h*V1 is not a valid EC point"
);
require(ecmulVerify(
@ -178,7 +178,7 @@ library ReEncryptionValidator {
);
// Input validation: V2
require(check_compressed_point(
require(checkCompressedPoint(
_cFrag.proof.pointV2.sign, // V2_sign
_cFrag.proof.pointV2.xCoord, // V2_x
_precomputed.pointV2yCoord), // V2_y
@ -204,7 +204,7 @@ library ReEncryptionValidator {
// We don't have to validate U since it's fixed and hard-coded
// Input validation: z*U
require(is_on_curve(_precomputed.pointUZxCoord, _precomputed.pointUZyCoord),
require(isOnCurve(_precomputed.pointUZxCoord, _precomputed.pointUZyCoord),
"Point z*U is not a valid EC point"
);
require(ecmulVerify(
@ -217,7 +217,7 @@ library ReEncryptionValidator {
);
// Input validation: U1 (a.k.a. KFragCommitment)
require(check_compressed_point(
require(checkCompressedPoint(
_cFrag.proof.pointKFragCommitment.sign, // U1_sign
_cFrag.proof.pointKFragCommitment.xCoord, // U1_x
_precomputed.pointU1yCoord), // U1_y
@ -225,7 +225,7 @@ library ReEncryptionValidator {
);
// Input validation: h*U1
require(is_on_curve(_precomputed.pointU1HxCoord, _precomputed.pointU1HyCoord),
require(isOnCurve(_precomputed.pointU1HxCoord, _precomputed.pointU1HyCoord),
"Point h*U1 is not a valid EC point"
);
require(ecmulVerify(
@ -238,7 +238,7 @@ library ReEncryptionValidator {
);
// Input validation: U2 (a.k.a. KFragPok ("proof of knowledge"))
require(check_compressed_point(
require(checkCompressedPoint(
_cFrag.proof.pointKFragPok.sign, // U2_sign
_cFrag.proof.pointKFragPok.xCoord, // U2_x
_precomputed.pointU2yCoord), // U2_y
@ -334,19 +334,19 @@ library ReEncryptionValidator {
/// @param _pointX The X coordinate of an EC point in affine representation
/// @param _pointY The Y coordinate of an EC point in affine representation
/// @return true iff _pointSign and _pointX are the compressed representation of (_pointX, _pointY)
function check_compressed_point(
function checkCompressedPoint(
uint8 _pointSign,
uint256 _pointX,
uint256 _pointY
) internal pure returns(bool) {
bool correct_sign = _pointY % 2 == _pointSign - 2;
return correct_sign && is_on_curve(_pointX, _pointY);
return correct_sign && isOnCurve(_pointX, _pointY);
}
/// @notice Tests if the given serialized coordinates represent a valid EC point
/// @param _coords The concatenation of serialized X and Y coordinates
/// @return true iff coordinates X and Y are a valid point
function check_serialized_coordinates(bytes memory _coords) internal pure returns(bool) {
function checkSerializedCoordinates(bytes memory _coords) internal pure returns(bool) {
require(_coords.length == 64, "Serialized coordinates should be 64 B");
uint256 coordX;
uint256 coordY;
@ -354,14 +354,14 @@ library ReEncryptionValidator {
coordX := mload(add(_coords, 32))
coordY := mload(add(_coords, 64))
}
return is_on_curve(coordX, coordY);
return isOnCurve(coordX, coordY);
}
/// @notice Tests if a point is on the secp256k1 curve
/// @param Px The X coordinate of an EC point in affine representation
/// @param Py The Y coordinate of an EC point in affine representation
/// @return true if (Px, Py) is a valid secp256k1 point; false otherwise
function is_on_curve(uint256 Px, uint256 Py) internal pure returns (bool) {
function isOnCurve(uint256 Px, uint256 Py) internal pure returns (bool) {
uint256 p = FIELD_ORDER;
if (Px >= p || Py >= p){

View File

@ -390,8 +390,8 @@ class Bob(Character):
"""
Raised when Bob detects incorrect CFrags returned by some Ursulas
"""
def __init__(self, grievances):
self.grievances = grievances
def __init__(self, evidence: List):
self.evidence = evidence
def __init__(self, controller=True, *args, **kwargs) -> None:
Character.__init__(self, *args, **kwargs)

View File

@ -194,20 +194,20 @@ contract ReEncryptionValidatorMock {
return ReEncryptionValidator.extendedKeccakToBN(_data);
}
function check_compressed_point(
function checkCompressedPoint(
uint8 _pointSign,
uint256 _pointX,
uint256 _pointY
) public pure returns(bool) {
return ReEncryptionValidator.check_compressed_point(_pointSign, _pointX, _pointY);
return ReEncryptionValidator.checkCompressedPoint(_pointSign, _pointX, _pointY);
}
function check_serialized_coordinates(bytes memory _coords) public pure returns(bool) {
return ReEncryptionValidator.check_serialized_coordinates(_coords);
function checkSerializedCoordinates(bytes memory _coords) public pure returns(bool) {
return ReEncryptionValidator.checkSerializedCoordinates(_coords);
}
function is_on_curve(uint256 Px, uint256 Py) public pure returns (bool) {
return ReEncryptionValidator.is_on_curve(Px, Py);
function isOnCurve(uint256 Px, uint256 Py) public pure returns (bool) {
return ReEncryptionValidator.isOnCurve(Px, Py);
}
function ecmulVerify(

View File

@ -49,25 +49,25 @@ def test_ec_point_operations(testerchain, reencryption_validator):
valid_point = Point.gen_rand()
x, y = valid_point.to_affine()
# Test is_on_curve
assert reencryption_validator.functions.is_on_curve(x, y).call()
# Test isOnCurve
assert reencryption_validator.functions.isOnCurve(x, y).call()
bad_y = y - 1
assert not reencryption_validator.functions.is_on_curve(x, bad_y).call()
assert not reencryption_validator.functions.isOnCurve(x, bad_y).call()
# Test check_compressed_point
# Test checkCompressedPoint
sign = 2 + (y % 2)
assert reencryption_validator.functions.check_compressed_point(sign, x, y).call()
assert reencryption_validator.functions.checkCompressedPoint(sign, x, y).call()
bad_sign = 3 - (y % 2)
assert not reencryption_validator.functions.check_compressed_point(bad_sign, x, y).call()
assert not reencryption_validator.functions.checkCompressedPoint(bad_sign, x, y).call()
# Test check_serialized_coordinates
# Test checkSerializedCoordinates
coords = valid_point.to_bytes(is_compressed=False)[1:]
assert reencryption_validator.functions.check_serialized_coordinates(coords).call()
assert reencryption_validator.functions.checkSerializedCoordinates(coords).call()
coords = coords[:-1] + ((coords[-1] + 42) % 256).to_bytes(1, 'big')
assert not reencryption_validator.functions.check_serialized_coordinates(coords).call()
assert not reencryption_validator.functions.checkSerializedCoordinates(coords).call()
# Test ecmulVerify
P = valid_point