Skip to content

Conversation

0xrusowsky
Copy link
Contributor

@0xrusowsky 0xrusowsky commented Sep 11, 2025

Motivation

Historical limitation in vm.parseJson where JSON object fields had to be sorted alphabetically, breaking compatibility with Solidity struct field order. This required developers to work around the limitation by manually ordering JSON fields.

Solution

Integrate Solar's compiler output into the multi-runners. The PR introduces a CheatcodeAnalysis architecture that provides the cheatcode inspector access to Solar's compiler output, enabling order-preserving JSON parsing.

JSON cheats improvements

  • parseJson and parseJsonType now use struct definitions to preserve field order
  • fallback to alphabetical ordering when unavailable (backwards compatible)

CheatcodeAnalysis Architecture

New CheatcodeAnalysis struct that provides cached, on-demand access to Solar's compiler output:

pub struct CheatcodeAnalysis {
    pub compiler: Arc<Compiler>,
    struct_defs: OnceLock<Result<StructDefinitions, AnalysisError>>,
}

the impl aims to be:

  • easily extensible by only having to modify the CheatcodeAnalysis struct with the new fields and getter methods
  • performant thanks to the lazy (on-demand) evaluation + caching

integrating a new analysis tool only requires setting up a new getter method (besides its impl):

/// Lazily initializes and returns the struct definitions.
pub fn struct_defs(&self) -> Result<&StructDefinitions, &AnalysisError> {
    self.struct_defs
        .get_or_init(|| {
            self.compiler.enter(|compiler| {
                let gcx = compiler.gcx();

                StructDefinitionResolver::new(gcx).process()
            })
        })
        .as_ref()
}

note: StructDefinitionResolver is a HIR visitor


old disc:

@0xrusowsky 0xrusowsky changed the title feat(cheats): sorted JSON params feat(cheats): preserve struct order when parsing JSON objects Sep 17, 2025
@grandizzy grandizzy added this to the v1.5.0 milestone Sep 22, 2025
@0xrusowsky 0xrusowsky marked this pull request as ready for review September 23, 2025 19:28
@0xrusowsky 0xrusowsky moved this to Ready For Review in Foundry Sep 24, 2025
@0xrusowsky 0xrusowsky moved this from Ready For Review to In Progress in Foundry Sep 24, 2025
@0xrusowsky 0xrusowsky marked this pull request as ready for review September 24, 2025 14:31
@DaniPopes DaniPopes mentioned this pull request Aug 28, 2025
1 task
@0xrusowsky 0xrusowsky moved this from In Progress to Ready For Review in Foundry Sep 29, 2025
@0xrusowsky 0xrusowsky enabled auto-merge (squash) October 6, 2025 16:41
@0xrusowsky 0xrusowsky merged commit c34a33e into master Oct 6, 2025
28 of 30 checks passed
@0xrusowsky 0xrusowsky deleted the rusowsky/sorted-json-w-compiler branch October 6, 2025 16:51
@github-project-automation github-project-automation bot moved this from Ready For Review to Done in Foundry Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants