Skip to content

Conversation

@andrew-fleming
Copy link
Contributor

@andrew-fleming andrew-fleming commented Jan 29, 2026

Types of changes

What types of changes does your code introduce to OpenZeppelin Midnight Contracts?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Fixes #59.

Note that the root README badge still shows 0.26.0. Instead of changing it now, this PR proposes to wait until there's a release document for it to point to. This PR could change the badge's version number and keep the link if preferred (but it's easier to forget if the output if correct)

This PR also proposes not to update all the CLI tests that use 0.26.0 as an input value. It's simple to change if it's really desired

PR Checklist

  • I have read the Contributing Guide
  • I have added tests that prove my fix is effective or that my feature works
  • I have added documentation of new methods and any new behavior or changes to existing behavior
  • CI Workflows Are Passing

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

Summary by CodeRabbit

  • Chores
    • Upgraded Compact toolchain from version 0.26.0 to 0.28.0
    • Updated developer tools from 0.1.0 to 0.2.0
    • Modernized module imports from CommonJS to ES module format across test fixtures
    • Updated language version requirements to 0.19.0
    • Updated runtime dependency to version 0.14.0-rc.0

✏️ Tip: You can customize this high-level summary in your review settings.

@andrew-fleming andrew-fleming requested review from a team as code owners January 29, 2026 03:44
@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review

Walkthrough

This pull request upgrades the Compact toolchain from version 0.26.0 to 0.28.0 and updates the compact-runtime dependency to 0.14.0-rc.0. The changes include refactoring the simulator core to use new runtime types (StateValue, ChargedState), replacing the CircuitContext structure to use currentQueryContext and costModel instead of originalState and transactionContext, migrating artifact imports from CommonJS to ES modules, and updating Compact contract files to language version 0.19.0 with named imports.

Changes

Cohort / File(s) Summary
Version Bump - Compact Toolchain
.github/actions/setup/action.yml, README.md, packages/cli/README.md
Updated Compact toolchain version from 0.26.0 to 0.28.0 in GitHub Actions configuration and documentation.
Version Bump - Runtime Dependency
package.json, packages/simulator/package.json
Removed @midnight-ntwrk/compact-runtime from root dependencies; updated packages/simulator version from ^0.9.0 to 0.14.0-rc.0.
Module Format Migration (CommonJS to ES)
packages/simulator/README.md, packages/simulator/test/fixtures/sample-contracts/witnesses/*, packages/simulator/test/fixtures/utils/address.ts, packages/simulator/test/integration/...*, packages/simulator/test/setup.ts
Changed artifact import paths from index.cjs to index.js across documentation and test files to use ES modules instead of CommonJS.
Core Simulator API Refactoring
packages/simulator/src/core/AbstractSimulator.ts, packages/simulator/src/core/CircuitContextManager.ts, packages/simulator/src/core/ContractSimulator.ts, packages/simulator/src/types/Simulator.ts, packages/simulator/src/utils/CircuitContextUtils.ts
Replaced CircuitContext structure: transactionContext → currentQueryContext (using QueryContext), originalState removed, added costModel field. Updated type imports: ContractState → StateValue/ChargedState. Modified getContractState() return type and implementation.
Factory and Simulator Setup
packages/simulator/src/factory/createSimulator.ts
Updated contract address and public state extraction to use currentQueryContext instead of transactionContext; replaced sampleContractAddress with dummyContractAddress.
Compact Language Contract Updates
packages/simulator/test/fixtures/sample-contracts/SampleZOwnable.compact, packages/simulator/test/fixtures/sample-contracts/Simple.compact, packages/simulator/test/fixtures/sample-contracts/Witness.compact
Bumped language_version from 0.18.0/0.18.0+ to 0.19.0; replaced default CompactStandardLibrary imports with named imports for specific symbols (Either, Counter, ZswapCoinPublicKey, ContractAddress, etc.).
Test Updates - Type and Import Changes
packages/simulator/test/unit/core/StateManager.test.ts, packages/simulator/test/integration/SampleZOwnable.test.ts, packages/simulator/test/integration/SampleZOwnableSimulator.ts, packages/simulator/test/integration/SimpleSimulator.ts, packages/simulator/test/integration/WitnessSimulator.ts
Updated test imports to use index.js; refactored type references (EncodedQualifiedCoinInfo → EncodedQualifiedShieldedCoinInfo, QualifiedCoinInfo → QualifiedShieldedCoinInfo); replaced originalState/transactionContext assertions with currentQueryContext and costModel; added ChargedState imports.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

Suggested reviewers

  • emnul

Poem

🐰 Hops of joy for runtime's grace,
CircuitContext finds its new place,
From CommonJS we swiftly flee,
To modules pure, ES modules free!
State and coins now shielded bright,
Version bumps, everything's right! 🚀

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Changes include refactoring of circuit context structures (ContractState→StateValue, originalState→currentQueryContext, transactionContext→currentQueryContext) and import path updates (.cjs→.js) beyond simple version bumping. Clarify whether context refactoring and module format changes are part of the 0.28.0 migration requirements or should be separated into distinct PRs for cleaner scope management.
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective: bumping the Compact toolchain to version 0.28.0, which is the primary focus across all modified files.
Linked Issues check ✅ Passed PR fulfills linked issue #59 requirements: Compact version bumped to 0.28.0 across action, READMEs, and package.json; compact-runtime updated to 0.14.0-rc.0 in packages/simulator/package.json.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.github/actions/setup/action.yml (1)

42-46: Update compact-version to an available release; version 0.28.0 does not exist.

The latest released Compact compiler version is 0.26.0 (October 8, 2025). Version 0.28.0 is not a published release and will cause the setup action to fail. Update to 0.26.0 or verify the correct version number.

🧹 Nitpick comments (2)
packages/cli/README.md (1)

238-244: Align remaining example versions for consistency.

This output block shows 0.28.0, but earlier examples still reference 0.26.0 (e.g., +0.26.0 and programmatic API snippets). Consider updating those to reduce confusion.

packages/simulator/test/unit/core/StateManager.test.ts (1)

99-133: Avoid using QueryContext as the costModel placeholder.

costModel is currently set to modifiedTxCtx (a QueryContext). If the runtime expects a distinct cost model type, this can mask mismatches. Consider reusing the existing context’s costModel (or constructing a proper one) instead.

Suggested tweak
 const newCtx: CircuitContext<SimplePrivateState> = {
   currentQueryContext: modifiedTxCtx,
   currentPrivateState: initialPrivateState,
   currentZswapLocalState: zswapLocalState_1,
-  costModel: modifiedTxCtx,
+  costModel: ctx.costModel,
 };

Copy link
Member

@0xisk 0xisk left a comment

Choose a reason for hiding this comment

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

Thank you @andrew-fleming! Looking good! I left some comments.

Copy link
Contributor

@emnul emnul left a comment

Choose a reason for hiding this comment

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

Looks good! I just have an open question about ledger v7

@andrew-fleming andrew-fleming requested review from 0xisk and emnul January 29, 2026 23:57
Copy link
Contributor

@emnul emnul left a comment

Choose a reason for hiding this comment

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

Quick turnaround ftw! 🚀

Copy link
Member

@0xisk 0xisk left a comment

Choose a reason for hiding this comment

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

Thank you @andrew-fleming! Changes look good! Left some comments mainly regarding gasLimit is it excluded as we are dealing with the Simulator so the gasLimit here is useless?

*/
public getCallerContext(): CircuitContext<P> {
const activeCaller = this.callerOverride || this.persistentCallerOverride;
const baseCtx = this.circuitContext;
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to wrap this.circuitContext in another variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to wrap it. It simplifies the return object so we're not rewriting this.circuitContext multiple times

    return {
      currentPrivateState: baseCtx.currentPrivateState,
      currentQueryContext: baseCtx.currentQueryContext,
      currentZswapLocalState: activeCaller
        ? emptyZswapLocalState(activeCaller)
        : baseCtx.currentZswapLocalState,
      costModel: baseCtx.costModel,
    };

const baseCtx = this.circuitContext;

return {
...this.circuitContext,
Copy link
Member

Choose a reason for hiding this comment

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

Why do we not return the rest of circuitContext here? we are basically excluding gasLimit is that intended?
If that is not intended, I would revert that as returning gasLimit is useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a part of the circuit context interface and it's better for future proofing. Will add it in 👍

contractAddress,
),
currentQueryContext: new QueryContext(chargedState, contractAddress),
costModel: CostModel.initialCostModel(),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
costModel: CostModel.initialCostModel(),
costModel: CostModel.initialCostModel(),
gasLimit: emptyRunningCost()

I think we can use this API for the default value: https://github.com/midnightntwrk/compact-export/blob/41de8595c568de8dfafc9e80bec60630c5417b00/runtime/src/circuit-context.ts#L159

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All contract tests that change the state:

CompactError: Error: ran out of gas budget

public getContractState(): ContractState {
return this.circuitContext.originalState;
public getContractState(): StateValue {
return this.circuitContext.currentQueryContext.state.state;
Copy link
Member

Choose a reason for hiding this comment

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

I don't like the naming of the chargedState here, it should be rather currentQueryContext.chargedState.state. If we agree I will write it as a small feedback to the MN team.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1

contractAddress,
),
currentZswapLocalState: emptyZswapLocalState(sender),
costModel: currentContext.costModel,
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to return the gasLimit here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically no bc it's an optional param. Will add for future proofing

});
export const encodeToAddress = (str: string): Compact.ContractAddress => {
const hex = toHexPadded(str);
// Remove last 2 bytes (4 hex chars) to comply with 31-byte field limit
Copy link
Member

@0xisk 0xisk Jan 30, 2026

Choose a reason for hiding this comment

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

Suggested change
// Remove last 2 bytes (4 hex chars) to comply with 31-byte field limit
// Remove last 2 bytes (4 hex chars) to comply with 32-byte field limit

Correct me if I'm wrong, but I think that's what do you mean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, thus it's not needed. Removing

andrew-fleming and others added 4 commits January 30, 2026 16:17
Co-authored-by: 0xisk <0xisk@proton.me>
Signed-off-by: Andrew Fleming <fleming.andrew@protonmail.com>
Copy link
Contributor

@emnul emnul left a comment

Choose a reason for hiding this comment

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

Re-approve edits

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.

Bump Simulator tool to Compact to 0.28.0

3 participants