-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Adds schemas for every API.** Every API exposed via JSON RPC now requires a zod schema (see #9656 for more context on the rationale for this change). All schemas are in `circuit-types/interfaces`, and look like: https://github.com/AztecProtocol/aztec-packages/blob/3e78ec721285fcd533cff61329a8e156958e2d65/yarn-project/circuit-types/src/interfaces/prover-node.ts#L33-L45 These schemas are type-checked against the interface via the `ApiSchemaFor` utility type, so if the interface changes, schemas are required by the compiler to change as well. Schemas are now used in the JSON RPC server to 1) identify which methods are exposed (so we no longer need the method disallowlist) and 2) parse their arguments. The JSON RPC server, once it has identified the method to be called, grabs the arguments schema and funnels the result of a vanilla JSON parse through it. Every type or struct that is exposed via an interface now has an associated schema, which is referenced in the API for parsing. Schemas both validate input and hydrate instances. This means that we no longer set a `type` property to identify how to hydrate each object in a request during deserialization, which was a security risk. https://github.com/AztecProtocol/aztec-packages/blob/3e78ec721285fcd533cff61329a8e156958e2d65/yarn-project/circuit-types/src/l2_block.ts#L24-L32 Schemas are also used in the JSON RPC client for deserializing the result types. Again, this lets us remove the `type` parameter from all serialized entities, though this is still present in since it is required by the `TypeRegistry` (still to be removed) which is only used in the snapshot manager. All schemas are tested via mini integration tests. These tests define a mock implementation for each service, use it for setting up a JSON RPC server, starting it in a free port, and test calling every method through JSON RPC. https://github.com/AztecProtocol/aztec-packages/blob/3e78ec721285fcd533cff61329a8e156958e2d65/yarn-project/circuit-types/src/interfaces/prover-node.test.ts#L12-L31 These changes prompted other changes. For instance, we introduced the following changes to APIs: - `ProvingJobSource.rejectProvingJob` now accepts a reason `string` instead of an `Error` type - `PXE.getEvents(type)` is removed in favor of `PXE.getEncryptedEvents` and `PXE.getUnencryptedEvents` since both methods required different arguments We also removed service-management methods (ie `stop`) from interfaces. We were inadvertently calling `stop` on remote instances over http when we shouldn't have. We also typed some previously untyped interfaces, such as the TXE's. Fixes #9455
- Loading branch information
1 parent
5246251
commit 6554122
Showing
268 changed files
with
5,990 additions
and
3,007 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
export * from './archiver_client.js'; | ||
export * from './archiver_server.js'; | ||
import { type ArchiverApi, ArchiverApiSchema } from '@aztec/circuit-types'; | ||
import { createSafeJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client'; | ||
import { createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server'; | ||
|
||
export function createArchiverClient(url: string, fetch = makeFetch([1, 2, 3], true)): ArchiverApi { | ||
return createSafeJsonRpcClient<ArchiverApi>(url, ArchiverApiSchema, false, 'archiver', fetch); | ||
} | ||
|
||
export function createArchiverRpcServer(handler: ArchiverApi) { | ||
return createSafeJsonRpcServer(handler, ArchiverApiSchema); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,11 @@ | ||
import { | ||
type AztecNode, | ||
EncryptedL2NoteLog, | ||
EncryptedNoteL2BlockL2Logs, | ||
EpochProofQuote, | ||
ExtendedUnencryptedL2Log, | ||
L2Block, | ||
LogId, | ||
NullifierMembershipWitness, | ||
PublicDataWitness, | ||
PublicSimulationOutput, | ||
SiblingPath, | ||
Tx, | ||
TxEffect, | ||
TxHash, | ||
TxReceipt, | ||
UnencryptedL2BlockL2Logs, | ||
} from '@aztec/circuit-types'; | ||
import { FunctionSelector, Header, PublicKeys } from '@aztec/circuits.js'; | ||
import { NoteSelector } from '@aztec/foundation/abi'; | ||
import { AztecAddress } from '@aztec/foundation/aztec-address'; | ||
import { Buffer32 } from '@aztec/foundation/buffer'; | ||
import { EthAddress } from '@aztec/foundation/eth-address'; | ||
import { Fr } from '@aztec/foundation/fields'; | ||
import { JsonRpcServer } from '@aztec/foundation/json-rpc/server'; | ||
import { type AztecNode, AztecNodeApiSchema } from '@aztec/circuit-types'; | ||
import { createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server'; | ||
|
||
/** | ||
* Wrap an AztecNode instance with a JSON RPC HTTP server. | ||
* @param node - The AztecNode | ||
* @returns An JSON-RPC HTTP server | ||
*/ | ||
export function createAztecNodeRpcServer(node: AztecNode) { | ||
const rpc = new JsonRpcServer( | ||
node, | ||
{ | ||
AztecAddress, | ||
EthAddress, | ||
ExtendedUnencryptedL2Log, | ||
Fr, | ||
FunctionSelector, | ||
Header, | ||
L2Block, | ||
TxEffect, | ||
LogId, | ||
TxHash, | ||
Buffer32, | ||
PublicDataWitness, | ||
PublicKeys, | ||
SiblingPath, | ||
}, | ||
{ | ||
EncryptedNoteL2BlockL2Logs, | ||
EncryptedL2NoteLog, | ||
NoteSelector, | ||
NullifierMembershipWitness, | ||
PublicSimulationOutput, | ||
Tx, | ||
TxReceipt, | ||
UnencryptedL2BlockL2Logs, | ||
EpochProofQuote, | ||
}, | ||
// disable methods not part of the AztecNode interface | ||
['start', 'stop'], | ||
); | ||
return rpc; | ||
return createSafeJsonRpcServer(node, AztecNodeApiSchema); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,12 @@ | ||
import { | ||
AuthWitness, | ||
CountedNoteLog, | ||
CountedPublicExecutionRequest, | ||
EncryptedL2Log, | ||
EncryptedL2NoteLog, | ||
EncryptedNoteL2BlockL2Logs, | ||
EventMetadata, | ||
ExtendedNote, | ||
ExtendedUnencryptedL2Log, | ||
L2Block, | ||
LogId, | ||
Note, | ||
NullifierMembershipWitness, | ||
type PXE, | ||
PrivateExecutionResult, | ||
SiblingPath, | ||
Tx, | ||
TxEffect, | ||
TxExecutionRequest, | ||
TxHash, | ||
TxProvingResult, | ||
TxReceipt, | ||
TxSimulationResult, | ||
UnencryptedL2BlockL2Logs, | ||
UnencryptedL2Log, | ||
UniqueNote, | ||
} from '@aztec/circuit-types'; | ||
import { | ||
AztecAddress, | ||
CompleteAddress, | ||
EthAddress, | ||
Fr, | ||
FunctionSelector, | ||
GrumpkinScalar, | ||
Point, | ||
PrivateCircuitPublicInputs, | ||
PublicKeys, | ||
} from '@aztec/circuits.js'; | ||
import { EventSelector, NoteSelector } from '@aztec/foundation/abi'; | ||
import { Buffer32 } from '@aztec/foundation/buffer'; | ||
import { createJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client'; | ||
import { type PXE, PXESchema } from '@aztec/circuit-types'; | ||
import { createSafeJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client'; | ||
|
||
/** | ||
* Creates a JSON-RPC client to remotely talk to PXE. | ||
* @param url - The URL of the PXE. | ||
* @param fetch - The fetch implementation to use. | ||
* @returns A JSON-RPC client of PXE. | ||
*/ | ||
export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], false)): PXE => | ||
createJsonRpcClient<PXE>( | ||
url, | ||
{ | ||
AuthWitness, | ||
AztecAddress, | ||
CompleteAddress, | ||
FunctionSelector, | ||
EthAddress, | ||
EventSelector, | ||
ExtendedNote, | ||
UniqueNote, | ||
ExtendedUnencryptedL2Log, | ||
Fr, | ||
GrumpkinScalar, | ||
L2Block, | ||
TxEffect, | ||
LogId, | ||
Note, | ||
Point, | ||
PublicKeys, | ||
TxExecutionRequest, | ||
TxHash, | ||
Buffer32, | ||
SiblingPath, | ||
}, | ||
{ | ||
EncryptedNoteL2BlockL2Logs, | ||
EncryptedL2NoteLog, | ||
EncryptedL2Log, | ||
EventMetadata, | ||
UnencryptedL2Log, | ||
NoteSelector, | ||
NullifierMembershipWitness, | ||
TxSimulationResult, | ||
TxProvingResult, | ||
PrivateCircuitPublicInputs, | ||
PrivateExecutionResult, | ||
CountedPublicExecutionRequest, | ||
CountedNoteLog, | ||
Tx, | ||
TxReceipt, | ||
UnencryptedL2BlockL2Logs, | ||
}, | ||
false, | ||
'pxe', | ||
fetch, | ||
) as PXE; | ||
export function createPXEClient(url: string, fetch = makeFetch([1, 2, 3], false)): PXE { | ||
return createSafeJsonRpcClient<PXE>(url, PXESchema, false, 'pxe', fetch); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.