Skip to content

fix: support dynamic fields in event signatures - #1522

Open
cburgdorf wants to merge 1 commit into
argotorg:masterfrom
cburgdorf:event_fix
Open

fix: support dynamic fields in event signatures#1522
cburgdorf wants to merge 1 commit into
argotorg:masterfrom
cburgdorf:event_fix

Conversation

@cburgdorf

@cburgdorf cburgdorf commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Fe already provides Solidity ABI types such as Bytes, DynString, and DynArray<T>, but they could not be used reliably as non-indexed event fields.

For example:

#[event]
struct ValuesChanged {
    values: DynArray<u256>,
}

This should produce the Solidity event signature:

ValuesChanged(uint256[])

and ABI-encoded event data containing:

offset(0x20) | array length | array elements

Before this change:

  • DynArray event fields failed to compile because event signature generation could not derive their canonical Solidity type.
  • A single dynamic field was encoded without its ABI offset head, producing malformed event data.
  • Imported aliases such as DynArray as Values were not resolved reliably.
  • Nested types such as DynArray<[u256; 2]> could not produce the canonical uint256[2][] signature.
  • Some failures while evaluating generated TOPIC0 constants could surface as compiler ICEs instead of diagnostics.

What changed

  • Add composable SolCompat implementations for dynamic and fixed-size arrays.

  • Generate event signature fragments through qualified SolCompat resolution:

    • aliases resolve to the underlying core type;
    • user-defined types named DynArray retain their own implementation;
    • nested array types produce their canonical Solidity spelling.
  • Encode all non-empty event data as a tuple through encode_event_payload.

    • This preserves the ABI head for a single dynamic field.
    • Static singleton fields retain their existing wire representation.
  • Detect unsupported indexed dynamic fields from their resolved semantic type.

  • Report generated TOPIC0 CTFE and semantic-constant reification failures as compiler diagnostics instead of panicking.

Result

Non-indexed dynamic event fields now compile and emit Solidity-compatible topics and data:

TOPIC0 = keccak256("ValuesChanged(uint256[])")
data = offset(0x20) | length | elements

Indexed dynamic fields remain unsupported for now, but produce a targeted diagnostic rather than failing indirectly.

Test coverage

Added regression coverage for:

  • Bytes and DynString event fields.
  • DynArray and DynArray.
  • Events mixing dynamic and static fields.
  • A single dynamic field with the required ABI offset head.
  • DynArray<[u256; 2]> producing uint256[2][].
  • Imported DynArray aliases.
  • User-defined generic types also named DynArray.
  • Indexed dynamic-field diagnostics through aliases.
  • Generated TOPIC0 CTFE failures.
  • Runtime semantic-constant reification failures.

@cburgdorf
cburgdorf marked this pull request as ready for review August 19, 2026 08:52
@cburgdorf

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 539cd703e2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/hir/src/core/lower/event.rs Outdated
Comment thread crates/hir/src/core/lower/event.rs Outdated
Comment thread crates/hir/src/core/lower/event.rs Outdated
@cburgdorf

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: bc984b6764

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf
cburgdorf requested a review from sbillig August 19, 2026 20:24
Build canonical Solidity type names for dynamic-array event fields while preserving correct topic and payload encoding.

Diagnose unsupported indexed dynamic fields from resolved core types, including aliases, without rejecting shadowed user types. Surface generated TOPIC0 CTFE failures and semantic-constant reification failures instead of panicking, with focused UI and execution regressions.
@cburgdorf

Copy link
Copy Markdown
Collaborator Author

@sbillig This one is ready for human review

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.

1 participant