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

fix(RoninGateway): cache calldata length, nit _i #5

Merged
merged 1 commit into from
Mar 6, 2024
Merged
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
63 changes: 29 additions & 34 deletions src/ronin/gateway/RoninGatewayV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,32 +152,31 @@ contract RoninGatewayV3 is
onlyBridgeOperator
returns (bool[] memory _executedReceipts)
{
address _governor = msg.sender;
uint256 _minVoteWeight = minimumVoteWeight();
address governor = msg.sender;
uint256 minVoteWeight = minimumVoteWeight();

uint256 _withdrawalId;
_executedReceipts = new bool[](_withdrawalIds.length);
uint256 withdrawalId;
uint length = _withdrawalIds.length;

_executedReceipts = new bool[](length);
IBridgeTracking bridgeTrackingContract = IBridgeTracking(getContract(ContractType.BRIDGE_TRACKING));
for (uint256 _i; _i < _withdrawalIds.length;) {
_withdrawalId = _withdrawalIds[_i];
bridgeTrackingContract.recordVote(IBridgeTracking.VoteKind.MainchainWithdrawal, _withdrawalId, _governor);
if (mainchainWithdrew(_withdrawalId)) {
_executedReceipts[_i] = true;

for (uint256 i; i < length; i++) {
withdrawalId = _withdrawalIds[i];
bridgeTrackingContract.recordVote(IBridgeTracking.VoteKind.MainchainWithdrawal, withdrawalId, governor);
if (mainchainWithdrew(withdrawalId)) {
_executedReceipts[i] = true;
} else {
IsolatedGovernance.Vote storage _vote = mainchainWithdrewVote[_withdrawalId];
Transfer.Receipt memory _withdrawal = withdrawal[_withdrawalId];
IsolatedGovernance.Vote storage _vote = mainchainWithdrewVote[withdrawalId];
Transfer.Receipt memory _withdrawal = withdrawal[withdrawalId];
bytes32 _hash = _withdrawal.hash();
VoteStatus _status = _castIsolatedVote(_vote, _governor, _minVoteWeight, _hash);
VoteStatus _status = _castIsolatedVote(_vote, governor, minVoteWeight, _hash);
if (_status == VoteStatus.Approved) {
_vote.status = VoteStatus.Executed;
bridgeTrackingContract.handleVoteApproved(IBridgeTracking.VoteKind.MainchainWithdrawal, _withdrawalId);
bridgeTrackingContract.handleVoteApproved(IBridgeTracking.VoteKind.MainchainWithdrawal, withdrawalId);
emit MainchainWithdrew(_hash, _withdrawal);
}
}

unchecked {
++_i;
}
}
}

Expand All @@ -190,11 +189,12 @@ contract RoninGatewayV3 is
onlyBridgeOperator
returns (bool[] memory _executedReceipts)
{
_executedReceipts = new bool[](receipts.length);
uint length = receipts.length;
_executedReceipts = new bool[](length);
uint256 minVoteWeight = minimumVoteWeight();

Transfer.Receipt memory iReceipt;
for (uint i; i < receipts.length; ++i) {
for (uint i; i < length; ++i) {
iReceipt = receipts[i];
if (depositVote[iReceipt.mainchain.chainId][iReceipt.id].status == VoteStatus.Executed) {
_executedReceipts[i] = true;
Expand All @@ -214,14 +214,12 @@ contract RoninGatewayV3 is
/**
* @inheritdoc IRoninGatewayV3
*/
function bulkRequestWithdrawalFor(Transfer.Request[] calldata _requests, uint256 _chainId) external whenNotPaused {
if (_requests.length == 0) revert ErrEmptyArray();
function bulkRequestWithdrawalFor(Transfer.Request[] calldata requests, uint256 chainId) external whenNotPaused {
uint length = requests.length;
if (length == 0) revert ErrEmptyArray();

for (uint256 _i; _i < _requests.length;) {
_requestWithdrawalFor(_requests[_i], msg.sender, _chainId);
unchecked {
++_i;
}
for (uint i; i < length; ++i) {
_requestWithdrawalFor(requests[i], msg.sender, chainId);
}
}

Expand All @@ -248,17 +246,18 @@ contract RoninGatewayV3 is
) external whenNotPaused onlyBridgeOperator {
address operator = msg.sender;

if (!(withdrawals.length > 0 && withdrawals.length == signatures.length)) {
uint length = withdrawals.length;
if (!(length > 0 && length == signatures.length)) {
revert ErrLengthMismatch(msg.sig);
}

uint256 _minVoteWeight = minimumVoteWeight();

uint256 id;
IBridgeTracking _bridgeTrackingContract = IBridgeTracking(getContract(ContractType.BRIDGE_TRACKING));
for (uint256 _i; _i < withdrawals.length;) {
id = withdrawals[_i];
_withdrawalSig[id][operator] = signatures[_i];
for (uint i; i < length; ++i) {
id = withdrawals[i];
_withdrawalSig[id][operator] = signatures[i];
_bridgeTrackingContract.recordVote(IBridgeTracking.VoteKind.Withdrawal, id, operator);

IsolatedGovernance.Vote storage _proposal = withdrawalStatVote[id];
Expand All @@ -267,10 +266,6 @@ contract RoninGatewayV3 is
_proposal.status = VoteStatus.Executed;
_bridgeTrackingContract.handleVoteApproved(IBridgeTracking.VoteKind.Withdrawal, id);
}

unchecked {
++_i;
}
}
}

Expand Down