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

Fix blank transition builder #108

Closed
wants to merge 3 commits into from
Closed

Conversation

crisdut
Copy link
Member

@crisdut crisdut commented Oct 26, 2023

Description

This PR intent fix a blank transition builder when contract has another ifaceimpl. This particular case occurs when issuer issues many contracts with different ifaceimpl in the same UTXO.

CC @cryptoquick @dr-orlovsky

@codecov
Copy link

codecov bot commented Oct 26, 2023

Codecov Report

Merging #108 (a94dd7a) into master (e512508) will decrease coverage by 0.3%.
The diff coverage is 1.7%.

@@           Coverage Diff            @@
##           master    #108     +/-   ##
========================================
- Coverage    26.5%   26.2%   -0.3%     
========================================
  Files          39      39             
  Lines        4473    4523     +50     
========================================
- Hits         1187    1186      -1     
- Misses       3286    3337     +51     
Flag Coverage Δ
rust 26.2% <1.7%> (-0.3%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
std/src/interface/rgb21.rs 81.2% <0.0%> (-0.7%) ⬇️
std/src/stl/specs.rs 35.0% <16.7%> (-0.9%) ⬇️
std/src/persistence/hoard.rs 0.0% <0.0%> (ø)
std/src/persistence/inventory.rs 0.0% <0.0%> (ø)
std/src/interface/contract.rs 1.0% <0.0%> (-0.3%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -477,8 +477,9 @@ impl DivisibleAssetSpec {
pub fn details(&self) -> Option<&str> { self.naming.details.as_ref().map(|d| d.as_str()) }
}

#[derive(Clone, Eq, PartialEq, Debug, Default)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[derive(Wrapper, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, From, Debug)]
Copy link
Member

Choose a reason for hiding this comment

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

Why Default implementation is removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Default causes conflict with strict_dumb. Do you prefer maintain Default?

Copy link
Member

Choose a reason for hiding this comment

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

I think having default is better

#[derive(Clone, Eq, PartialEq, Debug, Default)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[derive(Wrapper, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, From, Debug)]
#[wrapper(Deref, Display)]
Copy link
Member

Choose a reason for hiding this comment

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

Since we are adding Wrapper we need to add FromStr here and remove manual FromStr implementation below

impl RicardianContract {
pub fn from_strict_val_unchecked(value: &StrictVal) -> Self {
let s = value.unwrap_string();
RicardianContract::from_str(&s).expect("invalid term data")
Copy link
Member

Choose a reason for hiding this comment

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

This will open a vulnerability where an attacker can send a malformed consignment and crash end-user wallets and nodes (DoS attack).

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't know, as I saw in several code snippets, I imagined that this was the correct implementation. What would be the alternative?

Copy link
Member

Choose a reason for hiding this comment

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

Why do you need an unchecked version?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have a method that extracts some information from the ContractIface::global method, and this method returns the StrictVal array. I use from_strict_val_unchecked to convert StrictVal to a specific structure.

Copy link
Member

Choose a reason for hiding this comment

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

Can you point specific place in code where you do that call?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Why you do not want to use try_from and just propagate the error?

pub fn data(
&self,
name: impl Into<FieldName>,
) -> Result<LargeVec<DataAllocation>, ContractError> {
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to add outpoint filter like in fungible method above

@@ -101,6 +101,9 @@ impl Allocation {
pub fn with(index: TokenIndex, fraction: OwnedFraction) -> Allocation {
Allocation(index, fraction)
}

pub fn token_id(self) -> TokenIndex { self.0 }
Copy link
Member

Choose a reason for hiding this comment

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

Id's are usually hashes, thus better to use the type name token_index

@dr-orlovsky
Copy link
Member

Can you please rebase on the master to reflect everything which has happened in v0.11 branch?

@dr-orlovsky dr-orlovsky added this to the v0.11.0 milestone Dec 30, 2023
@dr-orlovsky dr-orlovsky added the bug Something isn't working label Dec 30, 2023
@crisdut crisdut closed this Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants