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

Missing custom error or require statement in onlyMinter modifier #165

Closed
code423n4 opened this issue Jan 27, 2023 · 2 comments
Closed

Missing custom error or require statement in onlyMinter modifier #165

code423n4 opened this issue Jan 27, 2023 · 2 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-608 edited-by-warden satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

code423n4 commented Jan 27, 2023

Lines of code

https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/RabbitHoleTickets.sol#L48
https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/RabbitHoleReceipt.sol#L59

Vulnerability details

Impact

Without custom error or require statement at modifier onlyMinter, anyone could mint a receipt in the RabbitHoleReceipt contract or a ticket in the RabbitHoleTickets contract.

Proof of Concept

For RabbitHoleReceipt add a test in RabbitHoleReceipt.spec.ts

describe('additional mint test', () => {
        it('check onlyMinter modifier', async () => {
              await RHReceipt.connect(minterAddress).mint(firstAddress.address, 'def456')
              expect(await RHReceipt.balanceOf(firstAddress.address)).to.eq(1)

              await RHReceipt.connect(firstAddress).mint(firstAddress.address, 'def456')
              expect(await RHReceipt.balanceOf(firstAddress.address)).to.eq(2)

              await RHReceipt.connect(royaltyRecipient).mint(firstAddress.address, 'def456')
              expect(await RHReceipt.balanceOf(firstAddress.address)).to.eq(3)

              expect(minterAddress.address != firstAddress.address && minterAddress.address != royaltyRecipient.address).to.equal(true)
         })
})

For RabbitHoleTickets add a test in RabbitHoleTickets.spec.ts

describe('additional mint test', () => {
        it('check onlyMinter modifier', async () => {
              await RHTickets.connect(minterAddress).mint(firstAddress.address, 1, 5, "0x")
              expect(await RHTickets.balanceOf(firstAddress.address, 1)).to.eq(5)

              await RHTickets.connect(firstAddress).mint(firstAddress.address, 1, 5, "0x")
              expect(await RHTickets.balanceOf(firstAddress.address, 1)).to.eq(10)

              await RHTickets.connect(royaltyRecipient).mint(firstAddress.address, 1, 5, "0x")
              expect(await RHTickets.balanceOf(firstAddress.address, 1)).to.eq(15)

              expect(minterAddress.address != firstAddress.address && minterAddress.address != royaltyRecipient.address).to.equal(true)
        })
})

As it is seen from these tests code, it is possible from anyone to call the mint operation in the RabbitHoleReceipt and RabbitHoleTickets (also, there is an additional except expect(minterAddress.address != firstAddress.address && minterAddress.address != royaltyRecipient.address).to.equal(true) which shows that addresses that call mint operation are different than minter address).

Tools Used

VSCode, Hardhat, Solidity Visual Developer plugin for VSCode

Recommended Mitigation Steps

Create and add a custom error in the if statement for a check is msg.sender different than minterAddress at lines RabbitHoleTickets.sol#L48 and RabbitHoleReceipt.sol#L59

modifier onlyMinter() {
       if (msg.sender != minterAddress) revert OnlyMinterAllowed();
       _;
}
@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Jan 27, 2023
code423n4 added a commit that referenced this issue Jan 27, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Feb 5, 2023

kirk-baird marked the issue as duplicate of #9

@c4-judge
Copy link
Contributor

kirk-baird marked the issue as satisfactory

@c4-judge c4-judge added satisfactory satisfies C4 submission criteria; eligible for awards duplicate-608 and removed duplicate-9 labels Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-608 edited-by-warden satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants