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

Contract/nft querier #184

Draft
wants to merge 18 commits into
base: feat/audit-fixes-oak-2024-11
Choose a base branch
from

Conversation

faust403
Copy link
Member

No description provided.

@faust403 faust403 marked this pull request as draft September 20, 2024 13:13
@faust403 faust403 marked this pull request as ready for review September 23, 2024 08:45
@faust403 faust403 requested review from ratik, foxpy and albertandrejev and removed request for foxpy September 23, 2024 08:47
Comment on lines +32 to +35
state::{
factory::{State, STATE},
pump::PumpTimeout,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seem to be out of the scope of this PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving messages from factory to package

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also as far as I remember it was made in the other pr

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's related because it's used in the contract itself to query a factory state

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it was done in #81. I guess it's okay to do that in both of these PR's and merge updates between them in future

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, my bad. IC. so this way I see you are already trying to query factory in phonebook-like manner. this way I think it we be great to adopt actual phonebook implementation

@faust403 faust403 changed the base branch from main to feat/audit-fixes-oak-2024-11 November 25, 2024 12:57
contracts/nft-querier/Cargo.toml Outdated Show resolved Hide resolved
contracts/nft-querier/src/state.rs Outdated Show resolved Hide resolved
contracts/nft-querier/src/contract.rs Outdated Show resolved Hide resolved
Err(_) => return Err(crate::error::ContractError::UnknownNftId {}),
};

let batch_id = nft_details.info.extension.unwrap().batch_id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment explaining why a call to this .unwrap() is safe (because our NFT contract always uses the extension field).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of this review request was to make it obvious for anyone reading the code why a call to .unwrap() is safe. I don't think your current comment is descriptive enough :D

Please write explicitly that an NFT contract we are interacting with here is written and controlled fully by us, and it always uses an extension.

contracts/nft-querier/src/contract.rs Outdated Show resolved Hide resolved
contracts/nft-querier/src/contract.rs Outdated Show resolved Hide resolved
contracts/nft-querier/src/contract.rs Outdated Show resolved Hide resolved
contracts/nft-querier/src/tests.rs Outdated Show resolved Hide resolved
contracts/nft-querier/src/tests.rs Outdated Show resolved Hide resolved
integration_tests/package.json Outdated Show resolved Hide resolved
faust403 and others added 3 commits November 25, 2024 15:59
Co-authored-by: Murad <muradkarammaev@gmail.com>
Co-authored-by: Murad <muradkarammaev@gmail.com>
@faust403 faust403 requested a review from foxpy November 25, 2024 15:23

#[cw_serde]
pub struct InstantiateMsg {
pub factory_contract: Addr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never accept Addr from external sources. There are a few basic rules to follow:

  • if you receive an address from an external source, it must be of type String. Examples of external sources: ExecuteMsg, QueryMsg, InstantiateMsg, etc.;
  • once you receive an address from an external source, run deps.api.addr_validate() on it to convert it into cosmwasm_std::Addr;
  • if you need to save an address to persistent storage, save it as Addr.
Suggested change
pub factory_contract: Addr,
pub factory_contract: String,

#[cw_ownable_execute]
#[cw_serde]
pub enum ExecuteMsg {
UpdateConfig { new_config: Config },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also applies here. Since in this context a struct of Config is used as an external source, you are at risk of accepting an unvalidated Addr.

Normally, in other contracts, we define a separate UpdateConfig struct to mitigate this issue.

@oldremez oldremez marked this pull request as draft December 2, 2024 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants