8000 Check for a validity of a `consumer` under `accId` by martinkersner · Pull Request #530 · Bisonai/orakl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Check for a validity of a consumer under accId #530

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

Merged
merged 1 commit into from 8000
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions contracts/src/v0.1/Prepayment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,11 @@ contract Prepayment is Ownable, IPrepayment, ITypeAndVersion {
/**
* @inheritdoc IPrepayment
*/
function isValidAccount(uint64 accId) external view returns (bool) {
Account account = sAccIdToAccount[accId];
if (address(account) != address(0) || sIsTemporaryAccount[accId]) {
return true;
} else {
revert InvalidAccount();
}
function isValid(uint64 accId, address consumer) external view returns (bool) {
bool isValidRegular = sAccIdToAccount[accId].getNonce(consumer) != 0;
bool isValidTemporary = sAccIdToTmpAcc[accId].owner == msg.sender;

return isValidRegular || isValidTemporary;
}

/**
Expand Down Expand Up @@ -255,12 +253,7 @@ contract Prepayment is Ownable, IPrepayment, ITypeAndVersion {
* @inheritdoc IPrepayment
*/
function getNonce(uint64 accId, address consumer) external view returns (uint64) {
Account account = sAccIdToAccount[accId];
if (address(account) != address(0)) {
return sAccIdToAccount[accId].getNonce(consumer);
} else {
return 1;
}
return sAccIdToAccount[accId].getNonce(consumer);
}

/**
Expand Down
8 changes: 1 addition & 7 deletions contracts/src/v0.1/RequestResponseCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,7 @@ contract RequestResponseCoordinator is
uint32 callbackGasLimit,
bool isDirectPayment
) internal returns (uint256) {
sPrepayment.isValidAccount(accId);

// Its important to ensure that the consumer is in fact who they say they
// are, otherwise they could use someone else's account balance.
// A nonce of 0 indicates consumer is not allocated to the acc.
uint64 currentNonce = sPrepayment.getNonce(accId, msg.sender);
if (currentNonce == 0) {
if (!sPrepayment.isValid(accId, msg.sender)) {
revert InvalidConsumer(accId, msg.sender);
}

Expand Down
9 changes: 2 additions & 7 deletions contracts/src/v0.1/VRFCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -482,16 +482,11 @@ contract VRFCoordinator is Ownable, ICoordinatorBase, ITypeAndVersion, IVRFCoord
uint32 numWords,
bool isDirectPayment
) internal returns (uint256) {
sPrepayment.isValidAccount(accId);

// Its important to ensure that the consumer is in fact who they say they
// are, otherwise they could use someone else's account balance.
// A nonce of 0 indicates consumer is not allocated to the acc.
uint64 currentNonce = sPrepayment.getNonce(accId, msg.sender);
if (currentNonce == 0) {
if (!sPrepayment.isValid(accId, msg.sender)) {
revert InvalidConsumer(accId, msg.sender);
}

// TODO update comment
// No lower bound on the requested gas limit. A user could request 0
// and they would simply be billed for the proof verification and wouldn't be
// able to do anything with the random value.
Expand Down
17 changes: 8 additions & 9 deletions contracts/src/v0.1/interfaces/IPrepayment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ interface IPrepayment {
/// READ-ONLY FUNCTIONS /////////////////////////////////////////////////////

/**
* @notice Returns `true` when given `accId` is valid, otherwise reverts.
* @notice Returns `true` when a `consumer` is registered under
* @notice `accId`, otherwise returns `false`.
* @dev This function can be used for checking validity of both
* @dev [regular] and [temporary] account.
* @param accId - ID of the account
*/
function isValidAccount(uint64 accId) external view returns (bool);
function isValid(uint64 accId, address consumer) external view returns (bool);

/**
* @notice Returns the balance of given account.
Expand Down Expand Up @@ -61,13 +62,11 @@ interface IPrepayment {

/**
* @notice Get nonce for specified `consumer` in account denoted by `accId`.
* @dev This function is meant to be used for both [regular] and
* @dev [temporary] account. In case of [regular] account, we keep
* @dev track of nonces for every consumer inside of the
* @dev account. [temporary] account is expected to be used only
* @dev once, therefore we do not keep track of nonce, and always return 1.
* @dev We do not check on validity of the `accId`, therefore when
* @dev a an invalid `accId` is passed, nonce equal to 1 is returned.
* @dev This function is meant to be used only for [regular]
* @dev account. [temporary] account does not have a notion of a nonce.
* @dev When an invalid `accId` is passed, transaction is
* @dev reverted. When an invalid `consumer` is passed, 0 zero
* @dev nonce is returned that represents an unregistered consumer.
* @param accId - ID of the account
* @param consumer - consumer address
*/
Expand Down
0