starknet_api: do not panic on malformed resource_bounds in tx json deserializer#14412
starknet_api: do not panic on malformed resource_bounds in tx json deserializer#14412avi-starkware wants to merge 1 commit into
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
Artifacts upload workflows: |
PR SummaryLow Risk Overview The helper now returns early if A regression test asserts no panic and Reviewed by Cursor Bugbot for commit 94bd28e. Bugbot is set up for automated code reviews on this repo. Configure here. |
…serializer Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
0cd1903 to
7b6e416
Compare
d3fbe70 to
94bd28e
Compare
AvivYossef-starkware
left a comment
There was a problem hiding this comment.
@AvivYossef-starkware reviewed 2 files and all commit messages, and made 3 comments.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on avi-starkware).
crates/starknet_api/src/serde_utils.rs line 165 at r1 (raw file):
/// Input may be attacker-controlled (e.g. an unparsable transaction body received over HTTP), so /// a missing or non-object `resource_bounds` field must not panic; the transaction is left /// unchanged and the typed deserialization that follows reports the error.
I`d remove it
Code quote:
/// Input may be attacker-controlled (e.g. an unparsable transaction body received over HTTP), so
/// a missing or non-object `resource_bounds` field must not panic; the transaction is left
/// unchanged and the typed deserialization that follows reports the error.crates/starknet_api/src/serde_utils.rs line 170 at r1 (raw file):
raw_transaction.get_mut("resource_bounds").and_then(Value::as_object_mut) else { return;
Shouldn't it be an error? Before we panicked
Code quote:
return;crates/starknet_api/src/serde_utils_test.rs line 202 at r1 (raw file):
let raw_transaction = serde_json::json!({"type": "INVOKE", "version": "0x3", "resource_bounds": 5}); assert!(deserialize_transaction_json_to_starknet_api_tx(raw_transaction).is_err());
I think you can remove it
Code quote:
// resource_bounds is not an object.
let raw_transaction =
serde_json::json!({"type": "INVOKE", "version": "0x3", "resource_bounds": 5});
assert!(deserialize_transaction_json_to_starknet_api_tx(raw_transaction).is_err());
Why
upper_case_resource_bounds_namespanics via.expect()when a V3 transaction JSON lacks aresource_boundsfield, when the field is not an object, or whenl1_gasis present withoutl2_gas. This is reachable from user-controlled input:apollo_http_server's add-transaction endpoint feeds the raw request body todeserialize_transaction_json_to_starknet_api_txon its deprecated-transaction metrics path, so the body{"type":"INVOKE","version":"0x3"}panics the serving task on every node. The panic predates the move intostarknet_api(#14408), but apub fn … -> serde_json::Resultin a foundational crate must not hide panic paths — new callers will trust the signature.What
upper_case_resource_bounds_namesnow leaves the transaction unchanged whenresource_boundsis missing or not an object, and normalizes each resource-bound key independently. The typed deserialization that follows remains the authority on required fields and reports the error — malformed input now yieldsErrinstead of a panic.l1_gaswithoutl2_gas), assertingErr.Behavior for well-formed input is unchanged:
blockifier_reexecution'sraw_rpc_json_testfixture suite (real invoke/declare/deploy-account/L1-handler JSONs across versions) passes unmodified.Validation
cargo test -p starknet_api— 88 passed, 0 failed.cargo test -p blockifier_reexecution raw_rpc— 12 passed (happy-path parity).cargo test -p apollo_http_server— 37 passed.cargo clippy -p starknet_api --no-deps --all-targets— clean;scripts/rust_fmt.shapplied.Stacked on #14408 (which moved the function into
starknet_api).🤖 Generated with Claude Code