Skip to content

Pass time delta into internal functions #42

Open

Description

@code423n4

Handle

0xImpostor

Vulnerability details

Impact

Small gas optimization if you pass the time delta into _setCurrentAccumulativeIssuancePerStakeStakedSynthSnapshot and _calculateNewCumulativeIssuancePerStakedSynth

Proof of Concept

https://github.com/code-423n4/2021-08-floatcapital/blob/main/contracts/contracts/Staker.sol#L635

// https://github.com/code-423n4/2021-08-floatcapital/blob/main/contracts/contracts/Staker.sol#L635
uint256 **timeDelta** = _calculateTimeDeltaFromLastAccumulativeIssuancePerStakedSynthSnapshot(marketIndex);
if (**timeDelta** > 0) {
	_setCurrentAccumulativeIssuancePerStakeStakedSynthSnapshot(
    marketIndex,
    longPrice,
    shortPrice,
    longValue,
    shortValue,
		**timeDelta**
  );
}

// https://github.com/code-423n4/2021-08-floatcapital/blob/main/contracts/contracts/Staker.sol#L567
function _setCurrentAccumulativeIssuancePerStakeStakedSynthSnapshot(
  uint32 marketIndex,
  uint256 longPrice,
  uint256 shortPrice,
  uint256 longValue,
  uint256 shortValue,
	uint256 **timeDelta**
) internal virtual {
	(
    uint256 newLongAccumulativeValue,
    uint256 newShortAccumulativeValue
  ) = _calculateNewCumulativeIssuancePerStakedSynth(marketIndex, longPrice, shortPrice, longValue, shortValue, **timeDelta**);
	...
}

// https://github.com/code-423n4/2021-08-floatcapital/blob/main/contracts/contracts/Staker.sol#L531
function _calculateNewCumulativeIssuancePerStakedSynth(
  uint32 marketIndex,
  uint256 longPrice,
  uint256 shortPrice,
  uint256 longValue,
  uint256 shortValue,
	**uint256 timeDelta,**
) internal view virtual returns (uint256 longCumulativeRates, uint256 shortCumulativeRates) {
  // Compute the current 'r' value for float issuance per second.
  (uint256 longFloatPerSecond, uint256 shortFloatPerSecond) = _calculateFloatPerSecond(
    marketIndex,
    longPrice,
    shortPrice,
    longValue,
    shortValue
  );
	...
}

Tools Used

manual analysis

Activity

  1. added a commit that references this issue on Aug 10, 2021
  2. JasoonS commented on Aug 11, 2021

    @JasoonS
    Collaborator

    I believe it is unfair game to award bounty for this. It is written on the line above. All wardens who read the contracts saw this.

  3. JasoonS commented on Aug 11, 2021

    @JasoonS
    Collaborator
  4. 0xean commented on Aug 25, 2021

    @0xean
    Collaborator

    Awarding to warden based on the fact that they are being asked to review the current code base for gas optimizations and even if this optimization was commented, it wasn't implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions