The noContract modifier does not work as expected.
The noContract modifier in yVault and yVaultLPFarming uses isContract() to restrict access to externally owned accounts, but isContract() relies on code length, which is zero during contract construction. An attacker could deploy a contract that calls the protected functions from its constructor, bypassing the modifier.
Submitted by Wayne, also found by hyh, PPrieditis, rayn, smilingheretic, and Cr4ckM3_
yVault.sol#L61 yVaultLPFarming.sol#L54
The expectation of the noContract modifier is to allow access only to accounts inside EOA or Whitelist, if access is controlled using ! access control with _account.isContract(), then because isContract() gets the size of the code length of the account in question by relying on extcodesize/address.code.length, this means that the restriction can be bypassed when deploying a smart contract through the smart contract’s constructor call.
Recommended Mitigation Steps
Modify the code to require(msg.sender == tx.origin);
spaghettieth (JPEG’d) confirmed, but disagreed with Medium severity and commented:
The observations made in the issue are correct, but given how impractical it would be to make an autocompounder that bypasses the
noContractmodifier this issue should probably be severity 0. It’s worth mentioning that this behaviour was already known as outlined in the modifier’s documentation.
spaghettieth (JPEG’d) resolved and commented:
Fixed in jpegd/core#17.
I’m going to let this stand. Impractical or not, this is very easily exploited.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the use of isContract() (which checks code length) to distinguish contracts from externally owned accounts, because code length is zero during contract construction.
Impact
An attacker could bypass the noContract modifier by calling protected functions from within a contract's constructor, though the project argued this is impractical for an autocompounder.
What the attacker needed
Ability to deploy a smart contract
The fix
The code was fixed by changing the check to require that the caller is the transaction origin (tx.origin).
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract is a program on a blockchain. Some functions are meant to be callable only by regular user accounts, not by other contracts. The code tried to enforce this by checking if the caller has code, but during the moment a contract is being created, it has no code yet, so the check fails to block it.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.