Skip to content

Commit 5afd48d

Browse files
committed
fix: add prefix to internal functions
1 parent 2036ec7 commit 5afd48d

7 files changed

Lines changed: 104 additions & 96 deletions

File tree

script/InitWithdraw.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ contract InitWithdraw is Script {
4242
// Read pegin data to compute the exact lock amount in PegBTC
4343
GatewayUpgradeable.PeginData memory pegin = gateway.getPeginData(instanceId);
4444
require(pegin.peginAmountSats > 0, "pegin not found or amount=0");
45-
uint256 lockAmount = Converter.amountFromSats(pegin.peginAmountSats);
45+
uint256 lockAmount = Converter._amountFromSats(pegin.peginAmountSats);
4646

4747
// derive sender address from private key in a view-only way
4848
address operator = vm.addr(pk);

src/CommitteeManagement.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ contract CommitteeManagement is MultiSigVerifier {
183183
uint256 nonce,
184184
bytes[] memory authSignatures
185185
) external {
186-
bytes32 msgHash = getAddWatchtowerDigest(watchtower);
186+
bytes32 msgHash = _getAddWatchtowerDigest(watchtower);
187187
_executeNoncedSignatures(msgHash, nonce, authSignatures);
188188
watchtowerList.add(watchtower);
189189
}
@@ -194,14 +194,14 @@ contract CommitteeManagement is MultiSigVerifier {
194194
uint256 nonce,
195195
bytes[] memory authSignatures
196196
) external {
197-
bytes32 msgHash = getRemoveWatchtowerDigest(watchtower);
197+
bytes32 msgHash = _getRemoveWatchtowerDigest(watchtower);
198198
_executeNoncedSignatures(msgHash, nonce, authSignatures);
199199
watchtowerList.remove(watchtower);
200200
}
201201

202202
// ========== Digest Helpers (Watchtower) ==========
203203
/// @dev Returns the domain-bound message hash for adding a watchtower (without nonce)
204-
function getAddWatchtowerDigest(
204+
function _getAddWatchtowerDigest(
205205
bytes32 watchtower
206206
) internal view returns (bytes32) {
207207
bytes32 typeHash = keccak256("ADD_WATCHTOWER(bytes32 watchtower)");
@@ -213,12 +213,12 @@ contract CommitteeManagement is MultiSigVerifier {
213213
bytes32 watchtower,
214214
uint256 nonce
215215
) public view returns (bytes32) {
216-
bytes32 msgHash = getAddWatchtowerDigest(watchtower);
216+
bytes32 msgHash = _getAddWatchtowerDigest(watchtower);
217217
return getNoncedDigest(msgHash, nonce);
218218
}
219219

220220
/// @dev Returns the domain-bound message hash for removing a watchtower (without nonce)
221-
function getRemoveWatchtowerDigest(
221+
function _getRemoveWatchtowerDigest(
222222
bytes32 watchtower
223223
) internal view returns (bytes32) {
224224
bytes32 typeHash = keccak256("REMOVE_WATCHTOWER(bytes32 watchtower)");
@@ -230,7 +230,7 @@ contract CommitteeManagement is MultiSigVerifier {
230230
bytes32 watchtower,
231231
uint256 nonce
232232
) public view returns (bytes32) {
233-
bytes32 msgHash = getRemoveWatchtowerDigest(watchtower);
233+
bytes32 msgHash = _getRemoveWatchtowerDigest(watchtower);
234234
return getNoncedDigest(msgHash, nonce);
235235
}
236236

@@ -264,7 +264,7 @@ contract CommitteeManagement is MultiSigVerifier {
264264
uint256 nonce,
265265
bytes[] memory authSignatures
266266
) external {
267-
bytes32 msgHash = getAddAuthorizedCallerDigest(caller);
267+
bytes32 msgHash = _getAddAuthorizedCallerDigest(caller);
268268
_executeNoncedSignatures(msgHash, nonce, authSignatures);
269269
authorizedCallers.add(caller);
270270
emit AuthorizedCallerAdded(caller);
@@ -276,15 +276,15 @@ contract CommitteeManagement is MultiSigVerifier {
276276
uint256 nonce,
277277
bytes[] memory authSignatures
278278
) external {
279-
bytes32 msgHash = getRemoveAuthorizedCallerDigest(caller);
279+
bytes32 msgHash = _getRemoveAuthorizedCallerDigest(caller);
280280
_executeNoncedSignatures(msgHash, nonce, authSignatures);
281281
authorizedCallers.remove(caller);
282282
emit AuthorizedCallerRemoved(caller);
283283
}
284284

285285
// ========== Digest Helpers (Authorized Callers) ==========
286286
/// @dev Returns the domain-bound message hash for adding an authorized external caller (without nonce)
287-
function getAddAuthorizedCallerDigest(
287+
function _getAddAuthorizedCallerDigest(
288288
address caller
289289
) internal view returns (bytes32) {
290290
bytes32 typeHash = keccak256("ADD_AUTH_CALLER(address caller)");
@@ -296,12 +296,12 @@ contract CommitteeManagement is MultiSigVerifier {
296296
address caller,
297297
uint256 nonce
298298
) public view returns (bytes32) {
299-
bytes32 msgHash = getAddAuthorizedCallerDigest(caller);
299+
bytes32 msgHash = _getAddAuthorizedCallerDigest(caller);
300300
return getNoncedDigest(msgHash, nonce);
301301
}
302302

303303
/// @dev Returns the domain-bound message hash for removing an authorized external caller (without nonce)
304-
function getRemoveAuthorizedCallerDigest(
304+
function _getRemoveAuthorizedCallerDigest(
305305
address caller
306306
) internal view returns (bytes32) {
307307
bytes32 typeHash = keccak256("REMOVE_AUTH_CALLER(address caller)");
@@ -313,7 +313,7 @@ contract CommitteeManagement is MultiSigVerifier {
313313
address caller,
314314
uint256 nonce
315315
) public view returns (bytes32) {
316-
bytes32 msgHash = getRemoveAuthorizedCallerDigest(caller);
316+
bytes32 msgHash = _getRemoveAuthorizedCallerDigest(caller);
317317
return getNoncedDigest(msgHash, nonce);
318318
}
319319

src/Gateway.sol

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
6868
mapping(bytes16 graphId => GraphData) public graphDataMap;
6969
mapping(bytes16 graphId => WithdrawData) public withdrawDataMap;
7070

71+
constructor() {
72+
_disableInitializers();
73+
}
74+
7175
// initializer
7276
function initialize(
7377
IPegBTC _pegBTC,
@@ -191,7 +195,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
191195
);
192196
}
193197

194-
function getCancelWithdrawDigest(
198+
function _getCancelWithdrawDigest(
195199
bytes16 graphId
196200
) internal view returns (bytes32) {
197201
return
@@ -204,11 +208,11 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
204208
bytes16 graphId,
205209
uint256 nonce
206210
) public view returns (bytes32) {
207-
bytes32 msgHash = getCancelWithdrawDigest(graphId);
211+
bytes32 msgHash = _getCancelWithdrawDigest(graphId);
208212
return committeeManagement.getNoncedDigest(msgHash, nonce);
209213
}
210214

211-
function getUnlockStakeDigest(
215+
function _getUnlockStakeDigest(
212216
address operator,
213217
uint256 amount
214218
) internal view returns (bytes32) {
@@ -228,7 +232,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
228232
uint256 amount,
229233
uint256 nonce
230234
) public view returns (bytes32) {
231-
bytes32 msgHash = getUnlockStakeDigest(operator, amount);
235+
bytes32 msgHash = _getUnlockStakeDigest(operator, amount);
232236
return committeeManagement.getNoncedDigest(msgHash, nonce);
233237
}
234238

@@ -277,7 +281,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
277281
if (withdrawData.status != WithdrawStatus.Processing)
278282
revert WithdrawStatusInvalid();
279283

280-
bytes32 takeTxid = BitvmTxParser.computeTxid(rawTakeTx);
284+
bytes32 takeTxid = BitvmTxParser._computeTxid(rawTakeTx);
281285
if (takeTxid != expectedTxid) revert TxidMismatch();
282286
_verifyMerkleInclusion(takeProof, takeTxid, false);
283287

@@ -287,7 +291,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
287291
uint64 rewardAmountSats = _operatorReward(peginData.peginAmountSats);
288292
pegBTC.transfer(
289293
withdrawData.operatorAddress,
290-
Converter.amountFromSats(rewardAmountSats)
294+
Converter._amountFromSats(rewardAmountSats)
291295
);
292296

293297
if (happyPath) {
@@ -331,6 +335,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
331335
string calldata userChangeAddress,
332336
string calldata userRefundAddress
333337
) external payable {
338+
// TODO: check if request already exists
334339
PeginDataInner storage peginData = peginDataMap[instanceId];
335340
if (peginData.status != PeginStatus.None) revert InstanceUsed();
336341
// TODO: check peginAmount,feeRate,userInputs
@@ -449,7 +454,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
449454
uint64 peginAmountSats,
450455
address depositorAddress,
451456
bytes16 parsedInstanceId
452-
) = BitvmTxParser.parsePegin(rawPeginTx);
457+
) = BitvmTxParser._parsePegin(rawPeginTx);
453458
if (parsedInstanceId != instanceId) revert InstanceMismatch();
454459
if (peginAmountSats != peginData.peginAmountSats)
455460
revert PeginAmountMismatch();
@@ -481,9 +486,9 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
481486
if (feeAmountSats >= peginAmountSats) revert FeeTooHigh();
482487
pegBTC.mint(
483488
depositorAddress,
484-
Converter.amountFromSats(peginAmountSats - feeAmountSats)
489+
Converter._amountFromSats(peginAmountSats - feeAmountSats)
485490
);
486-
pegBTC.mint(address(this), Converter.amountFromSats(feeAmountSats));
491+
pegBTC.mint(address(this), Converter._amountFromSats(feeAmountSats));
487492

488493
emit BridgeIn(
489494
depositorAddress,
@@ -554,7 +559,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
554559
peginData.status = PeginStatus.Locked;
555560

556561
// lock operator's pegBTC
557-
uint256 lockAmount = Converter.amountFromSats(
562+
uint256 lockAmount = Converter._amountFromSats(
558563
peginData.peginAmountSats
559564
);
560565
pegBTC.transferFrom(msg.sender, address(this), lockAmount);
@@ -588,6 +593,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
588593
revert TimelockNotExpired();
589594
}
590595
withdrawData.status = WithdrawStatus.Canceled;
596+
// FIXME: transfer to operator or gateway?
591597
pegBTC.transfer(msg.sender, withdrawData.lockAmount);
592598
peginData.status = PeginStatus.Withdrawbale;
593599

@@ -601,7 +607,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
601607
) external {
602608
// validate committeeSigs
603609
WithdrawData storage withdrawData = withdrawDataMap[graphId];
604-
bytes32 cancel_digest = getCancelWithdrawDigest(graphId);
610+
bytes32 cancel_digest = _getCancelWithdrawDigest(graphId);
605611
committeeManagement.executeNoncedSignatures(
606612
cancel_digest,
607613
nonce,
@@ -614,6 +620,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
614620
if (withdrawData.status != WithdrawStatus.Initialized)
615621
revert WithdrawStatusInvalid();
616622
withdrawData.status = WithdrawStatus.Canceled;
623+
// FIXME: transfer to operator or gateway?
617624
pegBTC.transfer(msg.sender, withdrawData.lockAmount);
618625
peginData.status = PeginStatus.Withdrawbale;
619626
emit CancelWithdraw(withdrawData.instanceId, graphId, msg.sender);
@@ -633,7 +640,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
633640
revert KickoffHeightLow();
634641

635642
GraphData storage graphData = graphDataMap[graphId];
636-
bytes32 kickoffTxid = BitvmTxParser.computeTxid(rawKickoffTx);
643+
bytes32 kickoffTxid = BitvmTxParser._computeTxid(rawKickoffTx);
637644
if (kickoffTxid != graphData.kickoffTxid) revert TxidMismatch();
638645
_verifyMerkleInclusion(kickoffProof, kickoffTxid, false);
639646

@@ -710,7 +717,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
710717
kickoffTxid,
711718
kickoffVout,
712719
challengerAddress
713-
) = BitvmTxParser.parseChallengeTx(rawChallengeStartTx);
720+
) = BitvmTxParser._parseChallengeTx(rawChallengeStartTx);
714721
if (kickoffTxid != graphData.kickoffTxid) revert TxidMismatch();
715722
if (kickoffVout != BitvmTxParser.CHALLENGE_CONNECTOR_VOUT)
716723
revert TxidMismatch();
@@ -725,21 +732,21 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
725732
bytes32 challengeFinishTxid;
726733
address disproverAddress;
727734
if (disproveTxType == DisproveTxType.AssertTimeout) {
728-
(challengeFinishTxid) = BitvmTxParser.computeTxid(
735+
(challengeFinishTxid) = BitvmTxParser._computeTxid(
729736
rawChallengeFinishTx
730737
);
731738
if (graphData.assertTimoutTxids.length <= txnIndex)
732739
revert IndexOutOfRange();
733740
if (challengeFinishTxid != graphData.assertTimoutTxids[txnIndex])
734741
revert TxidMismatch();
735742
} else if (disproveTxType == DisproveTxType.OperatorCommitTimeout) {
736-
(challengeFinishTxid) = BitvmTxParser.computeTxid(
743+
(challengeFinishTxid) = BitvmTxParser._computeTxid(
737744
rawChallengeFinishTx
738745
);
739746
if (challengeFinishTxid != graphData.commitTimoutTxid)
740747
revert TxidMismatch();
741748
} else if (disproveTxType == DisproveTxType.OperatorNack) {
742-
(challengeFinishTxid) = BitvmTxParser.computeTxid(
749+
(challengeFinishTxid) = BitvmTxParser._computeTxid(
743750
rawChallengeFinishTx
744751
);
745752
if (graphData.NackTxids.length <= txnIndex)
@@ -752,7 +759,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
752759
kickoffTxid,
753760
kickoffVout,
754761
disproverAddress
755-
) = BitvmTxParser.parseDisproveTx(rawChallengeFinishTx);
762+
) = BitvmTxParser._parseDisproveTx(rawChallengeFinishTx);
756763
if (kickoffTxid != graphData.kickoffTxid) revert TxidMismatch();
757764
if (kickoffVout != BitvmTxParser.DISPROVE_CONNECTOR_VOUT)
758765
revert TxidMismatch();
@@ -762,7 +769,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
762769
kickoffTxid,
763770
kickoffVout,
764771
disproverAddress
765-
) = BitvmTxParser.parseQuickChallengeTx(rawChallengeFinishTx);
772+
) = BitvmTxParser._parseQuickChallengeTx(rawChallengeFinishTx);
766773
if (kickoffTxid != graphData.kickoffTxid) revert TxidMismatch();
767774
if (kickoffVout != BitvmTxParser.GUARDIAN_CONNECTOR_VOUT)
768775
revert TxidMismatch();
@@ -774,7 +781,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
774781
kickoffTxid,
775782
kickoffVout,
776783
disproverAddress
777-
) = BitvmTxParser.parseChallengeIncompleteKickoffTx(
784+
) = BitvmTxParser._parseChallengeIncompleteKickoffTx(
778785
rawChallengeFinishTx
779786
);
780787
if (kickoffTxid != graphData.kickoffTxid) revert TxidMismatch();
@@ -835,7 +842,7 @@ contract GatewayUpgradeable is BitvmPolicy, Initializable, IGateway {
835842
uint256 nonce,
836843
bytes[] calldata committeeSigs
837844
) external {
838-
bytes32 msgHash = getUnlockStakeDigest(operator, amount);
845+
bytes32 msgHash = _getUnlockStakeDigest(operator, amount);
839846
committeeManagement.executeNoncedSignatures(
840847
msgHash,
841848
nonce,

src/StakeManagement.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ contract StakeManagement is IStakeManagement, Initializable {
4747
return lockedStakes[operator];
4848
}
4949

50+
// TODO: add caller authentication?
5051
function slashStake(address operator, uint256 amount) external override {
5152
require(stakes[operator] >= amount, "insufficient stake to slash");
5253
if (lockedStakes[operator] > amount) {

0 commit comments

Comments
 (0)