update() wrong privilege control
The OracleFactory contract's update function calls oracle.update, but oracle.update is restricted to the factory owner, not the factory contract itself. This prevents OracleFactory.update from ever succeeding, so the factory cannot add a new oracle provider.
Source: https://github.com/sherlock-audit/2023-07-perennial-judging/issues/121
Found by
bin2chen
oracle.update() wrong privilege control
lead to OracleFactory.update() unable to add oracleProvider
Vulnerability Detail
in OracleFactory.update() will call oracle.update()
contract OracleFactory is IOracleFactory, Factory {
...
function update(bytes32 id, IOracleProviderFactory factory) external onlyOwner {
if (!factories[factory]) revert OracleFactoryNotRegisteredError();
if (oracles[id] == IOracleProvider(address(0))) revert OracleFactoryNotCreatedError();
IOracleProvider oracleProvider = factory.oracles(id);
if (oracleProvider == IOracleProvider(address(0))) revert OracleFactoryInvalidIdError();
IOracle oracle = IOracle(address(oracles[id]));
@> oracle.update(oracleProvider);
}
But oracle.update() permission is needed for OracleFactory.owner() and not OracleFactory itself.
@> function update(IOracleProvider newProvider) external onlyOwner {
_updateCurrent(newProvider);
_updateLatest(newProvider.latest());
}
modifier onlyOwner {
@> if (msg.sender != factory().owner()) revert InstanceNotOwnerError(msg.sender);
_;
}
This results in OracleFactory not being able to do update().
Suggest changing the limit of oracle.update() to factory().
Impact
OracleFactory.update() unable to add IOracleProvider
Code Snippet
Tool used
Manual Review
Recommendation
contract Oracle is IOracle, Instance {
...
- function update(IOracleProvider newProvider) external onlyOwner {
+ function update(IOracleProvider newProvider) external {
+ require(msg.sender == factory(),"invalid sender");
_updateCurrent(newProvider);
_updateLatest(newProvider.latest());
}
Discussion
sherlock-admin
1 comment(s) were left on this issue during the judging contest.
141345 commented:
m
arjun-io
Fixed: https://github.com/equilibria-xyz/perennial-v2/pull/81
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
The oracle.update function's access control checks msg.sender against factory().owner() instead of allowing the factory contract itself.
Impact
OracleFactory.update cannot add a new IOracleProvider, so the factory's update functionality is broken.
What the attacker needed
None
The fix
The fix was to change oracle.update to allow calls from the factory contract itself, as shown in the recommendation and confirmed by the fix link.
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.
Smart contracts often have functions that only certain addresses can call. Here, the oracle contract only lets the factory's owner call update, but the factory contract itself tries to call it. Since the factory is not the owner, the call fails, and the factory cannot perform its intended update.
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.