Repository navigation
feat(encryption): support ERC-7730 encryption scheme - #10
Conversation
|
hey @llbartekll , did you get the time to have a look at this ? |
59435d1 to
9a29cb3
Compare
|
hey again @llbartekll , without this feature, new integration like ethereum/clear-signing-erc7730-registry#2595 have failing tests. Would it be possible to have a look at this PR ? thanks ! |
llbartekll
left a comment
There was a problem hiding this comment.
Thanks for porting this feature. I ran cargo fmt --check, the full test suite, the UniFFI/GitHub-registry feature tests, and Clippy with warnings denied; the existing checks pass. I am requesting changes because the wallet-facing callback plumbing is incomplete and targeted regression cases expose incorrect or inconsistent clear-signing output. In particular: Swift/Kotlin and CompositeDataProvider cannot reach the decryptor, an encrypted interpolated field is decrypted twice, signed intN values can be rendered with the wrong sign, visibility is evaluated on ciphertext, and EIP-712 never attempts decryption. Please address the inline findings and add coverage for these paths before merging.
| /// re-interprets it via the descriptor's declared `plaintextType`. Return | ||
| /// `None` when the value cannot be decrypted (unsupported scheme, declined | ||
| /// signature, no access) — the field then renders its `fallbackLabel`. | ||
| fn resolve_decrypted_value( |
There was a problem hiding this comment.
Please wire this callback through every public provider adapter before merging. DataProviderFfi has no corresponding method, so DataProviderFfiProxy inherits this default None; CompositeDataProvider also does not delegate it. Consequently every Swift/Kotlin integration, and any Rust decryptor wrapped in CompositeDataProvider, always renders the fallback even when the wallet can decrypt. Please add the FFI bridge/generated bindings, composite first-success delegation, and end-to-end tests.
| // When decryption is unavailable the field renders its `fallbackLabel`; a | ||
| // malformed annotation degrades the same way, distinguished by diagnostic. | ||
| let decrypted_owned; | ||
| if let Some(enc) = params.and_then(|p| p.encryption.as_ref()) { |
There was a problem hiding this comment.
This decryption runs inside format_value, which is invoked once while rendering entries and again when the same field appears in interpolatedIntent. The target Zama registry descriptor does interpolate the encrypted amount. A provider returning 0x2a and then None produces an entry of 42 but an intent containing [Encrypted], while an interactive provider may prompt twice and the second warning is discarded. Please decrypt once and reuse/cache that result for both outputs.
| fn build_plaintext_value(kind: PlainKind, bytes: Vec<u8>) -> ArgumentValue { | ||
| match kind { | ||
| PlainKind::Uint => ArgumentValue::Uint(bytes), | ||
| PlainKind::Int => ArgumentValue::Int(bytes), |
There was a problem hiding this comment.
The declared intN width is lost here. For plaintextType int64, the valid minimal positive encoding 0xc8 reaches int_to_bigint as a one-byte signed value and renders as -56 instead of 200. Preserve the declared bit width during signed conversion, and add tests for a positive top-bit-set value, a full-width value, and negative values.
| if let Some(ref enc) = params.encryption { | ||
| if let Some(ref fallback) = enc.fallback_label { | ||
| return Ok(fallback.clone()); | ||
| // Encryption (ERC-7730 `encryption`): decrypt via the wallet, then render the |
There was a problem hiding this comment.
Decryption occurs too late for conditional visibility: render_fields and the group/array variants call check_visibility on the ciphertext before reaching format_value. A decrypted value of 200 with visible.mustMatch [200] currently fails as InvalidDescriptor before the provider is even called; ifNotIn is likewise evaluated against the handle. Resolve/decrypt once before conditional visibility, then pass the same plaintext through formatting and interpolation.
| }; | ||
|
|
||
| // Check encryption fallback | ||
| // Check encryption fallback — opaque handle, cannot decrypt here. |
There was a problem hiding this comment.
The typed-data path never invokes resolve_decrypted_value: it immediately returns the fallback and does not emit decryption_failed. Thus even a capable Rust provider cannot decrypt an encrypted EIP-712 field, which breaks the repository's calldata/EIP-712 parity guardrail. Please share the decryption/coercion path with calldata using the typed container chainId and verifyingContract, and add parity tests.
|
hey @llbartekll , thanks for the review, I've just pushed new changes to take into account your comments but also align this PR a bit more with what was included in sourcifyeth/clear-signing#56. I've made some additional decisions that led to further changes, so please let me know if some are not relevant. Here is a summary: Review fixes
Also aligned with sourcifyeth/clear-signing#56 (now merged)
Consumer-visible changes
Verification
Remaining known divergences from TS
|
Ported the sourcify PR's behavior (sourcifyeth/clear-signing#56) to Rust :
Default impl means no existing implementor (or the FFI wrapper) breaks.
width), and format_value renders the plaintext with the field's normal format. On failure it renders fallbackLabel/[Encrypted]. Includes the Issue-1 width bounds check (> upper bound,
honoring leading-zero stripping). Plus the field-level-encryption parsing plumbing.
Verification
over-width→decryption_failed; no-fallbackLabel→[Encrypted]; bad plaintextType→encryption_invalid_descriptor. 7/7 pass.
Two deliberate divergences from the TS PR (Rust model differences)
diagnostic + render the fallback rather than blanking the transaction. (Arguably the better behavior — and I flagged the TS abort as debatable anyway.)
bindings. The core decrypt/fallback behavior is complete without it — worth a follow-up if you want the RECOMMENDED raw-value display.
result: Ported the wallet-delegated resolve_decrypted_value encryption model to the Rust fork on branch feat/erc7730-encryption (uncommitted, 6 files +281/−14 plus a new 7-case
integration test). Verified: 7/7 new tests pass, full suite no regressions, uniffi feature compiles, and the Zama registry testsv2 fixtures pass 16/16 via cs-test with no decryptor
(fallback path). Two documented divergences: malformed annotations degrade instead of aborting, and rawEncryptedValue output is omitted (invasive on the FFI DisplayItem).
🤖 Generated with Claude Code