From 541f416572b5874571e52c4e6a0fa07091d5f71a Mon Sep 17 00:00:00 2001 From: Faisal Usmani Date: Wed, 22 Oct 2025 10:25:36 -0400 Subject: [PATCH 1/2] improve: Move BytesLib to external folder Signed-off-by: Faisal Usmani --- .../{ => external}/libraries/BytesLib.sol | 12 +++-- .../external/libraries/MinimalLZOptions.sol | 2 +- contracts/libraries/SponsoredCCTPQuoteLib.sol | 2 +- .../mintburn/HyperCoreFlowExecutor.sol | 45 ++++++++++--------- .../sponsored-oft/ComposeMsgCodec.sol | 2 +- 5 files changed, 37 insertions(+), 26 deletions(-) rename contracts/{ => external}/libraries/BytesLib.sol (88%) diff --git a/contracts/libraries/BytesLib.sol b/contracts/external/libraries/BytesLib.sol similarity index 88% rename from contracts/libraries/BytesLib.sol rename to contracts/external/libraries/BytesLib.sol index fe83d77c7..31777de49 100644 --- a/contracts/libraries/BytesLib.sol +++ b/contracts/external/libraries/BytesLib.sol @@ -6,13 +6,15 @@ library BytesLib { * ERRORS * **************************************/ error OutOfBounds(); - error InvalidBytes(); - error InvalidStart(); /************************************** * FUNCTIONS * **************************************/ + // The following 4 functions are copied from solidity-bytes-utils library + // https://github.com/GNSPS/solidity-bytes-utils/blob/fc502455bb2a7e26a743378df042612dd50d1eb9/contracts/BytesLib.sol#L323C5-L398C6 + // Code was copied, and slightly modified to use revert instead of require + /** * @notice Reads a uint16 from a bytes array at a given start index * @param _bytes The bytes array to convert @@ -20,7 +22,9 @@ library BytesLib { * @return result The uint16 result */ function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16 result) { - require(_bytes.length >= _start + 2, "toUint16_outOfBounds"); + if (_bytes.length < _start + 2) { + revert OutOfBounds(); + } // solhint-disable-next-line no-inline-assembly assembly { @@ -81,6 +85,8 @@ library BytesLib { /** * @notice Reads a bytes array from a bytes array at a given start index and length + * Source: https://github.com/Vectorized/solady/blob/21202175063a0010826bf42697b5aa2ff0c27f9f/src/utils/LibBytes.sol#L369C5-L396C6 + * Code was copied, was not modified * @param _bytes The bytes array to convert * @param _start The start index of the bytes array * @param _end The end index of the bytes array diff --git a/contracts/external/libraries/MinimalLZOptions.sol b/contracts/external/libraries/MinimalLZOptions.sol index ecf495ea9..350da7591 100644 --- a/contracts/external/libraries/MinimalLZOptions.sol +++ b/contracts/external/libraries/MinimalLZOptions.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.23; -import { BytesLib } from "../../libraries/BytesLib.sol"; +import { BytesLib } from "../../external/libraries/BytesLib.sol"; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; /** diff --git a/contracts/libraries/SponsoredCCTPQuoteLib.sol b/contracts/libraries/SponsoredCCTPQuoteLib.sol index 251060312..db19790a8 100644 --- a/contracts/libraries/SponsoredCCTPQuoteLib.sol +++ b/contracts/libraries/SponsoredCCTPQuoteLib.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol"; import { SponsoredCCTPInterface } from "../interfaces/SponsoredCCTPInterface.sol"; -import { BytesLib } from "./BytesLib.sol"; +import { BytesLib } from "../external/libraries/BytesLib.sol"; import { Bytes32ToAddress } from "./AddressConverters.sol"; /** diff --git a/contracts/periphery/mintburn/HyperCoreFlowExecutor.sol b/contracts/periphery/mintburn/HyperCoreFlowExecutor.sol index ba5ee8946..f26338092 100644 --- a/contracts/periphery/mintburn/HyperCoreFlowExecutor.sol +++ b/contracts/periphery/mintburn/HyperCoreFlowExecutor.sol @@ -395,29 +395,34 @@ contract HyperCoreFlowExecutor is AccessControl, Lockable { ) internal virtual { CoreTokenInfo storage coreTokenInfo = coreTokenInfos[finalToken]; - bool isSponsoredFlow = maxBpsToSponsor > 0; - bool userHasNoCoreAccount = !HyperCoreLib.coreUserExists(finalRecipient); - if (userHasNoCoreAccount) { - if (isSponsoredFlow) { - revert AccountNotActivated(finalRecipient); - } else { - _fallbackHyperEVMFlow( - amountInEVM, - quoteNonce, - maxBpsToSponsor, - finalRecipient, - extraBridgingFeesEVM, - finalToken - ); - emit SimpleTransferFallbackAccountActivation(quoteNonce); - return; + { + bool isSponsoredFlow = maxBpsToSponsor > 0; + bool userHasNoCoreAccount = !HyperCoreLib.coreUserExists(finalRecipient); + if (userHasNoCoreAccount) { + if (isSponsoredFlow) { + revert AccountNotActivated(finalRecipient); + } else { + _fallbackHyperEVMFlow( + amountInEVM, + quoteNonce, + maxBpsToSponsor, + finalRecipient, + extraBridgingFeesEVM, + finalToken + ); + emit SimpleTransferFallbackAccountActivation(quoteNonce); + return; + } } } - uint256 maxEvmAmountToSponsor = ((amountInEVM + extraBridgingFeesEVM) * maxBpsToSponsor) / BPS_SCALAR; - uint256 amountToSponsor = extraBridgingFeesEVM; - if (amountToSponsor > maxEvmAmountToSponsor) { - amountToSponsor = maxEvmAmountToSponsor; + uint256 amountToSponsor; + { + uint256 maxEvmAmountToSponsor = ((amountInEVM + extraBridgingFeesEVM) * maxBpsToSponsor) / BPS_SCALAR; + amountToSponsor = extraBridgingFeesEVM; + if (amountToSponsor > maxEvmAmountToSponsor) { + amountToSponsor = maxEvmAmountToSponsor; + } } if (amountToSponsor > 0) { diff --git a/contracts/periphery/mintburn/sponsored-oft/ComposeMsgCodec.sol b/contracts/periphery/mintburn/sponsored-oft/ComposeMsgCodec.sol index df11de58d..bb24ef646 100644 --- a/contracts/periphery/mintburn/sponsored-oft/ComposeMsgCodec.sol +++ b/contracts/periphery/mintburn/sponsored-oft/ComposeMsgCodec.sol @@ -1,6 +1,6 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.23; -import { BytesLib } from "../../../libraries/BytesLib.sol"; +import { BytesLib } from "../../../external/libraries/BytesLib.sol"; /// @notice Codec for params passed in OFT `composeMsg`. library ComposeMsgCodec { From 3ecf2b60a87a6246cea0db756ec5b038bbdb4957 Mon Sep 17 00:00:00 2001 From: Faisal Usmani Date: Wed, 22 Oct 2025 11:01:04 -0400 Subject: [PATCH 2/2] Undo var scoping Signed-off-by: Faisal Usmani --- .../mintburn/HyperCoreFlowExecutor.sol | 45 +++++++++---------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/contracts/periphery/mintburn/HyperCoreFlowExecutor.sol b/contracts/periphery/mintburn/HyperCoreFlowExecutor.sol index f26338092..ba5ee8946 100644 --- a/contracts/periphery/mintburn/HyperCoreFlowExecutor.sol +++ b/contracts/periphery/mintburn/HyperCoreFlowExecutor.sol @@ -395,34 +395,29 @@ contract HyperCoreFlowExecutor is AccessControl, Lockable { ) internal virtual { CoreTokenInfo storage coreTokenInfo = coreTokenInfos[finalToken]; - { - bool isSponsoredFlow = maxBpsToSponsor > 0; - bool userHasNoCoreAccount = !HyperCoreLib.coreUserExists(finalRecipient); - if (userHasNoCoreAccount) { - if (isSponsoredFlow) { - revert AccountNotActivated(finalRecipient); - } else { - _fallbackHyperEVMFlow( - amountInEVM, - quoteNonce, - maxBpsToSponsor, - finalRecipient, - extraBridgingFeesEVM, - finalToken - ); - emit SimpleTransferFallbackAccountActivation(quoteNonce); - return; - } + bool isSponsoredFlow = maxBpsToSponsor > 0; + bool userHasNoCoreAccount = !HyperCoreLib.coreUserExists(finalRecipient); + if (userHasNoCoreAccount) { + if (isSponsoredFlow) { + revert AccountNotActivated(finalRecipient); + } else { + _fallbackHyperEVMFlow( + amountInEVM, + quoteNonce, + maxBpsToSponsor, + finalRecipient, + extraBridgingFeesEVM, + finalToken + ); + emit SimpleTransferFallbackAccountActivation(quoteNonce); + return; } } - uint256 amountToSponsor; - { - uint256 maxEvmAmountToSponsor = ((amountInEVM + extraBridgingFeesEVM) * maxBpsToSponsor) / BPS_SCALAR; - amountToSponsor = extraBridgingFeesEVM; - if (amountToSponsor > maxEvmAmountToSponsor) { - amountToSponsor = maxEvmAmountToSponsor; - } + uint256 maxEvmAmountToSponsor = ((amountInEVM + extraBridgingFeesEVM) * maxBpsToSponsor) / BPS_SCALAR; + uint256 amountToSponsor = extraBridgingFeesEVM; + if (amountToSponsor > maxEvmAmountToSponsor) { + amountToSponsor = maxEvmAmountToSponsor; } if (amountToSponsor > 0) {