-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated some more stuff around blocklock solidity
- Loading branch information
1 parent
c919583
commit 0cac39f
Showing
5 changed files
with
109 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import {BLS} from "./BLS.sol"; | ||
import {ISignatureScheme} from "./ISignatureScheme.sol"; | ||
|
||
contract BlocklockSignatureScheme is ISignatureScheme { | ||
using BLS for bytes; | ||
|
||
string public constant SCHEME_ID = "BN254-BLS-BLOCKLOCK"; | ||
bytes public constant DST = bytes("BLOCKLOCK_BN254G1_XMD:KECCAK-256_SVDW_RO_H1_"); | ||
|
||
/** | ||
* @dev See {ISignatureScheme-verifySignature}. | ||
*/ | ||
function verifySignature(bytes calldata message, bytes calldata signature, bytes calldata publicKey) | ||
external | ||
view | ||
returns (bool isValid) | ||
{ | ||
// convert message hash bytes to g1 | ||
BLS.PointG1 memory _message = BLS.g1Unmarshal(message); | ||
// convert signature bytes to g1 | ||
BLS.PointG1 memory _signature = BLS.g1Unmarshal(signature); | ||
// convert public key bytes to g2 | ||
BLS.PointG2 memory _publicKey = BLS.g2Unmarshal(publicKey); | ||
// call evm precompile for pairing check | ||
(bool pairingSuccess, bool callSuccess) = BLS.verifySingle(_signature, _publicKey, _message); | ||
return (pairingSuccess && callSuccess); | ||
} | ||
|
||
/** | ||
* @dev See {ISignatureScheme-hashToPoint}. | ||
*/ | ||
function hashToPoint(bytes calldata message) public view returns (uint256, uint256) { | ||
BLS.PointG1 memory point = BLS.hashToPoint(DST, message); | ||
return (point.x, point.y); | ||
} | ||
|
||
/** | ||
* @dev See {ISignatureScheme-hashToBytes}. | ||
*/ | ||
function hashToBytes(bytes calldata message) external view returns (bytes memory) { | ||
(uint256 x, uint256 y) = hashToPoint(message); | ||
return BLS.g1Marshal(BLS.PointG1({x: x, y: y})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
interface ISignatureScheme { | ||
/// Getters | ||
|
||
/** | ||
* @notice Returns the scheme identifier as a string, e.g., "BN254", "BLS12-381", "TESS" | ||
*/ | ||
function SCHEME_ID() external returns (string memory); | ||
|
||
/** | ||
* @notice Verifies a signature using the given signature scheme. | ||
* @param message The message that was signed. Message is a G1 point represented as bytes. | ||
* @param signature The signature to verify. Signature is a G1 point represented as bytes. | ||
* @param publicKey The public key of the signer. Public key is a G2 point represented as bytes. | ||
* @return isValid boolean which evaluates to true if the signature is valid, false otherwise. | ||
*/ | ||
function verifySignature(bytes calldata message, bytes calldata signature, bytes calldata publicKey) | ||
external | ||
view | ||
returns (bool isValid); | ||
|
||
/** | ||
* @notice Hashes a message to a G1 point on the elliptic curve. | ||
* @param message The message to be hashed. | ||
* @return (uint256, uint256) A point on the elliptic curve in G1, represented as x and y coordinates. | ||
*/ | ||
function hashToPoint(bytes memory message) external view returns (uint256, uint256); | ||
/** | ||
* @notice Hashes a message to a G1 point on the elliptic curve. | ||
* @param message The message to be hashed. | ||
* @return bytes A point on the elliptic curve in G1, represented as bytes. | ||
*/ | ||
function hashToBytes(bytes calldata message) external view returns (bytes memory); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters