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

transaction vout duplication bug fix #1

Closed
wants to merge 1 commit into from
Closed

transaction vout duplication bug fix #1

wants to merge 1 commit into from

Conversation

rajarshimaitra
Copy link
Contributor

@dr-orlovsky dr-orlovsky self-assigned this Jan 27, 2021
@dr-orlovsky dr-orlovsky added the bug Something isn't working label Jan 27, 2021
@dr-orlovsky
Copy link
Member

Did you tried testing this against the case described in the original issue? (meaning that with this fix transaction output is not duplicated with transfer command)

Copy link
Member

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

I am afraid this is wrong and does not match the solution from the original issue:

The solution was to provide TxContainer with the correct vout. Since TxContainer takes vout as (fee+protocol_factor)%num outputs we must use this instead of either fee or protocol_factor (I propose the later) and set the other one to 0.

@rajarshimaitra
Copy link
Contributor Author

rajarshimaitra commented Jan 28, 2021

I haven't been able to test it cause I couldn't get rgb-cli bin compiled on master.

Sorry I am not seeing how this wrong. We are passing on fee and protocol_factor=0 to TxContainer. So the vout calculation in TxContainer should produce the same result as vout of anchor https://github.com/rgb-org/rgb-core/blob/0deefa7998ab5401f084e46970eb624538165cfd/src/stash/anchor.rs#L157
Instead of 0 fee we are passing on the correct fee and 0 as protocol_factor, which made sense to me. So both the derivation now should match.

What am I missing?

I also didn't get why protocol_factor was set to vout in previous version.

Since TxContainer takes vout as (fee+protocol_factor)%num outputs we must use this instead of either fee or protocol_factor (I propose the later) and set the other one to 0.

I am not sure why we should trick TxContainer with vout as protocol_factor. TxContainer doesn't hold vout directly, it calculates vout from fee and protcol_factor, so by passing the correct values in these two variables it should be able to calculate correct vout

Copy link
Contributor

@claudiosdc claudiosdc left a comment

Choose a reason for hiding this comment

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

I am afraid that this fix is not compatible with other parts of the RGB node code. So I am proposing some adjustments to it.

Comment on lines +148 to +150
// TODO: use enum instead of hardcoded value
let protocol_factor = 0;

Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think that setting the protocol_factor to zero is the best approach here. Besides, this is not compatible with what is done in the verify associated function of the Anchor structure.

So I propose that protocol_factor be initialize the same way that it is done there.

Suggested change
// TODO: use enum instead of hardcoded value
let protocol_factor = 0;
let protocol_factor = (
Uint256::from_be_bytes(*contract_id.as_slice()) % Uint256::from_u64(num_outs).unwrap()
).low_u64() as u32;

@@ -211,7 +212,7 @@ impl Anchor {
let mut container = TxContainer {
tx: tx.clone(),
fee,
protocol_factor: vout as u32,
protocol_factor: protocol_factor as u32,
Copy link
Contributor

Choose a reason for hiding this comment

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

According to my suggested change above, there would be no need to cast protocol_factor here. So, it should be written only as:

Suggested change
protocol_factor: protocol_factor as u32,
protocol_factor: protocol_factor,

@dr-orlovsky
Copy link
Member

Am I right that this PR was superceded by #2 and can be close dnow?

@claudiosdc
Copy link
Contributor

Am I right that this PR was superceded by #2 and can be close dnow?

Yes, that is correct.

@dr-orlovsky
Copy link
Member

Ok, closing in favor of merged #2

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.

Transaction output duplicated by 'fungible transfer'
3 participants