Repository navigation
Conversation
… balance Signed-off-by: myetcd <mytech@139.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
NetworkClient::get_balancereturnsResult<U256>and propagates RPC failures with?, but the final step unwraps a parse of a server-controlled string:GetBalanceResponse::balance()returns the raw protoamountstring, so a non-numeric, negative, whitespace-padded, or out-of-range response panics the caller's process instead of surfacing an error. Checked againstalloy-primitives1.5.7 (the version pinned inCargo.lock),U256::from_strreturnsErrfor"invalid","1.5","-1"," 12", and10^78, so each of those panics at theunwrap(). A malformed or version-incompatible response is exactly the case where a caller wants a loggable error, not a panic mid-proving-pipeline.The same check turned up a second, quieter problem:
U256::from_str("")isOk(0), so an emptyamountdoes not panic — it silently reports a zero balance and hides the protocol error.Solution
parse_balance(&str) -> Result<U256>helper next to the existingparse_fulfillment_status(same module-level style andpub(super)visibility) that returns a contextual error carrying the offending value —invalid balance returned by prover network: "invalid"— and rejects blank responses explicitly, sinceU256::from_strmaps""to0.get_balancenow delegates to it:parse_balance(response.balance()). The public signature is unchanged, and valid responses parse exactly as before."0","1000",U256::MAX) and malformed ones (""," ","invalid","1.5","-1", an overflow value), asserting the error message contains the raw value.This follows the convention already used in the same file:
get_market_price_per_pguparses its server-supplied string fields with.with_context(...), andparse_fulfillment_statuswas added for the same class of bug in #2909.Validation
cargo check -p sp1-sdk --features network— cleanbalance_parser_handles_valid_and_invalid_valuescargo clippy -p sp1-sdk --features network --lib --tests— no diagnostics forclient.rsrustfmt --check crates/sdk/src/network/client.rs— cleangit diff --check— cleanVerified on toolchain
1.95.0(the repo pinschannel = "stable", which is not installed in my environment;1.95.0is above the workspacerust-version = "1.88"). Thezkevm/*andsp1-gpu/*workspace members were excluded from the build because they resolve git dependencies that are unreachable from my network; neither is touched by this change.PR Checklist