{
    "Function": "registerBLSPublicKey",
    "File": "src/contracts/middleware/BLSPublicKeyCompendium.sol",
    "Parent Contracts": [
        "src/contracts/interfaces/IBLSPublicKeyCompendium.sol"
    ],
    "High-Level Calls": [
        "BN254",
        "BN254",
        "BN254",
        "BN254",
        "BN254",
        "BN254",
        "BN254",
        "BN254"
    ],
    "Internal Calls": [
        "abi.encodePacked()",
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)",
        "keccak256(bytes)",
        "require(bool,string)",
        "require(bool,string)"
    ],
    "Library Calls": [
        "negate",
        "scalar_mul",
        "plus",
        "generatorG2",
        "scalar_mul",
        "plus",
        "hashG1Point",
        "pairing"
    ],
    "Low-Level Calls": [],
    "Code": "function registerBLSPublicKey(uint256 s, BN254.G1Point memory rPoint, BN254.G1Point memory pubkeyG1, BN254.G2Point memory pubkeyG2) external {\n        // calculate -g1\n        BN254.G1Point memory negGeneratorG1 = BN254.negate(BN254.G1Point({X: 1, Y: 2}));\n        // verify a Schnorr signature (s, R) of pubkeyG1\n        // calculate s*-g1 + (R + H(msg.sender, P, R)*P) = 0\n        // which is the Schnorr signature verification equation\n        BN254.G1Point memory shouldBeZero = \n            BN254.plus(\n                BN254.scalar_mul(negGeneratorG1, s),\n                BN254.plus(\n                    rPoint,\n                    BN254.scalar_mul(\n                        pubkeyG1,\n                        uint256(keccak256(abi.encodePacked(msg.sender, pubkeyG1.X, pubkeyG1.Y, rPoint.X, rPoint.Y))) % BN254.FR_MODULUS\n                    )\n                )\n            );\n\n        require(shouldBeZero.X == 0 && shouldBeZero.Y == 0, \"BLSPublicKeyCompendium.registerBLSPublicKey: incorrect schnorr singature\");\n\n        // verify that the G2 pubkey has the same discrete log as the G1 pubkey\n        // e(P, [1]_2) = e([-1]_1, P')\n        require(BN254.pairing(\n            pubkeyG1,\n            BN254.generatorG2(),\n            negGeneratorG1,\n            pubkeyG2\n        ), \"BLSPublicKeyCompendium.registerBLSPublicKey: G1 and G2 private key do not match\");\n\n        // getting pubkey hash\n        bytes32 pubkeyHash = BN254.hashG1Point(pubkeyG1);\n\n        require(pubkeyHash != ZERO_PK_HASH, \"BLSPublicKeyCompendium.registerBLSPublicKey: operator attempting to register the zero public key\");\n\n        require(\n            operatorToPubkeyHash[msg.sender] == bytes32(0),\n            \"BLSPublicKeyCompendium.registerBLSPublicKey: operator already registered pubkey\"\n        );\n        require(\n            pubkeyHashToOperator[pubkeyHash] == address(0),\n            \"BLSPublicKeyCompendium.registerBLSPublicKey: public key already registered\"\n        );\n\n        // store updates\n        operatorToPubkeyHash[msg.sender] = pubkeyHash;\n        pubkeyHashToOperator[pubkeyHash] = msg.sender;\n\n        emit NewPubkeyRegistration(msg.sender, pubkeyG1, pubkeyG2);\n    }"
}