Skip to content

Commit

Permalink
fix: cli fixes (#7543)
Browse files Browse the repository at this point in the history
- accept numeric salts (e.g. `123` is parsed to `Fr<0x0123>`)
- streamline `--init/--no-init`
`--public-deployment/--no-public-deployment` and
`--class-registeration/--no-class-registration` flags when deploying
contracts

---------

Co-authored-by: spypsy <spypsy@users.noreply.github.com>
Co-authored-by: spypsy <spypsy@outlook.com>
Co-authored-by: PhilWindle <60546371+PhilWindle@users.noreply.github.com>
  • Loading branch information
4 people authored Jul 22, 2024
1 parent 77ce1c3 commit 689000a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
16 changes: 7 additions & 9 deletions yarn-project/cli/src/cmds/pxe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
'<artifact>',
"A compiled Aztec.nr contract's artifact in JSON format or name of a contract artifact exported by @aztec/noir-contracts.js",
)
.option('--initialize <string>', 'The contract initializer function to call', 'constructor')
.option('--no-initialize')
.option('--init <string>', 'The contract initializer function to call', 'constructor')
.option('--no-init', 'Leave the contract uninitialized')
.option('-a, --args <constructorArgs...>', 'Contract constructor arguments', [])
.addOption(pxeOption)
.option(
Expand All @@ -88,10 +88,8 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
// `options.wait` is default true. Passing `--no-wait` will set it to false.
// https://github.com/tj/commander.js#other-option-types-negatable-boolean-and-booleanvalue
.option('--no-wait', 'Skip waiting for the contract to be deployed. Print the hash of deployment transaction')
.option('--class-registration', 'Register the contract class. Only has to be done once')
.option('--no-class-registration', 'Skip registering the contract class')
.option('--public-deployment', 'Deploy the public bytecode of contract')
.option('--no-public-deployment', "Skip deploying the contract's public bytecode");
.option('--no-class-registration', "Don't register this contract class")
.option('--no-public-deployment', "Don't emit this contract's public bytecode");
addOptions(deployCommand, FeeOpts.getOptions()).action(async (artifactPath, opts) => {
const { deploy } = await import('./deploy.js');
const {
Expand All @@ -103,7 +101,7 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
wait,
privateKey,
classRegistration,
initialize,
init,
publicDeployment,
universal,
} = opts;
Expand All @@ -115,10 +113,10 @@ export function injectCommands(program: Command, log: LogFn, debugLogger: DebugL
rawArgs,
salt,
privateKey,
typeof initialize === 'string' ? initialize : undefined,
typeof init === 'string' ? init : undefined,
!publicDeployment,
!classRegistration,
typeof initialize === 'string' ? false : initialize,
typeof init === 'string' ? false : init,
universal,
wait,
FeeOpts.fromCli(opts, log),
Expand Down
19 changes: 19 additions & 0 deletions yarn-project/cli/src/utils/commands.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Fr } from '@aztec/circuits.js';

import { parseFieldFromHexString } from './commands.js';

describe('parseFieldFromHexString', () => {
it.each<[string, Fr]>([
['0', Fr.ZERO],
['0x0', Fr.ZERO],
['0x1', new Fr(1)],
['0x00', Fr.ZERO],
['fa', new Fr(0xfa)],
['123', new Fr(0x0123)],
['0xff', new Fr(255)],
['0x0000000000000000000000000000000000000000000000000000000000000003', new Fr(3)],
['0x00000000000000000000000000000000000000000000000000000000000000003', new Fr(3)],
])('parses the field %s correctly', (str, expected) => {
expect(parseFieldFromHexString(str)).toEqual(expected);
});
});
9 changes: 8 additions & 1 deletion yarn-project/cli/src/utils/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,16 @@ export function parseFieldFromHexString(str: string): Fr {
// pad it so that we may read it as a buffer.
// Buffer needs _exactly_ two hex characters per byte
const padded = hex.length % 2 === 1 ? '0' + hex : hex;
let buf = Buffer.from(padded, 'hex');
if (buf.length > Fr.SIZE_IN_BYTES) {
buf = buf.subarray(buf.length - Fr.SIZE_IN_BYTES);
}

const fr = Buffer.alloc(Fr.SIZE_IN_BYTES, 0);
fr.set(buf, Fr.SIZE_IN_BYTES - buf.length);

// finally, turn it into an integer
return Fr.fromBuffer(Buffer.from(padded, 'hex'));
return Fr.fromBuffer(fr);
}

/**
Expand Down

0 comments on commit 689000a

Please sign in to comment.