Skip to content

Staker.sol: Cache marketIndex #63

@code423n4

Description

@code423n4

Handle

hickuphh3

Vulnerability details

Impact

Market index is retrieved from storage twice in stakeFromUser(), withdraw() and withdrawAll(). Its value can be cached first before calling updateSystemState().

Recommended Mitigation Steps

function stakeFromUser(address from, uint256 amount) public virtual override onlyValidSynthetic((msg.sender)) {
	uint32 marketIndex = marketIndexOfToken[msg.sender];
	ILongShort(longShort).updateSystemState(marketIndex );
  _stake(msg.sender, marketIndex, amount, from);
}

function withdraw(address token, uint256 amount) external {
	uint32 marketIndex = marketIndexOfToken[token];
  ILongShort(longShort).updateSystemState(marketIndex );
	...
}

function withdrawAll(address token) external {
	uint32 marketIndex = marketIndexOfToken[token];
  ILongShort(longShort).updateSystemState(marketIndex );
	...
}

    

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