Skip to content

Commit 631becd

Browse files
author
dawanyezhi
committed
fix
1 parent cedc12b commit 631becd

File tree

10 files changed

+116
-68
lines changed

10 files changed

+116
-68
lines changed

foundry.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"lib/forge-std": {
3+
"rev": "1eea5bae12ae557d589f9f0f0edae2faa47cb262"
4+
},
5+
"lib/openzeppelin-contracts": {
6+
"rev": "69c8def5f222ff96f2b5beff05dfba996368aa79"
7+
},
8+
"lib/openzeppelin-contracts-upgradeable": {
9+
"rev": "fa525310e45f91eb20a6d3baa2644be8e0adba31"
10+
}
11+
}

script/DappLinkVRFDepoly.s.sol

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.20;
33

4-
import "forge-std/Vm.sol";
4+
import {Vm} from "forge-std/Vm.sol";
55
import {Script, console} from "forge-std/Script.sol";
6-
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
6+
import {TransparentUpgradeableProxy, ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
7+
import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
8+
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
79

810

9-
import "../src/utils/EmptyContract.sol";
11+
import {EmptyContract} from "../src/utils/EmptyContract.sol";
1012

11-
import "../src/contracts/vrf/DappLinkVRFManager.sol";
12-
import "../src/contracts/DappLinkVRFFactory.sol";
13-
import "../src/contracts/bls/BLSApkRegistry.sol";
13+
import {DappLinkVRFManager} from "../src/contracts/vrf/DappLinkVRFManager.sol";
14+
import {DappLinkVRFFactory} from "../src/contracts/DappLinkVRFFactory.sol";
15+
import {BLSApkRegistry} from "../src/contracts/bls/BLSApkRegistry.sol";
1416

1517

1618
// forge script ./script/DappLinkVRFDepoly.s.sol --rpc-url https://eth-holesky.g.alchemy.com/v2/BvSZ5ZfdIwB-5SDXMz8PfGcbICYQqwrl --private-key $PrivateKey --broadcast
@@ -46,16 +48,16 @@ contract DappLinkVRFDepolyScript is Script {
4648
)
4749
);
4850

49-
DappLinkVRFManager dappLinkVRF = new DappLinkVRFManager();
51+
DappLinkVRFManager dappLinkVrf = new DappLinkVRFManager();
5052

5153

52-
DappLinkVRFFactory dappLinkVRFFactory = new DappLinkVRFFactory();
54+
DappLinkVRFFactory dappLinkVrfFactory = new DappLinkVRFFactory();
5355

54-
address proxyDappLink = dappLinkVRFFactory.createProxy(address(dappLinkVRF), msg.sender, address(blsApkRegistry));
56+
address proxyDappLink = dappLinkVrfFactory.createProxy(address(dappLinkVrf), msg.sender, address(blsApkRegistry));
5557

5658
console.log("dapplink blsApkRegistry contract deployed at:", address(blsApkRegistry));
57-
console.log("dapplink base contract deployed at:", address(dappLinkVRF));
58-
console.log("DappLink Proxy Factory contract deployed at:", address(dappLinkVRFFactory));
59+
console.log("dapplink base contract deployed at:", address(dappLinkVrf));
60+
console.log("DappLink Proxy Factory contract deployed at:", address(dappLinkVrfFactory));
5961
console.log("DappLink Proxy contract deployed at:", proxyDappLink);
6062
/*
6163
* dapplink blsApkRegistry contract deployed at: 0x78Ea04E072C857C508999b391176e91487A6F27f
@@ -67,8 +69,8 @@ contract DappLinkVRFDepolyScript is Script {
6769
}
6870

6971
function getProxyAdminAddress(address proxy) internal view returns (address) {
70-
address CHEATCODE_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D;
71-
Vm vm = Vm(CHEATCODE_ADDRESS);
72+
address cheatcodeAddress = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D;
73+
Vm vm = Vm(cheatcodeAddress);
7274

7375
bytes32 adminSlot = vm.load(proxy, ERC1967Utils.ADMIN_SLOT);
7476
return address(uint160(uint256(adminSlot)));

src/contracts/DappLinkVRFFactory.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.20;
33

4-
import "@openzeppelin/contracts/proxy/Clones.sol";
5-
import "./vrf/DappLinkVRFManager.sol";
4+
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
5+
import {DappLinkVRFManager} from "./vrf/DappLinkVRFManager.sol";
66

77

88
contract DappLinkVRFFactory {

src/contracts/bls/BLSApkRegistry.sol

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.20;
33

4-
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
5-
import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
6-
import "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
4+
import {OwnableUpgradeable} from "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
5+
import {Initializable} from "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
6+
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
77

8-
import "../../libraries/BN254.sol";
9-
import "../../interface/IBLSApkRegistry.sol";
10-
import "./BLSApkRegistryStorage.sol";
8+
import {BN254} from "../../libraries/BN254.sol";
9+
import {IBLSApkRegistry} from "../../interface/IBLSApkRegistry.sol";
10+
import {BLSApkRegistryStorage} from "./BLSApkRegistryStorage.sol";
1111

1212
contract BLSApkRegistry is Initializable, OwnableUpgradeable, IBLSApkRegistry, BLSApkRegistryStorage, EIP712 {
1313
using BN254 for BN254.G1Point;
@@ -16,17 +16,25 @@ contract BLSApkRegistry is Initializable, OwnableUpgradeable, IBLSApkRegistry, B
1616

1717

1818
modifier onlyWhitelistManagerManager() {
19+
_onlyWhitelistManagerManager();
20+
_;
21+
}
22+
23+
function _onlyWhitelistManagerManager() internal view {
1924
require(
2025
msg.sender == whitelistManager, "BLSApkRegistry.onlyRelayerManager: caller is not the relayer manager address"
2126
);
22-
_;
2327
}
2428

2529
modifier onlyVrfManager() {
30+
_onlyVrfManager();
31+
_;
32+
}
33+
34+
function _onlyVrfManager() internal view {
2635
require(
2736
msg.sender == vrfManagerAddress, "BLSApkRegistry.onlyRelayerManager: caller is not the relayer manager address"
2837
);
29-
_;
3038
}
3139

3240

@@ -64,27 +72,27 @@ contract BLSApkRegistry is Initializable, OwnableUpgradeable, IBLSApkRegistry, B
6472
emit OperatorRemoved(operator, operatorToPubkeyHash[operator]);
6573
}
6674

67-
function registerBLSPublicKey(
75+
function registerBlsPublicKey(
6876
address operator,
6977
PubkeyRegistrationParams calldata params,
7078
BN254.G1Point calldata pubkeyRegistrationMessageHash
7179
) external returns (bytes32) {
7280
require(
7381
blsRegisterWhitelist[msg.sender],
74-
"BLSApkRegistry.registerBLSPublicKey: this address have not permission to register bls key"
82+
"BLSApkRegistry.registerBlsPublicKey: this address have not permission to register bls key"
7583
);
7684

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

79-
require(pubkeyHash != ZERO_PK_HASH, "BLSApkRegistry.registerBLSPublicKey: cannot register zero pubkey");
87+
require(pubkeyHash != ZERO_PK_HASH, "BLSApkRegistry.registerBlsPublicKey: cannot register zero pubkey");
8088
require(
8189
operatorToPubkeyHash[operator] == bytes32(0),
82-
"BLSApkRegistry.registerBLSPublicKey: operator already registered pubkey"
90+
"BLSApkRegistry.registerBlsPublicKey: operator already registered pubkey"
8391
);
8492

8593
require(
8694
pubkeyHashToOperator[pubkeyHash] == address(0),
87-
"BLSApkRegistry.registerBLSPublicKey: public key already registered"
95+
"BLSApkRegistry.registerBlsPublicKey: public key already registered"
8896
);
8997

9098
uint256 gamma = uint256(
@@ -104,12 +112,12 @@ contract BLSApkRegistry is Initializable, OwnableUpgradeable, IBLSApkRegistry, B
104112

105113
require(
106114
BN254.pairing(
107-
params.pubkeyRegistrationSignature.plus(params.pubkeyG1.scalar_mul(gamma)),
115+
params.pubkeyRegistrationSignature.plus(params.pubkeyG1.scalarMul(gamma)),
108116
BN254.negGeneratorG2(),
109-
pubkeyRegistrationMessageHash.plus(BN254.generatorG1().scalar_mul(gamma)),
117+
pubkeyRegistrationMessageHash.plus(BN254.generatorG1().scalarMul(gamma)),
110118
params.pubkeyG2
111119
),
112-
"BLSApkRegistry.registerBLSPublicKey: either the G1 signature is wrong, or G1 and G2 private key do not match"
120+
"BLSApkRegistry.registerBlsPublicKey: either the G1 signature is wrong, or G1 and G2 private key do not match"
113121
);
114122

115123
operatorToPubkey[operator] = params.pubkeyG1;
@@ -141,7 +149,22 @@ contract BLSApkRegistry is Initializable, OwnableUpgradeable, IBLSApkRegistry, B
141149
require(pairingSuccessful, "BLSSignatureChecker.checkSignatures: pairing precompile call failed");
142150
require(signatureIsValid, "BLSSignatureChecker.checkSignatures: signature is invalid");
143151

144-
bytes32 signatoryRecordHash = keccak256(abi.encodePacked(referenceBlockNumber, nonSignersPubkeyHashes));
152+
bytes32 signatoryRecordHash;
153+
assembly {
154+
let ptr := mload(0x40)
155+
let startPtr := ptr
156+
mstore(ptr, referenceBlockNumber)
157+
ptr := add(ptr, 0x20)
158+
let arrayPtr := nonSignersPubkeyHashes
159+
let arrayLength := mload(arrayPtr)
160+
for { let i := 0 } lt(i, arrayLength) { i := add(i, 1) } {
161+
mstore(ptr, mload(add(arrayPtr, add(0x20, mul(i, 0x20)))))
162+
ptr := add(ptr, 0x20)
163+
}
164+
let dataLength := sub(ptr, startPtr)
165+
signatoryRecordHash := keccak256(startPtr, dataLength)
166+
mstore(0x40, ptr)
167+
}
145168

146169
StakeTotals memory stakeTotals = StakeTotals({totalDappLinkStake: params.totalDappLinkStake, totalBtcStake: params.totalBtcStake});
147170

@@ -167,9 +190,9 @@ contract BLSApkRegistry is Initializable, OwnableUpgradeable, IBLSApkRegistry, B
167190
)
168191
) % BN254.FR_MODULUS;
169192
(pairingSuccessful, siganatureIsValid) = BN254.safePairing(
170-
sigma.plus(apk.scalar_mul(gamma)),
193+
sigma.plus(apk.scalarMul(gamma)),
171194
BN254.negGeneratorG2(),
172-
BN254.hashToG1(msgHash).plus(BN254.generatorG1().scalar_mul(gamma)),
195+
BN254.hashToG1(msgHash).plus(BN254.generatorG1().scalarMul(gamma)),
173196
apkG2,
174197
PAIRING_EQUALITY_CHECK_GAS
175198
);

src/contracts/vrf/DappLinkVRFManager.sol

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.20;
33

4-
import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
5-
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
4+
import {Initializable} from "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
5+
import {OwnableUpgradeable} from "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
66

7-
import "./DappLinkVRFStorage.sol";
8-
import "../../interface/IDappLinkVRFManager.sol";
7+
import {DappLinkVRFStorage} from "./DappLinkVRFStorage.sol";
8+
import {IDappLinkVRFManager} from "../../interface/IDappLinkVRFManager.sol";
9+
import {IBLSApkRegistry} from "../../interface/IBLSApkRegistry.sol";
910

1011
contract DappLinkVRFManager is Initializable, OwnableUpgradeable, DappLinkVRFStorage, IDappLinkVRFManager {
1112
event RequestSent(
@@ -20,10 +21,14 @@ contract DappLinkVRFManager is Initializable, OwnableUpgradeable, DappLinkVRFSto
2021
);
2122

2223
modifier onlyDappLink() {
23-
require(msg.sender == dappLinkAddress, "DappLinkVRF.onlyDappLink");
24+
_onlyDappLink();
2425
_;
2526
}
2627

28+
function _onlyDappLink() internal view {
29+
require(msg.sender == dappLinkAddress, "DappLinkVRF.onlyDappLink");
30+
}
31+
2732
constructor() {
2833
_disableInitializers();
2934
}

src/contracts/vrf/DappLinkVRFStorage.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.20;
33

4-
import "../../interface/IBLSApkRegistry.sol";
4+
import {IBLSApkRegistry} from "../../interface/IBLSApkRegistry.sol";
55

66
abstract contract DappLinkVRFStorage {
77
struct RequestStatus {

src/interface/IBLSApkRegistry.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.20;
33

4-
import "../libraries/BN254.sol";
4+
import {BN254} from "../libraries/BN254.sol";
55

66
interface IBLSApkRegistry {
77
struct VrfNoSignerAndSignature {
@@ -40,7 +40,7 @@ interface IBLSApkRegistry {
4040

4141
function deregisterOperator(address operator) external;
4242

43-
function registerBLSPublicKey(
43+
function registerBlsPublicKey(
4444
address operator,
4545
PubkeyRegistrationParams calldata params,
4646
BN254.G1Point memory msgHash

src/interface/IDappLinkVRFManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.20;
33

4-
import "./IBLSApkRegistry.sol";
4+
import {IBLSApkRegistry} from "./IBLSApkRegistry.sol";
55

66
interface IDappLinkVRFManager {
77
function requestRandomWords(uint256 _requestId, uint256 _numWords) external;

0 commit comments

Comments
 (0)