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

feat: fix contract membership check #3034

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export function generateFunctionLeaves(functions: ContractFunctionDao[], wasm: C
const isInternal = f.isInternal;
const isPrivate = f.functionType === FunctionType.SECRET;
// All non-unconstrained functions have vks
const vkHash = hashVKStr(f.verificationKey!, wasm);
// TODO we'd need to have a defined length of the VK for this to be computed in noir
// const vkHash = hashVKStr(f.verificationKey!, wasm);
const vkHash = Buffer.alloc(32, 0);
// TODO
// FIXME: https://github.com/AztecProtocol/aztec3-packages/issues/262
// const acirHash = keccak(Buffer.from(f.bytecode, 'hex'));
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('e2e_cross_chain_messaging', () => {
);
await crossChainTestHarness.redeemShieldPrivatelyOnL2(bridgeAmount, secretForRedeemingMintedNotes);
await crossChainTestHarness.expectPrivateBalanceOnL2(ownerAddress, bridgeAmount);
}, 50_000);
}, 120_000);

it("Bridge can't withdraw my funds if I don't give approval", async () => {
const mintAmountToUser1 = 100n;
Expand All @@ -201,7 +201,7 @@ describe('e2e_cross_chain_messaging', () => {
.methods.exit_to_l1_private(l2Token.address, ethAccount, withdrawAmount, EthAddress.ZERO, nonce)
.simulate(),
).rejects.toThrowError(`Unknown auth witness for message hash 0x${expectedBurnMessageHash.toString('hex')}`);
});
}, 120_000);

it("Can't claim funds publicly if they were deposited privately", async () => {
// 1. Mint tokens on L1
Expand Down Expand Up @@ -234,5 +234,5 @@ describe('e2e_cross_chain_messaging', () => {
).rejects.toThrowError(
"Failed to solve brillig function, reason: explicit trap hit in brillig 'l1_to_l2_message_data.message.content == content'",
);
});
}, 120_000);
});
8 changes: 4 additions & 4 deletions yarn-project/end-to-end/src/guides/up_quick_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
set -eux

# docs:start:declare-accounts
ALICE="0x0f394e8bd156e15153376a711e3054821c2a1c1047dcfb3745d636a57fb42ab1"
BOB="0x2b67f90f0044596190644ddafea4152de47bd4781559493860fa7358e19d090a"
ALICE="0x16efad912187aa8ef0dcc6ef4f3743ab327b06465d4d229943f2fe3f88b06ad9"
BOB="0x17f5e66bfe7dafc76434268bcb3968a8bc207b476aeed78d1e4a2f02aad45842"
ALICE_PRIVATE_KEY="0x2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281"
# docs:end:declare-accounts

Expand All @@ -15,9 +15,9 @@ aztec-cli deploy \
--salt 0 \
--args $ALICE

aztec-cli check-deploy --contract-address 0x2f45f498b7912c779dde8e3594622e36d7908088b09e99ab91caaafb40d1f9ef
aztec-cli check-deploy --contract-address 0x0ed3aaa22d69559ee368b32fbafb24b49b103c0a07bd834fd519c8157553ec1f

CONTRACT="0x2f45f498b7912c779dde8e3594622e36d7908088b09e99ab91caaafb40d1f9ef"
CONTRACT="0x0ed3aaa22d69559ee368b32fbafb24b49b103c0a07bd834fd519c8157553ec1f"
# docs:end:deploy

# docs:start:mint-private
Expand Down
Original file line number Diff line number Diff line change
@@ -1,61 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Noir compatibility tests (interop_testing.nr) Complete Address matches Noir 1`] = `
CompleteAddress {
"address": AztecAddress {
"buffer": {
"data": [
26,
110,
137,
176,
52,
71,
135,
19,
199,
169,
241,
199,
127,
184,
10,
249,
149,
247,
8,
246,
242,
8,
191,
53,
43,
77,
218,
33,
36,
115,
145,
9,
],
"type": "Buffer",
},
},
"partialAddress": Fr {
"value": 11517109422981783267562923429265051163864675433397402239476609863059550730459n,
exports[`Noir compatibility tests (interop_testing.nr) Complete Address matches Noir 1`] = `"0x1a6e89b034478713c7a9f1c77fb80af995f708f6f208bf352b4dda2124739109"`;

exports[`Noir compatibility tests (interop_testing.nr) Complete Address matches Noir 2`] = `
Point {
"kind": "point",
"x": Fr {
"value": 1n,
},
"publicKey": Point {
"kind": "point",
"x": Fr {
"value": 1n,
},
"y": Fr {
"value": 2n,
},
"y": Fr {
"value": 2n,
},
}
`;

exports[`Noir compatibility tests (interop_testing.nr) Complete Address matches Noir 3`] = `"0x197673f31940878b2d6c681223dbed9cfacd2f722cbe30155225b2ada17778db"`;

exports[`Noir compatibility tests (interop_testing.nr) ComputeContractAddressFromPartial matches Noir 1`] = `"0x0b487ff2900ae1178e131bfe333fdbc351beef658f7c0d62db2801429b1aab75"`;

exports[`Noir compatibility tests (interop_testing.nr) Function leaf matches noir 1`] = `"0x1ad8ece7f40e63d011ae47c6ce6cdaf31d632a23f5cf35bbeaaf69c8302afdbc"`;

exports[`Noir compatibility tests (interop_testing.nr) TxRequest Hash matches Noir 1`] = `"0x0b487ff2900ae1178e131bfe333fdbc351beef658f7c0d62db2801429b1aab75"`;
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ pub fn contract_logic(private_call : PrivateCallData, public_inputs : &mut Kerne
private_call.contract_leaf_membership_witness.sibling_path);

let purported_contract_tree_root = private_call.call_stack_item.public_inputs().historical_block_data.contract_tree_root();
// assert(computed_contract_tree_root == purported_contract_tree_root, "computed_contract_tree_root doesn't match purported_contract_tree_root");
assert_eq(computed_contract_tree_root, purported_contract_tree_root, "computed_contract_tree_root doesn't match purported_contract_tree_root");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::transaction::request::TxRequest;
use crate::address::{Address, EthAddress};
use crate::transaction::context::TxContext;
use crate::abis::function_data::FunctionData;
use crate::abis::function_leaf_preimage::FunctionLeafPreimage;
use crate::contrakt::deployment_data::ContractDeploymentData;
use crate::abis::function_selector::FunctionSelector;
use crate::hash::compute_l2_to_l1_hash;
Expand All @@ -21,8 +22,8 @@ fn compute_complete_address() {

let complete_address = CompleteAddress::compute(point, contract_address_salt, function_tree_root, constructor_hash);

assert(complete_address.partial_address == 0x2d21887e877530560476baa456091e3ec947feb8c80a8d8b271aca475b3d0d2f);
assert(complete_address.address.to_field() == 0x0343055cb133a46b33e482843fc73f03697ee869f1786c1d15655a0ece4da1d4);
assert(complete_address.partial_address == 0x197673f31940878b2d6c681223dbed9cfacd2f722cbe30155225b2ada17778db);
assert(complete_address.address.to_field() == 0x1a6e89b034478713c7a9f1c77fb80af995f708f6f208bf352b4dda2124739109);
assert(complete_address.public_key.x == 1);
assert(complete_address.public_key.y == 2);
}
Expand Down Expand Up @@ -54,7 +55,7 @@ fn compute_tx_request_hash() {
is_constructor : true,
}
};
assert(tx_request.hash() == 0x030d01a52e494df23f5835c597bd53e194d5c27db185a720e55caa95561a1115);
assert(tx_request.hash() == 0x0b487ff2900ae1178e131bfe333fdbc351beef658f7c0d62db2801429b1aab75);
}

#[test]
Expand Down Expand Up @@ -82,4 +83,17 @@ fn smoke_sha256_to_field() {
];
let result = sha256_to_field(full_buffer);
assert( result == 0x142a6d57007171f6eaa33d55976d9dbe739c889c8e920f115f7808dea184c718);
}

#[test]
fn compute_function_leaf() {
let leaf = FunctionLeafPreimage {
selector: FunctionSelector::from_u32(27),
is_internal: false,
is_private: true,
vk_hash: 1,
acir_hash: 2,
};

assert_eq(leaf.hash(), 0x1ad8ece7f40e63d011ae47c6ce6cdaf31d632a23f5cf35bbeaaf69c8302afdbc);
}
16 changes: 14 additions & 2 deletions yarn-project/noir-private-kernel/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
ContractDeploymentData,
EthAddress,
FunctionData,
FunctionLeafPreimage,
FunctionSelector,
Point,
TxContext,
TxRequest,
Expand All @@ -11,7 +13,7 @@ import {
makePrivateKernelInputsInit,
makeSelector,
} from '@aztec/circuits.js';
import { computeCompleteAddress, computeTxHash } from '@aztec/circuits.js/abis';
import { computeCompleteAddress, computeFunctionLeaf, computeTxHash } from '@aztec/circuits.js/abis';
import { Fr } from '@aztec/foundation/fields';
import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';

Expand Down Expand Up @@ -71,7 +73,9 @@ describe('Noir compatibility tests (interop_testing.nr)', () => {

const res = computeCompleteAddress(wasm, deployerPubKey, contractAddrSalt, treeRoot, constructorHash);

expect(res).toMatchSnapshot();
expect(res.address.toString()).toMatchSnapshot();
expect(res.publicKey).toMatchSnapshot();
expect(res.partialAddress.toString()).toMatchSnapshot();
});

it('TxRequest Hash matches Noir', async () => {
Expand Down Expand Up @@ -115,6 +119,14 @@ describe('Noir compatibility tests (interop_testing.nr)', () => {

expect(hash.toString()).toMatchSnapshot();
});

it('Function leaf matches noir', async () => {
const wasm = await CircuitsWasm.get();

const fnLeafPreimage = new FunctionLeafPreimage(new FunctionSelector(27), false, true, new Fr(1), new Fr(2));
const fnLeaf = computeFunctionLeaf(wasm, fnLeafPreimage);
expect(fnLeaf.toString()).toMatchSnapshot();
});
});

function numberToBuffer(value: number) {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading