Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: unify Zero / Empty to Default + refactor away from std::unsafe::zeroed() #5496

Closed
wants to merge 60 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
45d39ab
initial
sklppy88 Mar 27, 2024
ae232cf
fix
sklppy88 Mar 28, 2024
95d2e36
fix
sklppy88 Mar 28, 2024
eef1ae4
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
sklppy88 Mar 28, 2024
94b50b8
fix build/test
sklppy88 Mar 28, 2024
0fe0c4b
fix
sklppy88 Mar 28, 2024
7d1d27d
fix
sklppy88 Mar 28, 2024
d6c67b6
fix
sklppy88 Mar 28, 2024
a3cd011
fix
sklppy88 Mar 28, 2024
0694acf
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
sklppy88 Mar 29, 2024
d5426e4
fix
sklppy88 Mar 29, 2024
8472c05
fix
sklppy88 Mar 29, 2024
9d23400
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
sklppy88 Mar 30, 2024
4ef2fcf
Fix
sklppy88 Mar 30, 2024
9f808e1
isdef ts
sklppy88 Mar 30, 2024
56009a0
fix
sklppy88 Mar 31, 2024
26e225a
Fix
sklppy88 Mar 31, 2024
ab830b4
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
sklppy88 Mar 31, 2024
97b9180
comment
sklppy88 Apr 1, 2024
dc0d26c
comment
sklppy88 Apr 1, 2024
512249c
comment
sklppy88 Apr 1, 2024
f6cdaa2
fix
sklppy88 Apr 1, 2024
6e536a7
edit
sklppy88 Apr 1, 2024
d738876
fix
sklppy88 Apr 1, 2024
933c73e
fixes
sklppy88 Apr 1, 2024
c9847c1
fixes
sklppy88 Apr 1, 2024
6669380
fix
sklppy88 Apr 1, 2024
34aa68d
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
sklppy88 Apr 5, 2024
b423c9a
fix
sklppy88 Apr 5, 2024
6e81f94
fix
sklppy88 Apr 5, 2024
1c433ed
fix
sklppy88 Apr 5, 2024
e2b1b53
address comments
sklppy88 Apr 5, 2024
1498c8b
fix
sklppy88 Apr 5, 2024
308b537
fix
sklppy88 Apr 5, 2024
1df2000
fix
sklppy88 Apr 5, 2024
af3a62e
fix msg
sklppy88 Apr 5, 2024
428621a
fix
sklppy88 Apr 5, 2024
57fbcbf
sync
sklppy88 Apr 5, 2024
626ba6a
sync
sklppy88 Apr 5, 2024
bcd67b3
align
sklppy88 Apr 5, 2024
6fd559f
fix
sklppy88 Apr 5, 2024
ac8e980
fix
sklppy88 Apr 5, 2024
5ea8eec
fix
sklppy88 Apr 5, 2024
2657a82
fix
sklppy88 Apr 5, 2024
b668055
fix
sklppy88 Apr 5, 2024
dad29c9
fix
sklppy88 Apr 5, 2024
7ba3c1c
fix
sklppy88 Apr 5, 2024
f1a1ef3
fix
sklppy88 Apr 5, 2024
3aedba2
fix
sklppy88 Apr 5, 2024
b78f9fd
address comments
sklppy88 Apr 5, 2024
34bb1b5
fix
sklppy88 Apr 6, 2024
a7a9bf8
noir
sklppy88 Apr 8, 2024
481d851
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
sklppy88 Apr 8, 2024
92d2f1f
fix
sklppy88 Apr 8, 2024
4aa05a6
yarn format
sklppy88 Apr 9, 2024
260b286
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
sklppy88 Apr 9, 2024
d07cd6a
l1 contracts ci
sklppy88 Apr 9, 2024
357490f
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
sklppy88 Apr 9, 2024
635f899
asdf
sklppy88 Apr 9, 2024
f8fdd28
Merge branch 'master' into ek/refactor/unify-zero-empty-to-default
sklppy88 Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix
  • Loading branch information
sklppy88 committed Apr 5, 2024
commit 5ea8eec4d592432826d98360db48ce9f734266ac
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ export class TokenContract extends ContractBase {
* Creates a tx to deploy a new instance of this contract.
*/
public static deploy(pxe: PXE, admin: AztecAddressLike) {
return new DeployMethod<TokenContract>(Point.ZERO, pxe, TokenContractArtifact, Array.from(arguments).slice(1));
return new DeployMethod<TokenContract>(Point.default(), pxe, TokenContractArtifact, Array.from(arguments).slice(1));
}

/**
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/contract/contract.ts
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ export class Contract extends ContractBase {
*/
public static deploy(wallet: Wallet, artifact: ContractArtifact, args: any[], constructorName?: string) {
const postDeployCtor = (address: AztecAddress, wallet: Wallet) => Contract.at(address, artifact, wallet);
return new DeployMethod(Point.ZERO, wallet, artifact, postDeployCtor, args, constructorName);
return new DeployMethod(Point.default(), wallet, artifact, postDeployCtor, args, constructorName);
}

/**
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/deployment/contract_deployer.ts
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ export class ContractDeployer {
public deploy(...args: any[]) {
const postDeployCtor = (address: AztecAddress, wallet: Wallet) => Contract.at(address, this.artifact, wallet);
return new DeployMethod(
this.publicKey ?? Point.ZERO,
this.publicKey ?? Point.default(),
this.wallet,
this.artifact,
postDeployCtor,
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/contract/contract_instance.ts
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ export function getContractInstanceFromDeployParams(
): ContractInstanceWithAddress {
const args = opts.constructorArgs ?? [];
const salt = opts.salt ?? Fr.random();
const publicKey = opts.publicKey ?? Point.ZERO;
const publicKey = opts.publicKey ?? Point.default();
const portalContractAddress = opts.portalAddress ?? EthAddress.default();
const constructorArtifact = getConstructorArtifact(artifact, opts.constructorArtifact);
const deployer = opts.deployer ?? AztecAddress.default();
6 changes: 3 additions & 3 deletions yarn-project/circuits.js/src/hints/build_hints.test.ts
Original file line number Diff line number Diff line change
@@ -165,8 +165,8 @@ describe('buildNullifierNonExistentReadRequestHints', () => {

it('builds default hints', async () => {
const hints = await buildHints();
const emptyHints = NullifierNonExistentReadRequestHintsBuilder.default();
expect(hints).toEqual(emptyHints);
const defaultHints = NullifierNonExistentReadRequestHintsBuilder.default();
expect(hints).toEqual(defaultHints);
});

it('builds hints for full sorted nullifiers', async () => {
@@ -200,7 +200,7 @@ describe('buildNullifierNonExistentReadRequestHints', () => {
expect(nullifiers[i].value.equals(sortedPendingValues[index].value)).toBe(true);
}

// The second half is empty.
// The second half is default (empty).
for (let i = numNonEmptyNullifiers; i < sortedPendingValues.length; ++i) {
expect(sortedPendingValues[i]).toEqual(SideEffectLinkedToNoteHash.default());
}
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/structs/l2_to_l1_message.ts
Original file line number Diff line number Diff line change
@@ -71,6 +71,6 @@ export class L2ToL1Message {
* @returns True if recipient is default and content is zero.
*/
isDefault(): boolean {
return this.recipient.isDefault() && this.content.isZero();
return this.recipient.isDefault() && this.content.isDefault();
}
}
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ export class NullifierKeyValidationRequest {
}

static default() {
return new NullifierKeyValidationRequest(Point.ZERO, GrumpkinScalar.ZERO);
return new NullifierKeyValidationRequest(Point.default(), GrumpkinScalar.ZERO);
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, mixing default and zero is kinda confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GrumpkinScalar is a Fq, and I didn't really want to mess with it :/

}
}

@@ -112,6 +112,6 @@ export class NullifierKeyValidationRequestContext {
}

static default() {
return new NullifierKeyValidationRequestContext(Point.ZERO, GrumpkinScalar.ZERO, AztecAddress.default());
return new NullifierKeyValidationRequestContext(Point.default(), GrumpkinScalar.ZERO, AztecAddress.default());
}
}
4 changes: 4 additions & 0 deletions yarn-project/foundation/src/fields/point.ts
Original file line number Diff line number Diff line change
@@ -34,6 +34,10 @@ export class Point {
return new Point(Fr.random(), Fr.random());
}

static default() {
return Point.default();
}

/**
* Create a Point instance from a given buffer or BufferReader.
* The input 'buffer' should have exactly 64 bytes representing the x and y coordinates.
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ function generateDeploy(input: ContractArtifact) {
* Creates a tx to deploy a new instance of this contract.
*/
public static deploy(wallet: Wallet, ${args}) {
return new DeployMethod<${contractName}>(Point.ZERO, wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(1));
return new DeployMethod<${contractName}>(Point.default(), wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(1));
}

/**
@@ -100,7 +100,7 @@ function generateDeploy(input: ContractArtifact) {
...args: Parameters<${contractName}['methods'][M]>
) {
return new DeployMethod<${contractName}>(
opts.publicKey ?? Point.ZERO,
opts.publicKey ?? Point.default(),
opts.wallet,
${artifactName},
${contractName}.at,
2 changes: 1 addition & 1 deletion yarn-project/protocol-contracts/src/gas-token/index.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { GasTokenArtifact } from './artifact.js';

/** Returns the canonical deployment of the gas token. */
export function getCanonicalGasToken(l1Bridge: EthAddress): ProtocolContract {
return getCanonicalProtocolContract(GasTokenArtifact, 1, [], Point.ZERO, l1Bridge);
return getCanonicalProtocolContract(GasTokenArtifact, 1, [], Point.default(), l1Bridge);
}

export function getCanonicalGasTokenAddress(l1Bridge: EthAddress): AztecAddress {
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol
import { MultiCallEntrypointArtifact } from './artifact.js';

export function getCanonicalMultiCallEntrypointContract(): ProtocolContract {
return getCanonicalProtocolContract(MultiCallEntrypointArtifact, 1, [], Point.ZERO, EthAddress.default());
return getCanonicalProtocolContract(MultiCallEntrypointArtifact, 1, [], Point.default(), EthAddress.default());
}

export function getCanonicalMultiCallEntrypointAddress(): AztecAddress {
2 changes: 1 addition & 1 deletion yarn-project/protocol-contracts/src/protocol_contract.ts
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ export function getCanonicalProtocolContract(
artifact: ContractArtifact,
salt: Fr | number | bigint,
constructorArgs: any[] = [],
publicKey: Point = Point.ZERO,
publicKey: Point = Point.default(),
portalAddress = EthAddress.default(),
): ProtocolContract {
// TODO(@spalladino): This computes the contract class from the artifact twice.