Skip to content

Display a group with "iteration": "sequential" one array after the other - #29

Open
kuzdogan wants to merge 1 commit into
llbartekll:mainfrom
kuzdogan:fix/sequential-group-iteration
Open

kuzdogan wants to merge 1 commit into
llbartekll:mainfrom
kuzdogan:fix/sequential-group-iteration

Conversation

@kuzdogan

Copy link
Copy Markdown
Contributor

Why

A group with "iteration": "sequential" gives the same lines as a group with "iteration": "bundled", if all the fields of the group are arrays. ERC-7730 says that sequential mode shows each array fully, one after the other.

Fixes #28 (a group with "iteration": "sequential" is displayed in bundled order).

Example

The function is disperseToken(address token, address[] recipients, uint256[] values). Alice gets 100 USDC and Bob gets 50 USDC.

{ "iteration": "sequential", "fields": [
  { "path": "recipients.[]", "label": "To" },
  { "path": "values.[]", "label": "Amount" }
] }
iteration Before After
bundled To: Alice, Amount: 100 USDC, To: Bob, Amount: 50 USDC Same
absent To: Alice, Amount: 100 USDC, To: Bob, Amount: 50 USDC Same
sequential To: Alice, Amount: 100 USDC, To: Bob, Amount: 50 USDC To: Alice, To: Bob, Amount: 100 USDC, Amount: 50 USDC

Only the last row changes.

Cause

The type FieldGroup gave an absent key the default value Sequential. So the code could not tell an absent key from an explicit "sequential".

The Sequential branch of render_group_kind has a special case that shows each element fully before the next element. This special case is necessary for a group whose path ends with .[] and that has no key, for example "path": "allowances.[]" with the fields asset and amount. It also applied to an explicit "sequential".

The change

1. The model keeps the absent key. In types/display.rs, the field iteration of FieldGroup and of DisplayField::Scope is now an Option:

#[serde(default, skip_serializing_if = "Option::is_none")]
pub iteration: Option<Iteration>,

2. The two render functions have three cases. render_group_kind in engine.rs and render_typed_group_kind in eip712.rs get the same change:

match group.iteration {
    // Explicit `"sequential"`: each array is displayed in full, one
    // after the other, in the order of the fields.
    Some(Iteration::Sequential) => Ok(GroupRenderKind::Scalar(
        flatten_group_children_in_field_order(child_kinds),
    )),
    // No `iteration` key. If every field of the group iterates over an
    // array, the elements are paired by index, as in `bundled` mode ...
    None => { /* the code of the old `Sequential` branch */ }
    Some(Iteration::Bundled) => { /* not changed */ }
}

The rule for each case:

Key Rule Changed?
sequential Show each field fully, in the order of the fields. Yes. This is the fix.
bundled Pair the elements by index. The two existing errors stay. No
absent, and all fields are arrays Pair the elements by index, as before. One change, see below
absent, all other groups Show the fields in the order of the fields, as before. No

Why a group with no arrays keeps its output. The Bundled branch returns the error bundled groups cannot mix array-expanded and scalar fields for a field that is not an array. Groups with no arrays and no key exist in the registry. Two examples are the group on #._settings in registry/flare/calldata-PollingFoundation-Flare.json and the group with the label "Access" in registry/slice/eip712-erc8128-delegation.json. So an absent key does not go to the Bundled branch. It keeps the code of the old Sequential branch.

The one change for an absent key. If all fields are arrays and the arrays have different lengths, the result is now the error bundled groups require all array-expanded fields to have the same length. Before, the code showed the elements that exist and gave no error. The elements cannot be paired in that case, and bundled mode already returns this error. Tell me if you prefer the old behaviour, and I remove this check.

Relation to the specification

The draft pull request ethereum/ERCs#2165 (require iteration for two or more array fields, default to bundled) proposes that an absent key means bundled. It is a draft and it is not merged.

This pull request does not depend on that draft. The fix for an explicit "sequential" follows the specification of today. The behaviour for an absent key stays as it is in this library, and it agrees with the draft.

Effect on library users

  • Descriptor model: the type of FieldGroup.iteration and of DisplayField::Scope { iteration } changes from Iteration to Option<Iteration>. Code that builds or reads these values directly must change. Descriptor JSON is read as before.
  • Output model: DisplayEntry::Group { label, iteration: GroupIteration, items } does not change. A group with no key and no label still gives flat DisplayEntry::Item entries.
  • UniFFI bindings: no change. The bindings expose the output model, not FieldGroup.
  • One case with a new order: a group whose path ends with .[] and that writes an explicit "sequential" now shows field by field, because the path joins the fields first. The only registry descriptor with this shape is registry/pendle/calldata-PendleRouterV4.json. All fields of its 32 groups have "visible": "never", so no line changes. A registry pull request, ethereum/clear-signing-erc7730-registry#3211 (remove the unused iteration key from the Router V4 limit order groups), removes that key.

Tests

Seven new tests in crates/clear-signing/tests/spec_compliance.rs. Six of them run the calldata path and the EIP-712 path with the same expected lines.

Test Result on main Result on this branch
test_group_explicit_sequential_displays_each_array_in_full Fail Pass
test_group_explicit_sequential_allows_unequal_array_lengths Fail Pass
test_group_without_iteration_unequal_array_lengths_errors Fail Pass
test_group_explicit_bundled_pairs_array_items_by_index Pass Pass
test_group_without_iteration_pairs_array_items_by_index Pass Pass
test_array_path_group_without_iteration_displays_element_by_element Pass Pass
test_group_without_iteration_mixed_scalar_field_keeps_field_order Pass Pass

No existing test changed.

Command Result
cargo fmt --check Pass
cargo clippy -p clear-signing --all-targets --features uniffi,github-registry -- -D warnings Pass
cargo test -p clear-signing --features uniffi,github-registry 459 pass, 0 fail
cargo test 487 pass, 0 fail

Regression check on the registry

I built cs-test from main at 8bfe6b4 and from this branch. I ran both on all testsv2 files of ethereum/clear-signing-erc7730-registry and compared the status and the rendered fields of each case.

Input Test files Cases main This branch Cases that differ
All registry test files 692 3251 3249 pass, 2 fail 3249 pass, 2 fail 0
Pendle Router V4 with the sequential key on its 32 groups 1 48 48 pass 48 pass 0

The 2 failures are the same cases on both builds.

The Disperse descriptor, test disperseToken - chain 1 with five recipients, with the key of its group changed:

iteration main This branch
bundled To, Amount, To, Amount, … To, Amount, To, Amount, …
absent To, Amount, To, Amount, … To, Amount, To, Amount, …
sequential To, Amount, To, Amount, … To ×5, then Amount ×5

🤖 Generated with Claude Code

A group with an explicit "sequential" was displayed in bundled order when
all its fields iterate over arrays. The descriptor model could not tell an
absent `iteration` key from an explicit "sequential", and the special case
for a group whose path ends with `.[]` applied to both.

- `FieldGroup.iteration` and `DisplayField::Scope.iteration` are now
  `Option<Iteration>`; `None` means the key is absent.
- Explicit "sequential": each array is displayed in full, in field order.
- Absent key: if every field of the group iterates over an array, the
  elements are paired by index, as before. Arrays of different lengths are
  now an error, as in bundled mode. Every other group keeps its output.
- Explicit "bundled": unchanged.

Fixes llbartekll#28

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@kuzdogan kuzdogan moved this to Sprint - Blocked in Sourcify Public Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A group with "iteration": "sequential" is displayed in bundled order

1 participant