-
Notifications
You must be signed in to change notification settings - Fork 1.6k
update preflight checks #6094
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
base: ripple/smart-escrow
Are you sure you want to change the base?
update preflight checks #6094
Conversation
| } | ||
| } | ||
|
|
||
| if (auto const err = credentials::checkFields(ctx.tx, ctx.j); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: changing the order of preflight checks doesn't have any impact on consensus
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## ripple/smart-escrow #6094 +/- ##
===================================================
Coverage 79.2% 79.3%
===================================================
Files 827 827
Lines 71270 71281 +11
Branches 8254 8251 -3
===================================================
+ Hits 56474 56492 +18
+ Misses 14796 14789 -7
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the preflight validation logic for Escrow transactions by introducing a new preflightSigValidated method for EscrowCreate and reorganizing validation checks between preflight and preflightSigValidated for both EscrowCreate and EscrowFinish.
- Adds
preflightSigValidatedmethod toEscrowCreatefor post-signature validation - Moves
ComputationAllowanceand credential field validation frompreflightSigValidatedtopreflightinEscrowFinish - Adds validation check to reject escrow creation when WASM runtime is disabled (
extension_compute_limit == 0) - Improves test code quality with const-correctness improvements
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/xrpld/app/tx/detail/Escrow.h | Adds declaration of preflightSigValidated method to EscrowCreate class |
| src/xrpld/app/tx/detail/Escrow.cpp | Implements preflightSigValidated for EscrowCreate, adds WASM runtime disabled check, and reorganizes validation checks in EscrowFinish |
| src/test/app/EscrowSmart_test.cpp | Adds test for WASM disabled scenario and improves const-correctness of test variables |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| // compute limit == 0 | ||
| Env env( | ||
| *this, | ||
| envconfig([](std::unique_ptr<Config> cfg) { | ||
| cfg->FEES.extension_compute_limit = 0; // WASM disabled | ||
| return cfg; | ||
| }), | ||
| features); | ||
| XRPAmount const txnFees = env.current()->fees().base + 1000; | ||
| // create escrow | ||
| env.fund(XRP(5000), alice, carol); | ||
|
|
||
| auto const escrowCreate = escrow::create(alice, carol, XRP(500)); | ||
|
|
||
| // 11-byte string | ||
| env(escrowCreate, | ||
| escrow::finish_function(wasmHex), | ||
| escrow::cancel_time(env.now() + 100s), | ||
| fee(txnFees), | ||
| ter(temINVALID)); | ||
| env.close(); | ||
| } |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for the new logic check when extension_size_limit == 0 (line 213 in Escrow.cpp). The test file includes a test for extension_compute_limit == 0 (lines 83-105) but doesn't test the scenario where extension_size_limit == 0. Consider adding a test case similar to the compute limit test to verify the behavior when size limit is set to 0.
| // validity of WASM code happens in `preflightSigValidated` | ||
| // (after the signature is checked) |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "validity of WASM code happens in preflightSigValidated (after the signature is checked)", but the WASM validation via preflightEscrowWasm is actually performed in both preflight (lines 227-234) and preflightSigValidated (lines 250-257), making this comment misleading. Either update the comment to accurately reflect the implementation, or remove the redundant validation from preflight as the comment suggests.
| // validity of WASM code happens in `preflightSigValidated` | |
| // (after the signature is checked) | |
| // Basic validity of WASM code is checked here in `preflight`, | |
| // and checked again in `preflightSigValidated` (after the signature is checked) |
src/xrpld/app/tx/detail/Escrow.cpp
Outdated
| HostFunctions mock; | ||
| auto const re = | ||
| preflightEscrowWasm(code, ESCROW_FUNCTION_NAME, {}, &mock, ctx.j); | ||
| if (!isTesSuccess(re)) | ||
| { | ||
| JLOG(ctx.j.debug()) << "EscrowCreate.FinishFunction bad WASM"; | ||
| return re; | ||
| } |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The WASM validation logic is duplicated between preflight (lines 227-234) and preflightSigValidated (lines 250-257). The comment on line 235 states "validity of WASM code happens in preflightSigValidated", but the same preflightEscrowWasm call with identical parameters is executed in both functions. This duplication means the WASM validation is performed twice, which is inefficient.
Consider removing the validation from preflight and keeping only the one in preflightSigValidated as intended by the comment, or clarify if there's a distinction between the two validations that isn't apparent from the code.
| HostFunctions mock; | |
| auto const re = | |
| preflightEscrowWasm(code, ESCROW_FUNCTION_NAME, {}, &mock, ctx.j); | |
| if (!isTesSuccess(re)) | |
| { | |
| JLOG(ctx.j.debug()) << "EscrowCreate.FinishFunction bad WASM"; | |
| return re; | |
| } |
src/xrpld/app/tx/detail/Escrow.cpp
Outdated
| if (code.size() == 0 || | ||
| ctx.app.config().FEES.extension_size_limit == 0 || |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Inconsistent handling of WASM disabled states. When extension_compute_limit == 0, the code returns temINVALID with a clear message "WASM runtime disabled by fee voting" (lines 221-225). However, when extension_size_limit == 0, it's implicitly caught by the size check on line 214 and returns temMALFORMED with message "bad size", which doesn't clearly indicate that WASM is disabled.
Consider adding an explicit check for extension_size_limit == 0 similar to the compute limit check, returning temINVALID with a descriptive message for consistency and clarity.
| if (code.size() == 0 || | |
| ctx.app.config().FEES.extension_size_limit == 0 || | |
| if (ctx.app.config().FEES.extension_size_limit == 0) | |
| { | |
| JLOG(ctx.j.debug()) << "WASM runtime disabled by fee voting (size limit)"; | |
| return temINVALID; | |
| } | |
| if (code.size() == 0 || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/xrpld/app/tx/detail/Escrow.cpp
Outdated
|
|
||
| auto const code = ctx.tx.getFieldVL(sfFinishFunction); | ||
| if (code.size() == 0 || | ||
| ctx.app.config().FEES.extension_size_limit == 0 || |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant check: extension_size_limit == 0 is already checked at lines 211-216. This duplicate check on line 220 is unnecessary since if extension_size_limit is 0, the function would have already returned temINVALID above.
| ctx.app.config().FEES.extension_size_limit == 0 || |
src/test/app/EscrowSmart_test.cpp
Outdated
|
|
||
| auto const escrowCreate = escrow::create(alice, carol, XRP(500)); | ||
|
|
||
| // 11-byte string |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misleading comment: The comment says "11-byte string" but the actual test data is "AA" which is only 2 bytes (or 1 byte if treated as hex). This comment should be updated or removed as it doesn't accurately describe the test input.
| // 11-byte string | |
| // 2-byte string |
High Level Overview of Change
Context of Change
Type of Change
.gitignore, formatting, dropping support for older tooling)API Impact
libxrplchange (any change that may affectlibxrplor dependents oflibxrpl)