Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registration tests for Gasp + Aligned Layer + Ungate + Predicate #16

Merged
merged 8 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/othentic/BLSAuthLibrary.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.25;

/*______ __ __ __ __
/ \ / | / | / | / |
/$$$$$$ | _$$ |_ $$ |____ ______ _______ _$$ |_ $$/ _______
$$ | $$ |/ $$ | $$ \ / \ / \ / $$ | / | / |
$$ | $$ |$$$$$$/ $$$$$$$ |/$$$$$$ |$$$$$$$ |$$$$$$/ $$ |/$$$$$$$/
$$ | $$ | $$ | __ $$ | $$ |$$ $$ |$$ | $$ | $$ | __ $$ |$$ |
$$ \__$$ | $$ |/ |$$ | $$ |$$$$$$$$/ $$ | $$ | $$ |/ |$$ |$$ \_____
$$ $$/ $$ $$/ $$ | $$ |$$ |$$ | $$ | $$ $$/ $$ |$$ |
$$$$$$/ $$$$/ $$/ $$/ $$$$$$$/ $$/ $$/ $$$$/ $$/ $$$$$$$/
*/

import { BLS } from "./OthenticBLS.sol";

import "forge-std/console2.sol";

library OthenticBLSAuthLibrary {
using BLS for uint256[2];

bytes32 internal constant DOMAIN = keccak256("OthenticBLSAuth");

struct Signature {
uint256[2] signature;
}

/// @dev because of backwards compatibility issues, _signature is memory
/// even though it should be calldata. Once old registration is removed, adjust accordingly
function isValidSignature(
Signature memory _signature,
address _signer,
address _contract,
uint256[4] memory _blsKey
) internal view returns (bool) {
/// @dev signature verification succeeds if signature and pubkey are empty
if (!_signature.signature.isValidSignature()) return false;

uint256[2] memory _messageHash = _message(_signer, _contract);
(bool _callSuccess, bool _result) = _signature.signature.verifySingle(_blsKey, _messageHash);
return _callSuccess && _result;
}

/// @dev uses abi.encode twice because of the way the bls signatures are implemented in the CLI
/// if we want to reduce more gas we should look into how polygon implemented it
function _message(address _signer, address _contract) internal view returns (uint256[2] memory) {
// slither-disable-next-line calls-loop
bytes32 _hash = keccak256(abi.encode(_signer, _contract, block.chainid));
return BLS.hashToPoint(DOMAIN, abi.encode(_hash));
}
}
Loading