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

The long open interest may exceed the max open interest limit #273

Closed
code423n4 opened this issue Dec 15, 2022 · 4 comments
Closed

The long open interest may exceed the max open interest limit #273

code423n4 opened this issue Dec 15, 2022 · 4 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-377 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/PairsContract.sol#L142

Vulnerability details

Impact

In Contract PairsContract, when updating the max open interest limit _idToOi[_asset][_tigAsset].maxOi, the contract did not check the long open interests of existing assets. This may result in the fact that some long open interests of existing assets will be higher than the allowed max open interest limit. This confuses the market.

Proof of Concept

Put the below test under describe('Protocol-only functions', function () { in test file: 02.PairsContract.js.

	it('Succeed if reducing max open interest limit to values lower than existing long open interest', async function () {
		await pairscontract.connect(owner).addAsset(99, 'XYZ/ABC', ethers.constants.AddressZero, ethers.utils.parseEther('1'), ethers.utils.parseEther('100'), 1e10, 3e9);
		await pairscontract.connect(owner).setProtocol(NewTrading.address);
		await pairscontract.connect(owner).setMaxOi(99, StableToken.address, ethers.utils.parseEther('2000')); //@audit - set initial max open interest limit
		await pairscontract.connect(NewTrading).modifyLongOi(99, StableToken.address, true, ethers.utils.parseEther('500'));  //@audit - set long open interest of asset
		let [longOi, shortOi] = await pairscontract.idToOi(99, StableToken.address);
		expect(longOi).to.equal(ethers.utils.parseEther('500'));
		await expect(pairscontract.connect(owner).setMaxOi(99, StableToken.address, ethers.utils.parseEther('1'))).to.be.not.reverted; //@audit - update max open interest limit to a level lower than exist long open interest
	});

Tools Used

Manual audit.

Recommended Mitigation Steps

Set the max open interest limit as constant/immutable, or adopt some strategies that can keep consistency between existing long open interests and the max open interest limit.

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Dec 15, 2022
code423n4 added a commit that referenced this issue Dec 15, 2022
@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as duplicate of #370

@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as duplicate of #377

@c4-judge c4-judge added duplicate-377 and removed duplicate-370 3 (High Risk) Assets can be stolen/lost/compromised directly labels Jan 15, 2023
@c4-judge
Copy link
Contributor

GalloDaSballo changed the severity to 2 (Med Risk)

@c4-judge c4-judge added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue labels Jan 15, 2023
@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-377 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants