-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add batched signerless contract calls
- Loading branch information
Showing
6 changed files
with
165 additions
and
7 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
9 changes: 9 additions & 0 deletions
9
noir-projects/noir-contracts/contracts/signerless_entrypoint_contract/Nargo.toml
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "signerless_entrypoint_contract" | ||
authors = [""] | ||
compiler_version = ">=0.18.0" | ||
type = "contract" | ||
|
||
[dependencies] | ||
aztec = { path = "../../../aztec-nr/aztec" } | ||
authwit = { path = "../../../aztec-nr/authwit" } |
13 changes: 13 additions & 0 deletions
13
noir-projects/noir-contracts/contracts/signerless_entrypoint_contract/src/main.nr
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// An entrypoint contract that allows everything to go through. Only used for testing | ||
// Pair this with SignerlessWallet to perform multiple actions before any account contracts are deployed (and without authentication) | ||
contract SignerlessEntrypoint { | ||
use dep::std; | ||
|
||
use dep::aztec::prelude::AztecAddress; | ||
use dep::authwit::entrypoint::app::AppPayload; | ||
|
||
#[aztec(private)] | ||
fn entrypoint(app_payload: pub AppPayload) { | ||
app_payload.execute_calls(&mut context); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
yarn-project/aztec.js/src/entrypoint/signerless_entrypoint.ts
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/circuit-types'; | ||
import { AztecAddress, FunctionData, TxContext } from '@aztec/circuits.js'; | ||
import { FunctionAbi, encodeArguments } from '@aztec/foundation/abi'; | ||
|
||
import { EntrypointInterface } from '../account/interface.js'; | ||
import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js'; | ||
import { buildAppPayload } from './entrypoint_payload.js'; | ||
|
||
/** | ||
* Interface to a contract that forwards functions calls directly, without any authentication or signing. | ||
*/ | ||
export class SignerlessEntrypoint implements EntrypointInterface { | ||
constructor( | ||
private address: AztecAddress, | ||
private chainId: number = DEFAULT_CHAIN_ID, | ||
private version: number = DEFAULT_VERSION, | ||
) {} | ||
|
||
createTxExecutionRequest(executions: FunctionCall[]): Promise<TxExecutionRequest> { | ||
const { payload: appPayload, packedArguments: appPackedArguments } = buildAppPayload(executions); | ||
|
||
const abi = this.getEntrypointAbi(); | ||
const entrypointPackedArgs = PackedArguments.fromArgs(encodeArguments(abi, [appPayload])); | ||
const txRequest = TxExecutionRequest.from({ | ||
argsHash: entrypointPackedArgs.hash, | ||
origin: this.address, | ||
functionData: FunctionData.fromAbi(abi), | ||
txContext: TxContext.empty(this.chainId, this.version), | ||
packedArguments: [...appPackedArguments, entrypointPackedArgs], | ||
authWitnesses: [], | ||
}); | ||
|
||
return Promise.resolve(txRequest); | ||
} | ||
|
||
private getEntrypointAbi() { | ||
return { | ||
name: 'entrypoint', | ||
isInitializer: false, | ||
functionType: 'secret', | ||
isInternal: false, | ||
parameters: [ | ||
{ | ||
name: 'app_payload', | ||
type: { | ||
kind: 'struct', | ||
path: 'authwit::entrypoint::app::AppPayload', | ||
fields: [ | ||
{ | ||
name: 'function_calls', | ||
type: { | ||
kind: 'array', | ||
length: 4, | ||
type: { | ||
kind: 'struct', | ||
path: 'authwit::entrypoint::function_call::FunctionCall', | ||
fields: [ | ||
{ name: 'args_hash', type: { kind: 'field' } }, | ||
{ | ||
name: 'function_selector', | ||
type: { | ||
kind: 'struct', | ||
path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector', | ||
fields: [{ name: 'inner', type: { kind: 'integer', sign: 'unsigned', width: 32 } }], | ||
}, | ||
}, | ||
{ | ||
name: 'target_address', | ||
type: { | ||
kind: 'struct', | ||
path: 'authwit::aztec::protocol_types::address::AztecAddress', | ||
fields: [{ name: 'inner', type: { kind: 'field' } }], | ||
}, | ||
}, | ||
{ name: 'is_public', type: { kind: 'boolean' } }, | ||
], | ||
}, | ||
}, | ||
}, | ||
{ name: 'nonce', type: { kind: 'field' } }, | ||
], | ||
}, | ||
visibility: 'public', | ||
}, | ||
], | ||
returnTypes: [], | ||
} as FunctionAbi; | ||
} | ||
} |
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