rippled
XChainBridge.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2022 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_TX_XCHAINBRIDGE_H_INCLUDED
21 #define RIPPLE_TX_XCHAINBRIDGE_H_INCLUDED
22 
23 #include <ripple/app/tx/impl/Transactor.h>
24 #include <ripple/protocol/SField.h>
25 #include <ripple/protocol/XChainAttestations.h>
26 
27 namespace ripple {
28 
29 constexpr size_t xbridgeMaxAccountCreateClaims = 128;
30 
31 // Attach a new bridge to a door account. Once this is done, the cross-chain
32 // transfer transactions may be used to transfer funds from this account.
34 {
35 public:
37 
39  {
40  }
41 
42  static NotTEC
43  preflight(PreflightContext const& ctx);
44 
45  static TER
46  preclaim(PreclaimContext const& ctx);
47 
48  TER
49  doApply() override;
50 };
51 
52 class BridgeModify : public Transactor
53 {
54 public:
56 
57  explicit BridgeModify(ApplyContext& ctx) : Transactor(ctx)
58  {
59  }
60 
61  static NotTEC
62  preflight(PreflightContext const& ctx);
63 
64  static TER
65  preclaim(PreclaimContext const& ctx);
66 
67  TER
68  doApply() override;
69 };
70 //------------------------------------------------------------------------------
71 
72 // Claim funds from a `XChainCommit` transaction. This is normally not needed,
73 // but may be used to handle transaction failures or if the destination account
74 // was not specified in the `XChainCommit` transaction. It may only be used
75 // after a quorum of signatures have been sent from the witness servers.
76 //
77 // If the transaction succeeds in moving funds, the referenced `XChainClaimID`
78 // ledger object will be destroyed. This prevents transaction replay. If the
79 // transaction fails, the `XChainClaimID` will not be destroyed and the
80 // transaction may be re-run with different parameters.
81 class XChainClaim : public Transactor
82 {
83 public:
84  // Blocker since we cannot accurately calculate the consequences
86 
87  explicit XChainClaim(ApplyContext& ctx) : Transactor(ctx)
88  {
89  }
90 
91  static NotTEC
92  preflight(PreflightContext const& ctx);
93 
94  static TER
95  preclaim(PreclaimContext const& ctx);
96 
97  TER
98  doApply() override;
99 };
100 
101 //------------------------------------------------------------------------------
102 
103 // Put assets into trust on the locking-chain so they may be wrapped on the
104 // issuing-chain, or return wrapped assets on the issuing-chain so they can be
105 // unlocked on the locking-chain. The second step in a cross-chain transfer.
106 class XChainCommit : public Transactor
107 {
108 public:
110 
111  static TxConsequences
113 
114  explicit XChainCommit(ApplyContext& ctx) : Transactor(ctx)
115  {
116  }
117 
118  static NotTEC
119  preflight(PreflightContext const& ctx);
120 
121  static TER
122  preclaim(PreclaimContext const& ctx);
123 
124  TER
125  doApply() override;
126 };
127 
128 //------------------------------------------------------------------------------
129 
130 // Create a new claim id owned by the account. This is the first step in a
131 // cross-chain transfer. The claim id must be created on the destination chain
132 // before the `XChainCommit` transaction (which must reference this number) can
133 // be sent on the source chain. The account that will send the `XChainCommit` on
134 // the source chain must be specified in this transaction (see note on the
135 // `SourceAccount` field in the `XChainClaimID` ledger object for
136 // justification). The actual sequence number must be retrieved from a validated
137 // ledger.
139 {
140 public:
142 
144  {
145  }
146 
147  static NotTEC
148  preflight(PreflightContext const& ctx);
149 
150  static TER
151  preclaim(PreclaimContext const& ctx);
152 
153  TER
154  doApply() override;
155 };
156 
157 //------------------------------------------------------------------------------
158 
159 // Provide attestations from a witness server attesting to events on
160 // the other chain. The signatures must be from one of the keys on the door's
161 // signer's list at the time the signature was provided. However, if the
162 // signature list changes between the time the signature was submitted and the
163 // quorum is reached, the new signature set is used and some of the currently
164 // collected signatures may be removed. Also note the reward is only sent to
165 // accounts that have keys on the current list.
167 {
168 public:
169  // Blocker since we cannot accurately calculate the consequences
171 
173  {
174  }
175 
176  static NotTEC
177  preflight(PreflightContext const& ctx);
178 
179  static TER
180  preclaim(PreclaimContext const& ctx);
181 
182  TER
183  doApply() override;
184 };
185 
187 {
188 public:
189  // Blocker since we cannot accurately calculate the consequences
191 
193  : Transactor(ctx)
194  {
195  }
196 
197  static NotTEC
198  preflight(PreflightContext const& ctx);
199 
200  static TER
201  preclaim(PreclaimContext const& ctx);
202 
203  TER
204  doApply() override;
205 };
206 
207 //------------------------------------------------------------------------------
208 
209 // This is a special transaction used for creating accounts through a
210 // cross-chain transfer. A normal cross-chain transfer requires a "chain claim
211 // id" (which requires an existing account on the destination chain). One
212 // purpose of the "chain claim id" is to prevent transaction replay. For this
213 // transaction, we use a different mechanism: the accounts must be claimed on
214 // the destination chain in the same order that the `XChainCreateAccountCommit`
215 // transactions occurred on the source chain.
216 //
217 // This transaction can only be used for XRP to XRP bridges.
218 //
219 // IMPORTANT: This transaction should only be enabled if the witness
220 // attestations will be reliably delivered to the destination chain. If the
221 // signatures are not delivered (for example, the chain relies on user wallets
222 // to collect signatures) then account creation would be blocked for all
223 // transactions that happened after the one waiting on attestations. This could
224 // be used maliciously. To disable this transaction on XRP to XRP bridges, the
225 // bridge's `MinAccountCreateAmount` should not be present.
226 //
227 // Note: If this account already exists, the XRP is transferred to the existing
228 // account. However, note that unlike the `XChainCommit` transaction, there is
229 // no error handling mechanism. If the claim transaction fails, there is no
230 // mechanism for refunds. The funds are permanently lost. This transaction
231 // should still only be used for account creation.
233 {
234 public:
236 
238  {
239  }
240 
241  static NotTEC
242  preflight(PreflightContext const& ctx);
243 
244  static TER
245  preclaim(PreclaimContext const& ctx);
246 
247  TER
248  doApply() override;
249 };
250 
251 //------------------------------------------------------------------------------
252 
253 } // namespace ripple
254 
255 #endif
ripple::XChainClaim::doApply
TER doApply() override
Definition: XChainBridge.cpp:1767
ripple::Transactor::Blocker
@ Blocker
Definition: Transactor.h:101
ripple::XChainClaim
Definition: XChainBridge.h:81
ripple::XChainCommit::ConsequencesFactory
static constexpr ConsequencesFactoryType ConsequencesFactory
Definition: XChainBridge.h:109
ripple::Transactor
Definition: Transactor.h:85
ripple::XChainAddClaimAttestation::ConsequencesFactory
static constexpr ConsequencesFactoryType ConsequencesFactory
Definition: XChainBridge.h:170
ripple::XChainCreateBridge::ConsequencesFactory
static constexpr ConsequencesFactoryType ConsequencesFactory
Definition: XChainBridge.h:36
ripple::XChainCreateAccountCommit::ConsequencesFactory
static constexpr ConsequencesFactoryType ConsequencesFactory
Definition: XChainBridge.h:235
ripple::XChainCreateClaimID::ConsequencesFactory
static constexpr ConsequencesFactoryType ConsequencesFactory
Definition: XChainBridge.h:141
ripple::XChainCreateClaimID::doApply
TER doApply() override
Definition: XChainBridge.cpp:2067
ripple::XChainCommit::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition: XChainBridge.cpp:1921
ripple::BridgeModify
Definition: XChainBridge.h:52
ripple::XChainCreateAccountCommit::XChainCreateAccountCommit
XChainCreateAccountCommit(ApplyContext &ctx)
Definition: XChainBridge.h:237
ripple::XChainCommit::XChainCommit
XChainCommit(ApplyContext &ctx)
Definition: XChainBridge.h:114
ripple::XChainCommit
Definition: XChainBridge.h:106
ripple::XChainAddClaimAttestation::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition: XChainBridge.cpp:2131
ripple::XChainCreateBridge::XChainCreateBridge
XChainCreateBridge(ApplyContext &ctx)
Definition: XChainBridge.h:38
ripple::XChainCreateBridge::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition: XChainBridge.cpp:1367
ripple::XChainCreateAccountCommit::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition: XChainBridge.cpp:2192
ripple::Transactor::ConsequencesFactoryType
ConsequencesFactoryType
Definition: Transactor.h:101
ripple::XChainClaim::XChainClaim
XChainClaim(ApplyContext &ctx)
Definition: XChainBridge.h:87
ripple::XChainCreateAccountCommit::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition: XChainBridge.cpp:2165
ripple::TERSubset
Definition: TER.h:380
ripple::XChainCreateBridge::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition: XChainBridge.cpp:1451
ripple::XChainCreateClaimID::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition: XChainBridge.cpp:2010
ripple::XChainClaim::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition: XChainBridge.cpp:1683
ripple::ApplyContext
State information when applying a tx.
Definition: ApplyContext.h:35
ripple::XChainAddAccountCreateAttestation::XChainAddAccountCreateAttestation
XChainAddAccountCreateAttestation(ApplyContext &ctx)
Definition: XChainBridge.h:192
ripple::BridgeModify::doApply
TER doApply() override
Definition: XChainBridge.cpp:1618
ripple::XChainClaim::ConsequencesFactory
static constexpr ConsequencesFactoryType ConsequencesFactory
Definition: XChainBridge.h:85
ripple::XChainAddClaimAttestation::XChainAddClaimAttestation
XChainAddClaimAttestation(ApplyContext &ctx)
Definition: XChainBridge.h:172
ripple::BridgeModify::ConsequencesFactory
static constexpr ConsequencesFactoryType ConsequencesFactory
Definition: XChainBridge.h:55
ripple::BridgeModify::BridgeModify
BridgeModify(ApplyContext &ctx)
Definition: XChainBridge.h:57
ripple::XChainAddAccountCreateAttestation
Definition: XChainBridge.h:186
ripple::XChainCreateBridge
Definition: XChainBridge.h:33
ripple::PreclaimContext
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:52
ripple::Transactor::Custom
@ Custom
Definition: Transactor.h:101
ripple::xbridgeMaxAccountCreateClaims
constexpr size_t xbridgeMaxAccountCreateClaims
Definition: XChainBridge.h:29
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::XChainCreateClaimID::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition: XChainBridge.cpp:2030
ripple::XChainCreateAccountCommit::doApply
TER doApply() override
Definition: XChainBridge.cpp:2251
ripple::XChainAddAccountCreateAttestation::ConsequencesFactory
static constexpr ConsequencesFactoryType ConsequencesFactory
Definition: XChainBridge.h:190
ripple::XChainAddAccountCreateAttestation::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition: XChainBridge.cpp:2151
ripple::XChainCreateClaimID
Definition: XChainBridge.h:138
ripple::Transactor::Normal
@ Normal
Definition: Transactor.h:101
ripple::XChainCommit::makeTxConsequences
static TxConsequences makeTxConsequences(PreflightContext const &ctx)
Definition: XChainBridge.cpp:1883
ripple::XChainCommit::doApply
TER doApply() override
Definition: XChainBridge.cpp:1966
ripple::XChainCreateClaimID::XChainCreateClaimID
XChainCreateClaimID(ApplyContext &ctx)
Definition: XChainBridge.h:143
ripple::XChainAddClaimAttestation::doApply
TER doApply() override
Definition: XChainBridge.cpp:2137
ripple::XChainCommit::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition: XChainBridge.cpp:1896
ripple::XChainCreateBridge::doApply
TER doApply() override
Definition: XChainBridge.cpp:1502
ripple::XChainAddAccountCreateAttestation::doApply
TER doApply() override
Definition: XChainBridge.cpp:2157
ripple::XChainAddClaimAttestation::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition: XChainBridge.cpp:2125
ripple::BridgeModify::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition: XChainBridge.cpp:1601
ripple::XChainCreateAccountCommit
Definition: XChainBridge.h:232
ripple::PreflightContext
State information when preflighting a tx.
Definition: Transactor.h:31
ripple::XChainAddClaimAttestation
Definition: XChainBridge.h:166
ripple::XChainClaim::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition: XChainBridge.cpp:1658
ripple::BridgeModify::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition: XChainBridge.cpp:1548
ripple::TxConsequences
Class describing the consequences to the account of applying a transaction if the transaction consume...
Definition: applySteps.h:45
ripple::XChainAddAccountCreateAttestation::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition: XChainBridge.cpp:2145