Skip to content

Commit

Permalink
Merge branch 'main' of github.com:dapplink-labs/l2fp-contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
guoshijiang committed Dec 26, 2024
2 parents 70a6614 + b7ae61a commit 4c50035
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 1,759 deletions.
350 changes: 0 additions & 350 deletions broadcast/deployFinalityRelayer.s.sol/17000/run-1734950985.json

This file was deleted.

350 changes: 0 additions & 350 deletions broadcast/deployFinalityRelayer.s.sol/17000/run-1734951327.json

This file was deleted.

350 changes: 0 additions & 350 deletions broadcast/deployFinalityRelayer.s.sol/17000/run-1735026376.json

This file was deleted.

350 changes: 0 additions & 350 deletions broadcast/deployFinalityRelayer.s.sol/17000/run-1735027040.json

This file was deleted.

350 changes: 0 additions & 350 deletions broadcast/deployFinalityRelayer.s.sol/17000/run-latest.json

This file was deleted.

2 changes: 1 addition & 1 deletion lib/forge-std
34 changes: 27 additions & 7 deletions src/bls/BLSApkRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.20;

import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/utils/cryptography/EIP712.sol";

import "../libraries/BN254.sol";

Expand All @@ -14,16 +15,12 @@ import { console } from "forge-std/Script.sol";



contract BLSApkRegistry is Initializable, OwnableUpgradeable, IBLSApkRegistry, BLSApkRegistryStorage {
contract BLSApkRegistry is Initializable, OwnableUpgradeable, IBLSApkRegistry, BLSApkRegistryStorage, EIP712{
using BN254 for BN254.G1Point;

uint256 internal constant PAIRING_EQUALITY_CHECK_GAS = 120000;

modifier onlyFinalityRelayerManager() {
console.log("==============================");
console.log("sender===", msg.sender);
console.log("finalityRelayerManager==", finalityRelayerManager);
console.log("==============================");
require(
msg.sender == finalityRelayerManager,
"BLSApkRegistry.onlyFinalityRelayerManager: caller is not finality relayer manager contracts "
Expand All @@ -39,7 +36,9 @@ contract BLSApkRegistry is Initializable, OwnableUpgradeable, IBLSApkRegistry, B
_;
}

constructor() {
constructor()
EIP712("BLSApkRegistry", "v0.0.1")
{
_disableInitializers();
}

Expand All @@ -51,6 +50,7 @@ contract BLSApkRegistry is Initializable, OwnableUpgradeable, IBLSApkRegistry, B
_transferOwnership(_initialOwner);
finalityRelayerManager = _finalityRelayerManager;
relayerManager = _relayerManager;
_initializeApk();
}

function registerOperator(
Expand Down Expand Up @@ -81,7 +81,9 @@ contract BLSApkRegistry is Initializable, OwnableUpgradeable, IBLSApkRegistry, B
blsRegisterWhitelist[msg.sender],
"BLSApkRegistry.registerBLSPublicKey: this address have not permission to register bls key"
);

bytes32 pubkeyHash = BN254.hashG1Point(params.pubkeyG1);

require(
pubkeyHash != ZERO_PK_HASH,
"BLSApkRegistry.registerBLSPublicKey: cannot register zero pubkey"
Expand Down Expand Up @@ -114,7 +116,6 @@ contract BLSApkRegistry is Initializable, OwnableUpgradeable, IBLSApkRegistry, B
params.pubkeyG2
), "BLSApkRegistry.registerBLSPublicKey: either the G1 signature is wrong, or G1 and G2 private key do not match");


operatorToPubkey[operator] = params.pubkeyG1;
operatorToPubkeyHash[operator] = pubkeyHash;
pubkeyHashToOperator[pubkeyHash] = operator;
Expand Down Expand Up @@ -213,4 +214,23 @@ contract BLSApkRegistry is Initializable, OwnableUpgradeable, IBLSApkRegistry, B

return (pubkey, pubkeyHash);
}

function pubkeyRegistrationMessageHash(address operator) public view returns (BN254.G1Point memory) {
return BN254.hashToG1(
_hashTypedDataV4(
keccak256(abi.encode(PUBKEY_REGISTRATION_TYPEHASH, operator))
)
);
}

function _initializeApk() internal {
require(apkHistory.length == 0, "BLSApkRegistry.initializeApk: apk already exists");

apkHistory.push(ApkUpdate({
apkHash: bytes24(0),
updateBlockNumber: uint32(block.number),
nextUpdateBlockNumber: 0
}));
}

}
3 changes: 3 additions & 0 deletions src/interfaces/IBLSApkRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ interface IBLSApkRegistry {
function getRegisteredPubkey(address operator) external view returns (BN254.G1Point memory, bytes32);

function addOrRemoveBlsRegisterWhitelist(address operator, bool isAdd) external;

function pubkeyRegistrationMessageHash(address operator) external view returns (BN254.G1Point memory);

}

0 comments on commit 4c50035

Please sign in to comment.