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

Last audit fixes #94

Merged
merged 3 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/LBPair.sol
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ contract LBPair is LBToken, ReentrancyGuard, Clone, ILBPair {
external
override
nonReentrant
notAddressZeroOrThis(to)
returns (bytes32 amountsReceived, bytes32 amountsLeft, uint256[] memory liquidityMinted)
{
if (liquidityConfigs.length == 0) revert LBPair__EmptyMarketConfigs();
Expand Down
8 changes: 4 additions & 4 deletions src/LBToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ abstract contract LBToken is ILBToken {
* @param id The token id.
* @param amount The amount to mint.
*/
function _mint(address account, uint256 id, uint256 amount) internal notAddressZeroOrThis(account) {
function _mint(address account, uint256 id, uint256 amount) internal {
_totalSupplies[id] += amount;

unchecked {
Expand All @@ -183,15 +183,15 @@ abstract contract LBToken is ILBToken {
* @param id The token id.
* @param amount The amount to burn.
*/
function _burn(address account, uint256 id, uint256 amount) internal notAddressZeroOrThis(account) {
function _burn(address account, uint256 id, uint256 amount) internal {
mapping(uint256 => uint256) storage accountBalances = _balances[account];

uint256 balance = accountBalances[id];
if (balance < amount) revert LBToken__BurnExceedsBalance(account, id, amount);

unchecked {
_totalSupplies[id] -= amount;
accountBalances[id] -= amount;
accountBalances[id] = balance - amount;
}
}

Expand Down Expand Up @@ -235,7 +235,7 @@ abstract contract LBToken is ILBToken {
* @param spender The address of the spender
* @param approved The boolean value to grant or revoke permission
*/
function _approveForAll(address owner, address spender, bool approved) internal {
function _approveForAll(address owner, address spender, bool approved) internal notAddressZeroOrThis(owner) {
if (owner == spender) revert LBToken__SelfApproval(owner);

_spenderApprovals[owner][spender] = approved;
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/ILBRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ interface ILBRouter {
* - distributionX: The distribution of tokenX with sum(distributionX) = 100e18 (100%) or 0 (0%)
* - distributionY: The distribution of tokenY with sum(distributionY) = 100e18 (100%) or 0 (0%)
* - to: The address of the recipient
* - deadline: The deadline of the tx
* - refundTo: The address of the recipient of the refunded tokens if too much tokens are sent
* - deadline: The deadline of the transaction
*/
struct LiquidityParameters {
IERC20 tokenX;
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/PairParameterHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ library PairParameterHelper {
newParams = newParams.set(baseFactor, Encoded.MASK_UINT16, OFFSET_BASE_FACTOR);
newParams = newParams.set(filterPeriod, Encoded.MASK_UINT12, OFFSET_FILTER_PERIOD);
newParams = newParams.set(decayPeriod, Encoded.MASK_UINT12, OFFSET_DECAY_PERIOD);
newParams = newParams.set(reductionFactor, Encoded.MASK_UINT16, OFFSET_REDUCTION_FACTOR);
newParams = newParams.set(reductionFactor, Encoded.MASK_UINT14, OFFSET_REDUCTION_FACTOR);
newParams = newParams.set(variableFeeControl, Encoded.MASK_UINT24, OFFSET_VAR_FEE_CONTROL);
newParams = newParams.set(protocolShare, Encoded.MASK_UINT16, OFFSET_PROTOCOL_SHARE);
newParams = newParams.set(maxVolatilityAccumulator, Encoded.MASK_UINT24, OFFSET_MAX_VOL_ACC);
newParams = newParams.set(protocolShare, Encoded.MASK_UINT14, OFFSET_PROTOCOL_SHARE);
newParams = newParams.set(maxVolatilityAccumulator, Encoded.MASK_UINT20, OFFSET_MAX_VOL_ACC);

return params.set(uint256(newParams), MASK_STATIC_PARAMETER, 0);
}
Expand Down
14 changes: 0 additions & 14 deletions test/LBToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -265,27 +265,13 @@ contract LBTokenTest is Test {
uint256[] memory ids = new uint256[](1);
uint256[] memory amounts = new uint256[](1);

vm.expectRevert(abi.encodeWithSelector(ILBToken.LBToken__AddressThisOrZero.selector));
lbToken.mintBatch(address(0), ids, amounts);

vm.expectRevert(abi.encodeWithSelector(ILBToken.LBToken__AddressThisOrZero.selector));
vm.prank(address(1));
lbToken.batchTransferFrom(address(1), address(0), ids, amounts);

vm.expectRevert(abi.encodeWithSelector(ILBToken.LBToken__AddressThisOrZero.selector));
vm.prank(address(1));
lbToken.batchBurnFrom(address(0), ids, amounts);

vm.expectRevert(abi.encodeWithSelector(ILBToken.LBToken__AddressThisOrZero.selector));
lbToken.mintBatch(address(lbToken), ids, amounts);

vm.expectRevert(abi.encodeWithSelector(ILBToken.LBToken__AddressThisOrZero.selector));
vm.prank(address(1));
lbToken.batchTransferFrom(address(1), address(lbToken), ids, amounts);

vm.expectRevert(abi.encodeWithSelector(ILBToken.LBToken__AddressThisOrZero.selector));
vm.prank(address(1));
lbToken.batchBurnFrom(address(lbToken), ids, amounts);
}

function testFuzz_SetApprovalOnSelf(address account) external {
Expand Down