Skip to content

Commit

Permalink
remove ability for SeekerPowerOracle owner to set power
Browse files Browse the repository at this point in the history
  • Loading branch information
JCSanPedro committed Jan 16, 2024
1 parent a274ea0 commit 2f87c39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
18 changes: 9 additions & 9 deletions contracts/SeekerPowerOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "./interfaces/ISeekerPowerOracle.sol";

/**
* @notice Acts as a source of information for Seeker Powers. Allows setting
* a Seeker's power level via a restricted owner call. Seeker Power can also
* a Seeker's power level via a restricted oracle account call. Seeker Power can also
* be set by any account if the correct Oracle signature proof is provided.
*/
contract SeekerPowerOracle is ISeekerPowerOracle, Initializable, Ownable2StepUpgradeable {
Expand All @@ -33,15 +33,15 @@ contract SeekerPowerOracle is ISeekerPowerOracle, Initializable, Ownable2StepUpg

event SeekerPowerUpdated(uint256 indexed seekerId, uint256 indexed power);

error UnauthorizedRegisterSeekerPowerCall();
error NonceCannotBeReused();

function initialize(address _oracle) external initializer {
Ownable2StepUpgradeable.__Ownable2Step_init();

oracle = _oracle;
}

error UnauthorizedSetSeekerCall();
error NonceCannotBeReused();

/**
* @notice Sets the oracle account.
* @param _oracle The oracle account.
Expand All @@ -57,8 +57,8 @@ contract SeekerPowerOracle is ISeekerPowerOracle, Initializable, Ownable2StepUpg
* @param power The power level of the Seeker.
*/
function registerSeekerPowerRestricted(uint256 seekerId, uint256 power) external {
if (msg.sender != this.owner() && msg.sender != oracle) {
revert UnauthorizedSetSeekerCall();
if (msg.sender != oracle) {
revert UnauthorizedRegisterSeekerPowerCall();
}

seekerPowers[seekerId] = power;
Expand All @@ -85,13 +85,13 @@ contract SeekerPowerOracle is ISeekerPowerOracle, Initializable, Ownable2StepUpg
bytes32 ecdsaHash = ECDSA.toEthSignedMessageHash(proofMessage);

if (ECDSA.recover(ecdsaHash, proof) != oracle) {
revert UnauthorizedSetSeekerCall();
revert UnauthorizedRegisterSeekerPowerCall();
}

seekerPowers[seekerId] = power;
emit SeekerPowerUpdated(seekerId, power);

proofNonces[nonce] = oracle;

emit SeekerPowerUpdated(seekerId, power);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions test/seekerOracle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ describe('Seeker Power Oracle', () => {
expect(updatedPower).to.equal(seekerPower);
});

it('only allows registerSeekerPowerRestricted to be called by owner or oracle', async () => {
it('only allows registerSeekerPowerRestricted to be called by the oracle', async () => {
await expect(
contracts.seekerPowerOracle
.connect(accounts[2]) // unauthorized caller
.registerSeekerPowerRestricted(1, 2),
).to.be.revertedWithCustomError(
contracts.seekerPowerOracle,
'UnauthorizedSetSeekerCall',
'UnauthorizedRegisterSeekerPowerCall',
);
});

Expand Down Expand Up @@ -161,7 +161,7 @@ describe('Seeker Power Oracle', () => {
),
).to.be.revertedWithCustomError(
contracts.seekerPowerOracle,
'UnauthorizedSetSeekerCall',
'UnauthorizedRegisterSeekerPowerCall',
);

const validProof = await accounts[1].signMessage(
Expand Down
8 changes: 5 additions & 3 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Options = {
epochDuration?: number;
minimumStakeProportion?: number;
unlockDuration?: number;
oracle?: string;
seekerPowerOracleAccount?: string;
};

const initializeContracts = async function (
Expand All @@ -38,7 +38,7 @@ const initializeContracts = async function (

const minimumStakeProportion = opts.minimumStakeProportion ?? 2000;

const oracle = opts.oracle ?? deployer;
const seekerPowerOracleAccount = opts.seekerPowerOracleAccount ?? deployer;

const tokenAddress = await syloToken.getAddress();

Expand Down Expand Up @@ -126,7 +126,9 @@ const initializeContracts = async function (
{ from: deployer },
);
await authorizedAccounts.initialize({ from: deployer });
await seekerPowerOracle.initialize(oracle, { from: deployer });
await seekerPowerOracle.initialize(seekerPowerOracleAccount, {
from: deployer,
});

const TicketingFactory = await ethers.getContractFactory('SyloTicketing');
const syloTicketing = await TicketingFactory.deploy();
Expand Down

0 comments on commit 2f87c39

Please sign in to comment.