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

Disallow the same bridge on one chain: #4720

Merged
merged 2 commits into from
Oct 2, 2023

Conversation

seelabs
Copy link
Collaborator

@seelabs seelabs commented Sep 21, 2023

Before this patch, two door accounts on the same chain could could own the same bridge spec (of course, one would have to be the issuer and one would have to be the locker). While this is silly, it does not violate any bridge invariants. However, on further review if we allow this then the claim transactions would need to change. Since it's hard to see a use case for two doors to own the same bridge, this patch disallows it. (The transaction will return tecDUPLICATE).

  • [x ] Bug fix (non-breaking change which fixes an issue)

@@ -631,10 +632,12 @@ struct XChain_test : public beast::unit_test::suite,
env.tx(create_bridge(a1, bridge(a1, GUSD, B, BUSD))).close();
env.tx(create_bridge(a2, bridge(a2, GUSD, B, BUSD))).close();

// Add the exact same bridge to two different accoutns (one must locking
// account and one must be issuing)
// Add the exact same bridge to two different accoutns (one locking
Copy link
Collaborator

Choose a reason for hiding this comment

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

While you're here:

Suggested change
// Add the exact same bridge to two different accoutns (one locking
// Add the exact same bridge to two different accounts (one locking

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 211ccc6fd9 [fold] Add additional test

Comment on lines 637 to +642
env.tx(create_bridge(a3, bridge(a3, GUSD, a4, a4["USD"]))).close();
env.tx(create_bridge(a4, bridge(a3, GUSD, a4, a4["USD"]))).close();
env.tx(create_bridge(a4, bridge(a3, GUSD, a4, a4["USD"])),
ter(tecDUPLICATE))
.close();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps this should check the reverse situation compared to the above test change - issuing chain then locking chain.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 211ccc6fd9 [fold] Add additional test

@intelliot intelliot added this to the 2.0 milestone Sep 21, 2023
Copy link
Collaborator

@scottschurr scottschurr left a comment

Choose a reason for hiding this comment

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

LGTM 👍. I've offered a small optimization to consider, but it's at your discretion.

{
return tecDUPLICATE;
auto hasBridge = [&](STXChainBridge::ChainType ct) -> bool {
return !!ctx.view.read(keylet::bridge(bridgeSpec, ct));
Copy link
Collaborator

Choose a reason for hiding this comment

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

As a small optimization, consider calling ctx.view.exists() instead, like this:

return ctx.view.exists(keylet::bridge(bridgeSpec, ct));

This will avoid deserializing the bridge to check the LedgerEntryType. Just a thought.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Love it. Fixed in 8bbf7b9e21 [fold] Use exists instead of read to check if ledger object exists

Copy link
Collaborator

@scottschurr scottschurr left a comment

Choose a reason for hiding this comment

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

👍 Looks great.

Before this patch, two door accounts on the same chain could could own
the same bridge spec (of course, one would have to be the issuer and one
would have to be the locker). While this is silly, it does not violate
any bridge invariants. However, on further review if we allow this then
the `claim` transactions would need to change. Since it's hard to see a
use case for two doors to own the same bridge, this patch disallows
it. (The transaction will return tecDUPLICATE).
@seelabs seelabs force-pushed the xbridge-disallow-same-bridge branch from 8bbf7b9 to df63e1f Compare September 28, 2023 15:06
@seelabs
Copy link
Collaborator Author

seelabs commented Sep 28, 2023

Squashed and rebased on the latest dev. This is ready to merge into develop.

@seelabs seelabs added the Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. label Sep 28, 2023
@intelliot intelliot merged commit 925aca7 into XRPLF:develop Oct 2, 2023
@intelliot intelliot mentioned this pull request Oct 17, 2023
1 task
@intelliot
Copy link
Collaborator

note: have tests for this (Ram)

sophiax851 pushed a commit to sophiax851/rippled that referenced this pull request Jun 12, 2024
Modify the `XChainBridge` amendment.

Before this patch, two door accounts on the same chain could could own
the same bridge spec (of course, one would have to be the issuer and one
would have to be the locker). While this is silly, it does not violate
any bridge invariants. However, on further review, if we allow this then
the `claim` transactions would need to change. Since it's hard to see a
use case for two doors to own the same bridge, this patch disallows
it. (The transaction will return tecDUPLICATE).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants