Skip to content

Conversation

@saitunc
Copy link
Contributor

@saitunc saitunc commented Jan 12, 2026

Changes

In this PR, it is aimed to convert from provable types to non-provable types in out-of-circuit code.

Starting point changes in this refactoring was to implement or convert to JSON type of the followings:

  • Block
  • BlockWithResult

And since they are

  • TransactionExecutionResult
  • PendingTransaction
  • StateTransitionBatch
  • UntypedStateTransition
  • NetworkState

Especially last 3 is used all around the Sequencing and Tracing modules.

Commits

UntypedStateTransition & StateTransitionBatch

  • Implement UntypedStateTransitionJson 0199877 ( rename: 5934a13 )
  • Implement in block and tracing services 0199877
  • Change in tracing, block result services 5934a13

TransactionExecutionResult

  • Implemented Json interface, TransactionExecutionResultJson b017bb5
  • Implement conversion function between json type and provable type to use when needed 08f95bb
  • Changed in execution and tracing 564ba7a
  • Changed in Prisma storage 6905b36
  • Changed in various modules fb4c854

PendingTransaction

  • Changed in PrivateMempool d3c9336
  • Changed in various modules d5b6d7b
  • Changed in storage and mempool d8558f9
  • Changed in execution and tracing 564ba7a

NetworkState

  • Define NetworkStateJson by inferring it from Struct c29a51d
  • add RuntimeProofParametersJson type with NetworkStateJson and PendingTransactionJsonType a4ac392

Miscellanous

  • refactor CllientBlock with value types 1093afe

#### Test

  • Updated changes in test files 57ad69d

This PR closes #201

saitunc and others added 30 commits January 7, 2026 10:34
@saitunc saitunc requested a review from rpanic January 20, 2026 10:55
);

console.log("tx nonce", tx.transaction?.nonce.toBigInt());
console.log("tx nonce", (tx.transaction as PendingTransaction).nonce);
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 you do this? tx should already be of type PendingTransaction, no?

import { ObjectMapper } from "../../../ObjectMapper";

type EventData = {
type EventDataJson = {
Copy link
Member

Choose a reason for hiding this comment

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

I think we should leave this as EventData - there's not provable version of it, so that name is fine imo


let txHash: string;

if (transaction.transaction instanceof PendingTransaction) {
Copy link
Member

Choose a reason for hiding this comment

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

Whaat - why do we have this conditional in a test?

}

if (lastProcessedBlockHeight === Number(block?.block.height.toBigInt())) {
if (lastProcessedBlockHeight === Number(block?.block.height)) {
Copy link
Member

Choose a reason for hiding this comment

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

Can't we skip this cast to number since it's already a number?

const args = await methodEncoder.decode(fieldArgs, []);

const { fields, auxiliary } = methodEncoder.encode(args);
const hash = Poseidon.hash([
Copy link
Member

Choose a reason for hiding this comment

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

Like I mentioned in PendingTransaction.ts, we shouldn't do this!

latestBlockWithResult.result.afterNetworkState.hash().toString()
).toStrictEqual(batch!.toNetworkState.hash().toString());
new ProvableNetworkState(
ProvableNetworkState.fromJSON(
Copy link
Member

Choose a reason for hiding this comment

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

We have these 5 lines at least 20 times in the codebase - should we make NetworkState a class and implement toProvable and fromProvable on it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure - even though toProvable and fromProvable will be good to remove these parts, we could need fromJson and toJson in that class too.

Maybe not though, have to check where NetworkState is used.

interface PendingTransactionJSONType {
hash: string;
methodId: string;
nonce: string;
Copy link
Member

Choose a reason for hiding this comment

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

Why is nonce a string? It should be a number

async function createBatch(
withTransactions: boolean,
customNonce: number = 0,
// Why is it like this?
Copy link
Member

Choose a reason for hiding this comment

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

What are you referring to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A note for myself that where i thought of using PendingTransaction as json, this line will be removed.


const txHash = tx.transaction?.hash().toString()!;
const txHash =
tx.transaction instanceof UnsignedTransaction
Copy link
Member

Choose a reason for hiding this comment

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

Yeah no, we need to fix the PendingTransaction implementation :)

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.

Refactor non-provable codebase to use value-types instead of provable types

3 participants