Skip to content

Include new contract data function tree root in tx hash#188

Merged
spalladino merged 12 commits into
masterfrom
palla/tx-hash-with-fn-tree-root
Apr 10, 2023
Merged

Include new contract data function tree root in tx hash#188
spalladino merged 12 commits into
masterfrom
palla/tx-hash-with-fn-tree-root

Conversation

@spalladino

@spalladino spalladino commented Apr 5, 2023

Copy link
Copy Markdown
Contributor
  • Refactors wasm wrappers in bb and circuits
  • Introduces new primitives wasm wrapper (using bb wasm for now)
  • Uses calculateContractLeaf for calculating contract tree commitments used for the tx hash
  • Makes txHash tx getter async (sorry)

Note that, since we now depend on circuits for explicitly calculating contract leaves via the computeContractLeaf cbind, the primitives wasm is left unused. I'm leaving it as part of the PR since we can leverage it in the future for more lightweight dependencies, but I wouldn't worry about this atm.

Depends on AztecProtocol/aztec3-circuits#178

Fixes #154

@spalladino spalladino force-pushed the palla/tx-hash-with-fn-tree-root branch 4 times, most recently from 4ae9246 to 65ea927 Compare April 10, 2023 11:23
@spalladino spalladino force-pushed the palla/tx-hash-with-fn-tree-root branch from ba5780a to 356689a Compare April 10, 2023 13:31
@spalladino spalladino requested a review from ludamad April 10, 2023 13:55
@spalladino spalladino marked this pull request as ready for review April 10, 2023 13:55
import { BarretenbergWasm } from '../../wasm/index.js';
import { WasmWrapper } from '@aztec/foundation/wasm';

export class Grumpkin {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not the biggest fan of the Wrapper name, the intent was that the generic concept was called WasmModule

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Almost any utility class could be called a Wrapper, is my reasoning, but it represents what it wraps

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agree, and WasmModule was also my first choice for a name, but there's already a lower level WasmModule in the repo.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah I created that one, it was meant to provide everything needed to just pass around without introducing base classes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I suppose that's not quite right though with async call state

COPY l2-block l2-block
COPY tx tx
COPY unverified-data unverified-data
COPY . .

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1 if we're going to have a dependency system no reason to copy dependencies one by one (which mostly can help with docker figuring out its own dependencies)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ludamad ludamad left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM other than naming comment

@spalladino

Copy link
Copy Markdown
Contributor Author

I cannot come up with a better name for now. I'll merge and keep thinking about it.

@spalladino spalladino merged commit 86851ec into master Apr 10, 2023
@spalladino spalladino deleted the palla/tx-hash-with-fn-tree-root branch April 10, 2023 14:33
PhilWindle added a commit that referenced this pull request Jun 8, 2026
#23921)

Fixes A-836 (Audit #188).

## Problem

The CLI loaded contract artifacts via `loadContractArtifact`
(`getContractArtifact` in `cli/src/utils/aztec.ts`). For an
**already-processed** artifact, `loadContractArtifact` only runs the
shallow `isContractArtifact` heuristic — its own JSDoc notes "The check
is not exhaustive". It checks
`name`/`functions`/`nonDispatchPublicFunctions` shape but never
validates parameter ABIs, types, storage layout, outputs, etc. (Raw
nargo output is already fully validated, since it flows through
`generateContractArtifact` → `ContractArtifactSchema.parse`.)

A malformed-but-superficially-shaped artifact therefore bypassed schema
validation and surfaced as an opaque error later during
deployment/arg-encoding rather than a clear validation failure.

## Fix

Add `loadContractArtifactWithValidation` in stdlib: it runs the full
`ContractArtifactSchema` over an already-processed artifact before
returning, and otherwise defers to `loadContractArtifact` (raw nargo
stays validated as before). The returned object is identical to
`loadContractArtifact`'s — the schema parse is used purely as a
validation gate. The CLI's `getContractArtifact` now uses it.

Scoped deliberately to the CLI (the audit's concern).
`loadContractArtifact` is called at 100+ module-load sites with
wire-form JSON; adding a stricter schema gate to all of them would have
a large blast radius and risk rejecting legacy artifacts, so the
unguarded function is left unchanged.

## Test

Added `loadContractArtifactWithValidation` tests in
`contract_artifact.test.ts`: a valid already-processed artifact (wire
form) loads, and one whose `functionType` is a non-enum string — which
still passes the shallow `isContractArtifact` check — is rejected. The
rejection test fails without the schema gate and passes with it.

## Note

Severity is MEDIUM in the finding, but as the artifact is local input
the deployer supplies (not an untrusted network boundary) and downstream
code still throws on bad input, the practical impact is closer to LOW (a
clearer error message, earlier).
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.

Include functionTreeRoot of new contracts when calculating tx hash

2 participants