From b3c2a5b449912de97ab26609b39f7368b36af6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bene=C5=A1?= Date: Thu, 24 Aug 2023 12:45:28 +0200 Subject: [PATCH] feat: no unencrypted logs in private functions (#1780) Fixes #1689 --- docs/docs/dev_docs/contracts/events.md | 18 +++++----- docs/docs/dev_docs/getting_started/cli.md | 13 ------- docs/docs/dev_docs/getting_started/sandbox.md | 36 ++----------------- .../src/abis/ecdsa_account_contract.json | 24 ++++++------- .../src/abis/schnorr_account_contract.json | 24 ++++++------- .../schnorr_single_key_account_contract.json | 12 +++---- .../end-to-end/src/e2e_2_rpc_servers.test.ts | 10 +----- .../e2e_multiple_accounts_1_enc_key.test.ts | 7 +--- .../src/e2e_private_token_contract.test.ts | 10 +----- .../src/e2e_public_token_contract.test.ts | 21 +++-------- .../src/e2e_sandbox_example.test.ts | 34 +----------------- yarn-project/end-to-end/src/fixtures/utils.ts | 4 +++ .../easy_private_token_contract/src/main.nr | 7 ---- .../src/main.nr | 1 - .../contracts/lending_contract/src/main.nr | 1 - .../src/main.nr | 4 --- .../private_token_contract/src/main.nr | 15 -------- .../public_token_contract/src/main.nr | 6 ++++ 18 files changed, 60 insertions(+), 187 deletions(-) diff --git a/docs/docs/dev_docs/contracts/events.md b/docs/docs/dev_docs/contracts/events.md index 5eb174bbf479..e115cd4a2778 100644 --- a/docs/docs/dev_docs/contracts/events.md +++ b/docs/docs/dev_docs/contracts/events.md @@ -61,6 +61,14 @@ Emitting unencrypted events from private function is a significant privacy leak ::: +To emit unencrypted logs first import the `emit_unencrypted_log` utility function inside your contract: + +#include_code unencrypted_import /yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr rust + +Then you can call the function: + +#include_code unencrypted_log /yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr rust + Once emitted, unencrypted events are stored in AztecNode and can be queried by anyone: @@ -72,19 +80,11 @@ aztec-cli get-logs --from 5 --limit 1 -#include_code logs /yarn-project/end-to-end/src/e2e_public_token_contract.test.ts typescript +#include_code get_logs /yarn-project/end-to-end/src/fixtures/utils.ts typescript -To emit unencrypted logs first import the `emit_unencrypted_log` utility function inside your contract: - -#include_code unencrypted_import /yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr rust - -Then you can call the function: - -#include_code unencrypted /yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr rust - ### Costs All event data is pushed to Ethereum as calldata by the sequencer and for this reason the cost of emitting an event is non-trivial. diff --git a/docs/docs/dev_docs/getting_started/cli.md b/docs/docs/dev_docs/getting_started/cli.md index 6272d5f94632..c7057f122412 100644 --- a/docs/docs/dev_docs/getting_started/cli.md +++ b/docs/docs/dev_docs/getting_started/cli.md @@ -216,16 +216,3 @@ View result: [ "{\"type\":\"bigint\",\"data\":\"543\"}" ] ``` - -## Logs - -Finally, we can use the CLI's `get-logs` command to retrieve unencrypted logs emitted by the contract: - -``` -% aztec-cli get-logs --from 5 --limit 1 -Logs found: - -Coins transferred -``` - -Here we asked for the logs from block 5 (the block in which our call to `transfer` was mined) and to include a total of 1 block's worth of logs. The text `Coins Transferred` is emitted during the execution of the `transfer` function on the contract. diff --git a/docs/docs/dev_docs/getting_started/sandbox.md b/docs/docs/dev_docs/getting_started/sandbox.md index adf2dbdfd402..b68f472c4658 100644 --- a/docs/docs/dev_docs/getting_started/sandbox.md +++ b/docs/docs/dev_docs/getting_started/sandbox.md @@ -56,7 +56,6 @@ With the help of Aztec.js you will be able to: - Simulate the calling of contract functions - Send transactions to the network - Be notified when transactions settle -- Retrieve and view unencrypted logs emitted by contracts - Query chain state such as chain id, block number etc. ## I have the Sandbox running, show me how to use it! @@ -215,14 +214,14 @@ Running `yarn start` should now output: That might seem like a lot to digest but it can be broken down into the following steps: -1. We create 2 `Account` objects in Typescript. This object heavily abstracts away the mechanics of configuring and deploying an account contract and setting up a 'wallet' for signing transactions. If you aren't interested in building new types of account contracts or wallets then you don't need to be too concerned with it. In this example we have constructed account contracts and corresposing wallets that sign/verify transactions using schnorr signatures. +1. We create 2 `Account` objects in Typescript. This object heavily abstracts away the mechanics of configuring and deploying an account contract and setting up a 'wallet' for signing transactions. If you aren't interested in building new types of account contracts or wallets then you don't need to be too concerned with it. In this example we have constructed account contracts and corresponding wallets that sign/verify transactions using schnorr signatures. 2. We wait for the deployment of the 2 account contracts to complete. 3. We retrieve the expected account addresses from the `Account` objects and ensure that they are present in the set of account addresses registered on the Sandbox. Note, we use the `getAccounts` api to verify that the addresses computed as part of the account contract deployment have been successfully added to the Sandbox. -If you were looking at your terminal that is running the Sandbox you should hopefully have seen a lot of activity. This is because the Sandbox will have simulated the deployment of both contracts, executed the private kernel circuit for each before submitted 2 transactions to the pool. The sequencer will have picked them up and inserted them into a rollup and executed the recursive rollup circuits before publising the rollup to Anvil. Once this has completed, the rollup is retrieved and pulled down to the internal RPC Server so that any new account state can be decrypted. +If you were looking at your terminal that is running the Sandbox you should hopefully have seen a lot of activity. This is because the Sandbox will have simulated the deployment of both contracts, executed the private kernel circuit for each before submitted 2 transactions to the pool. The sequencer will have picked them up and inserted them into a rollup and executed the recursive rollup circuits before publishing the rollup to Anvil. Once this has completed, the rollup is retrieved and pulled down to the internal RPC Server so that any new account state can be decrypted. ## Token Contract Deployment @@ -250,14 +249,6 @@ We can break this down as follows: 4. We use the `getContractInfo()` api on the RPC Server to retrieve information about the reported contract address. 5. The fact that this api returns a valid object tells us that the contract was successfully deployed in a prior block. -The Private Token Contract emits an unencrypted log message during construction: - -#include_code constructor /yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr rust - -We can retrieve this emitted log using the `getUnencryptedLogs()` api: - -#include_code Logs /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript - Our output will now be: ``` @@ -266,14 +257,9 @@ Our output will now be: private-token Created Alice's account at 0x054d89d0...f17e +23s private-token Created Bob's account at 0x0a8410a1...7c48 +1ms private-token Deploying private token contract minting an initial 1000000 tokens to Alice... +0ms - private-token Transaction status is mined +8s private-token Contract successfully deployed at address 0x143e0af4...11b6 +7ms - private-token Retrieving unencrypted logs for block 3 +4ms - private-token Emitted logs: [ 'Balance set in constructor' ] +5ms ``` -Note how we used the `getBlockNum()` api to retrieve the number of the last mined block. This is the block for which we want to retrieve logs as it is the last mined block number. - ## Viewing the balance of an account A token contract wouldn't be very useful if you aren't able to query the balance of an account. As part of the deployment, tokens were minted to Alice. We can now call the contract's `getBalance()` function to retrieve the balances of the accounts. @@ -294,8 +280,6 @@ Running now should yield output: private-token Deploying private token contract minting an initial 1000000 tokens to Alice... +0ms private-token Transaction status is mined +8s private-token Contract successfully deployed at address 0x143e0af4...11b6 +7ms - private-token Retrieving unencrypted logs for block 3 +4ms - private-token Emitted logs: [ 'Balance set in constructor' ] +5ms private-token Alice's balance 1000000 +4s private-token Bob's balance 0 +3s ``` @@ -314,8 +298,6 @@ Now lets transfer some funds from Alice to Bob by calling the `transfer` functio #include_code transfer /yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr rust -We will again view the unencrypted logs emitted by the function and check the balances after the transfer: - #include_code Transfer /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript Our output should now look like this: @@ -326,20 +308,15 @@ Our output should now look like this: private-token Created Alice's account at 0x054d89d0...f17e +23s private-token Created Bob's account at 0x0a8410a1...7c48 +1ms private-token Deploying private token contract minting an initial 1000000 tokens to Alice... +0ms - private-token Transaction status is mined +8s private-token Contract successfully deployed at address 0x143e0af4...11b6 +7ms - private-token Retrieving unencrypted logs for block 3 +4ms - private-token Emitted logs: [ 'Balance set in constructor' ] +5ms private-token Alice's balance 1000000 +4s private-token Bob's balance 0 +3s private-token Transferring 543 tokens from Alice to Bob... +0ms - private-token Retrieving unencrypted logs for block 4 +20s - private-token Emitted logs: [ 'Coins transferred' ] +13ms private-token Alice's balance 999457 +4s private-token Bob's balance 543 +3s ``` -Here, we used the same contract abstraction as was previously used for reading Alice's balance. But this time we called `send()` generating and sending a transaction to the network. After waiting for the transaction to settle we were able to retrieve the newly emitted unencrypted logs and check the new balance values. +Here, we used the same contract abstraction as was previously used for reading Alice's balance. But this time we called `send()` generating and sending a transaction to the network. After waiting for the transaction to settle we were able to check the new balance values. Finally, the contract has a `mint` function that can be used to generate new tokens for an account. This takes 2 arguments: @@ -360,20 +337,13 @@ Our complete output should now be: private-token Created Alice's account at 0x054d89d0...f17e +23s private-token Created Bob's account at 0x0a8410a1...7c48 +1ms private-token Deploying private token contract minting an initial 1000000 tokens to Alice... +0ms - private-token Transaction status is mined +8s private-token Contract successfully deployed at address 0x143e0af4...11b6 +7ms - private-token Retrieving unencrypted logs for block 3 +4ms - private-token Emitted logs: [ 'Balance set in constructor' ] +5ms private-token Alice's balance 1000000 +4s private-token Bob's balance 0 +3s private-token Transferring 543 tokens from Alice to Bob... +0ms - private-token Retrieving unencrypted logs for block 4 +20s - private-token Emitted logs: [ 'Coins transferred' ] +13ms private-token Alice's balance 999457 +4s private-token Bob's balance 543 +3s private-token Minting 10000 tokens to Bob... +1ms - private-token Retrieving unencrypted logs for block 5 +13s - private-token Emitted logs: [ 'Coins minted' ] +13ms private-token Alice's balance 999457 +4s private-token Bob's balance 10543 +4s ``` diff --git a/yarn-project/aztec.js/src/abis/ecdsa_account_contract.json b/yarn-project/aztec.js/src/abis/ecdsa_account_contract.json index fbf73e265e25..988773307d4c 100644 --- a/yarn-project/aztec.js/src/abis/ecdsa_account_contract.json +++ b/yarn-project/aztec.js/src/abis/ecdsa_account_contract.json @@ -166,7 +166,7 @@ "fileMap": { "0": { "source": "mod storage;\nmod ecdsa_public_key_note;\n\n// Account contract that uses ECDSA signatures for authentication on the same curve as Ethereum.\n// The signing key is stored in an immutable private note and should be different from the signing key.\ncontract EcdsaAccount {\n use dep::std;\n use dep::aztec::entrypoint;\n use dep::aztec::entrypoint::EntrypointPayload;\n use dep::aztec::abi;\n use dep::aztec::abi::PrivateContextInputs;\n use dep::aztec::abi::CallContext;\n use dep::aztec::context::PrivateContext;\n use dep::aztec::log::emit_encrypted_log;\n use dep::aztec::oracle::get_public_key::get_public_key;\n use dep::aztec::types::vec::BoundedVec;\n use dep::aztec::types::point::Point;\n use dep::aztec::constants_gen::GENERATOR_INDEX__SIGNATURE_PAYLOAD;\n\n use dep::aztec::constants_gen::MAX_NOTE_FIELDS_LENGTH;\n use dep::aztec::note::{\n note_header::{NoteHeader},\n utils as note_utils,\n };\n\n use crate::storage::Storage;\n use crate::ecdsa_public_key_note::EcdsaPublicKeyNote;\n use crate::ecdsa_public_key_note::EcdsaPublicKeyNoteInterface;\n use crate::ecdsa_public_key_note::ECDSA_PUBLIC_KEY_NOTE_LEN;\n\n // All calls made by this account will be routed through this entrypoint\n fn entrypoint( \n inputs: pub PrivateContextInputs,\n payload: pub EntrypointPayload, // contains a set of arguments, selectors, targets and a nonce\n signature: pub [u8;64],\n ) -> distinct pub abi::PrivateCircuitPublicInputs {\n \n // Initialise context\n // ENTRYPOINT_PAYLOAD_SIZE(13) + 64\n let mut args: BoundedVec = BoundedVec::new(0);\n args.push_array(payload.serialize());\n for byte in signature { args.push(byte as Field); }\n let mut context = PrivateContext::new(inputs, abi::hash_args(args.storage));\n\n // Load public key from storage\n let storage = Storage::init();\n let public_key = storage.public_key.get_note(&mut context);\n\n // Verify payload signature using Ethereum's signing scheme\n // Note that noir expects the hash of the message/challenge as input to the ECDSA verification.\n let payload_fields: [Field; entrypoint::ENTRYPOINT_PAYLOAD_SIZE] = payload.serialize();\n let message_field: Field = std::hash::pedersen_with_separator(payload_fields, GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0];\n let message_bytes = message_field.to_be_bytes(32);\n let hashed_message: [u8; 32] = std::hash::sha256(message_bytes);\n let verification = std::ecdsa_secp256k1::verify_signature(public_key.x, public_key.y, signature, hashed_message);\n assert(verification == true);\n\n payload.execute_calls(&mut context);\n\n context.finish()\n }\n\n // Creates a new account out of an ECDSA public key to use for signature verification\n fn constructor(\n inputs: pub PrivateContextInputs,\n signing_pub_key_x: pub [u8;32],\n signing_pub_key_y: pub [u8;32],\n ) -> distinct pub abi::PrivateCircuitPublicInputs {\n let storage = Storage::init();\n \n let mut args: BoundedVec = BoundedVec::new(0);\n for byte in signing_pub_key_x { args.push(byte as Field); }\n for byte in signing_pub_key_y { args.push(byte as Field); }\n let mut context = PrivateContext::new(inputs, abi::hash_args(args.storage));\n \n let this = context.this_address();\n let mut pub_key_note = EcdsaPublicKeyNote::new(signing_pub_key_x, signing_pub_key_y, this);\n storage.public_key.initialise(&mut context, &mut pub_key_note);\n \n emit_encrypted_log(\n &mut context,\n this,\n storage.public_key.storage_slot,\n get_public_key(this),\n pub_key_note.serialise(),\n );\n\n context.finish()\n }\n\n // Computes note hash and nullifier.\n // Note 1: Needs to be defined by every contract producing logs.\n // Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.\n unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; ECDSA_PUBLIC_KEY_NOTE_LEN]) -> [Field; 4] {\n assert(storage_slot == 1);\n let note_header = NoteHeader { contract_address, nonce, storage_slot };\n note_utils::compute_note_hash_and_nullifier(EcdsaPublicKeyNoteInterface, note_header, preimage)\n }\n}\n", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/main" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-contracts/src/contracts/ecdsa_account_contract/src/main" }, "3": { "source": "mod poseidon;\n\n#[foreign(sha256)]\nfn sha256(_input : [u8; N]) -> [u8; 32] {}\n\n#[foreign(blake2s)]\nfn blake2s(_input : [u8; N]) -> [u8; 32] {}\n\nfn pedersen(input : [Field; N]) -> [Field; 2] {\n pedersen_with_separator(input, 0)\n}\n\n#[foreign(pedersen)]\nfn pedersen_with_separator(_input : [Field; N], _separator : u32) -> [Field; 2] {}\n\n#[foreign(hash_to_field_128_security)]\nfn hash_to_field(_input : [Field; N]) -> Field {}\n\n#[foreign(keccak256)]\nfn keccak256(_input : [u8; N], _message_size: u32) -> [u8; 32] {}\n\n// mimc-p/p implementation\n// constants are (publicly generated) random numbers, for instance using keccak as a ROM.\n// You must use constants generated for the native field\n// Rounds number should be ~ log(p)/log(exp)\n// For 254 bit primes, exponent 7 and 91 rounds seems to be recommended\nfn mimc(x: Field, k: Field, constants: [Field; N], exp : Field) -> Field {\n //round 0\n let mut t = x + k;\n let mut h = t.pow_32(exp);\n //next rounds\n for i in 1 .. constants.len() {\n t = h + k + constants[i];\n h = t.pow_32(exp);\n };\n h + k\n}\n\nglobal MIMC_BN254_ROUNDS = 91;\n\n//mimc implementation with hardcoded parameters for BN254 curve.\nfn mimc_bn254(array: [Field; N]) -> Field {\n //mimc parameters\n let exponent = 7;\n //generated from seed \"mimc\" using keccak256 \n let constants: [Field; MIMC_BN254_ROUNDS] = [\n 0, \n 20888961410941983456478427210666206549300505294776164667214940546594746570981,\n 15265126113435022738560151911929040668591755459209400716467504685752745317193,\n 8334177627492981984476504167502758309043212251641796197711684499645635709656,\n 1374324219480165500871639364801692115397519265181803854177629327624133579404,\n 11442588683664344394633565859260176446561886575962616332903193988751292992472,\n 2558901189096558760448896669327086721003508630712968559048179091037845349145,\n 11189978595292752354820141775598510151189959177917284797737745690127318076389,\n 3262966573163560839685415914157855077211340576201936620532175028036746741754,\n 17029914891543225301403832095880481731551830725367286980611178737703889171730,\n 4614037031668406927330683909387957156531244689520944789503628527855167665518,\n 19647356996769918391113967168615123299113119185942498194367262335168397100658,\n 5040699236106090655289931820723926657076483236860546282406111821875672148900,\n 2632385916954580941368956176626336146806721642583847728103570779270161510514,\n 17691411851977575435597871505860208507285462834710151833948561098560743654671,\n 11482807709115676646560379017491661435505951727793345550942389701970904563183,\n 8360838254132998143349158726141014535383109403565779450210746881879715734773,\n 12663821244032248511491386323242575231591777785787269938928497649288048289525,\n 3067001377342968891237590775929219083706800062321980129409398033259904188058,\n 8536471869378957766675292398190944925664113548202769136103887479787957959589,\n 19825444354178182240559170937204690272111734703605805530888940813160705385792,\n 16703465144013840124940690347975638755097486902749048533167980887413919317592,\n 13061236261277650370863439564453267964462486225679643020432589226741411380501,\n 10864774797625152707517901967943775867717907803542223029967000416969007792571,\n 10035653564014594269791753415727486340557376923045841607746250017541686319774,\n 3446968588058668564420958894889124905706353937375068998436129414772610003289,\n 4653317306466493184743870159523234588955994456998076243468148492375236846006,\n 8486711143589723036499933521576871883500223198263343024003617825616410932026,\n 250710584458582618659378487568129931785810765264752039738223488321597070280,\n 2104159799604932521291371026105311735948154964200596636974609406977292675173,\n 16313562605837709339799839901240652934758303521543693857533755376563489378839,\n 6032365105133504724925793806318578936233045029919447519826248813478479197288,\n 14025118133847866722315446277964222215118620050302054655768867040006542798474,\n 7400123822125662712777833064081316757896757785777291653271747396958201309118,\n 1744432620323851751204287974553233986555641872755053103823939564833813704825,\n 8316378125659383262515151597439205374263247719876250938893842106722210729522,\n 6739722627047123650704294650168547689199576889424317598327664349670094847386,\n 21211457866117465531949733809706514799713333930924902519246949506964470524162,\n 13718112532745211817410303291774369209520657938741992779396229864894885156527,\n 5264534817993325015357427094323255342713527811596856940387954546330728068658,\n 18884137497114307927425084003812022333609937761793387700010402412840002189451,\n 5148596049900083984813839872929010525572543381981952060869301611018636120248,\n 19799686398774806587970184652860783461860993790013219899147141137827718662674,\n 19240878651604412704364448729659032944342952609050243268894572835672205984837,\n 10546185249390392695582524554167530669949955276893453512788278945742408153192,\n 5507959600969845538113649209272736011390582494851145043668969080335346810411,\n 18177751737739153338153217698774510185696788019377850245260475034576050820091,\n 19603444733183990109492724100282114612026332366576932662794133334264283907557,\n 10548274686824425401349248282213580046351514091431715597441736281987273193140,\n 1823201861560942974198127384034483127920205835821334101215923769688644479957,\n 11867589662193422187545516240823411225342068709600734253659804646934346124945,\n 18718569356736340558616379408444812528964066420519677106145092918482774343613,\n 10530777752259630125564678480897857853807637120039176813174150229243735996839,\n 20486583726592018813337145844457018474256372770211860618687961310422228379031,\n 12690713110714036569415168795200156516217175005650145422920562694422306200486,\n 17386427286863519095301372413760745749282643730629659997153085139065756667205,\n 2216432659854733047132347621569505613620980842043977268828076165669557467682,\n 6309765381643925252238633914530877025934201680691496500372265330505506717193,\n 20806323192073945401862788605803131761175139076694468214027227878952047793390,\n 4037040458505567977365391535756875199663510397600316887746139396052445718861,\n 19948974083684238245321361840704327952464170097132407924861169241740046562673,\n 845322671528508199439318170916419179535949348988022948153107378280175750024,\n 16222384601744433420585982239113457177459602187868460608565289920306145389382,\n 10232118865851112229330353999139005145127746617219324244541194256766741433339,\n 6699067738555349409504843460654299019000594109597429103342076743347235369120,\n 6220784880752427143725783746407285094967584864656399181815603544365010379208,\n 6129250029437675212264306655559561251995722990149771051304736001195288083309,\n 10773245783118750721454994239248013870822765715268323522295722350908043393604,\n 4490242021765793917495398271905043433053432245571325177153467194570741607167,\n 19596995117319480189066041930051006586888908165330319666010398892494684778526,\n 837850695495734270707668553360118467905109360511302468085569220634750561083,\n 11803922811376367215191737026157445294481406304781326649717082177394185903907,\n 10201298324909697255105265958780781450978049256931478989759448189112393506592,\n 13564695482314888817576351063608519127702411536552857463682060761575100923924,\n 9262808208636973454201420823766139682381973240743541030659775288508921362724,\n 173271062536305557219323722062711383294158572562695717740068656098441040230,\n 18120430890549410286417591505529104700901943324772175772035648111937818237369,\n 20484495168135072493552514219686101965206843697794133766912991150184337935627,\n 19155651295705203459475805213866664350848604323501251939850063308319753686505,\n 11971299749478202793661982361798418342615500543489781306376058267926437157297,\n 18285310723116790056148596536349375622245669010373674803854111592441823052978,\n 7069216248902547653615508023941692395371990416048967468982099270925308100727,\n 6465151453746412132599596984628739550147379072443683076388208843341824127379,\n 16143532858389170960690347742477978826830511669766530042104134302796355145785,\n 19362583304414853660976404410208489566967618125972377176980367224623492419647,\n 1702213613534733786921602839210290505213503664731919006932367875629005980493,\n 10781825404476535814285389902565833897646945212027592373510689209734812292327,\n 4212716923652881254737947578600828255798948993302968210248673545442808456151,\n 7594017890037021425366623750593200398174488805473151513558919864633711506220,\n 18979889247746272055963929241596362599320706910852082477600815822482192194401,\n 13602139229813231349386885113156901793661719180900395818909719758150455500533,\n ];\n\n let mut r = 0;\n for elem in array {\n let h = mimc(elem, r, constants, exponent);\n r = r + elem + h;\n }\n r\n}\n", @@ -178,47 +178,47 @@ }, "31": { "source": "use crate::constants_gen::{\n RETURN_VALUES_LENGTH,\n MAX_READ_REQUESTS_PER_CALL,\n MAX_NEW_COMMITMENTS_PER_CALL,\n MAX_NEW_NULLIFIERS_PER_CALL,\n MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL,\n MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,\n MAX_NEW_L2_TO_L1_MSGS_PER_CALL,\n NUM_FIELDS_PER_SHA256,\n MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,\n MAX_PUBLIC_DATA_READS_PER_CALL,\n GENERATOR_INDEX__FUNCTION_ARGS,\n HISTORIC_BLOCK_DATA_LENGTH,\n CONTRACT_DEPLOYMENT_DATA_LENGTH,\n CALL_CONTEXT_LENGTH,\n PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH,\n PRIVATE_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH,\n CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH,\n CONTRACT_STORAGE_READ_LENGTH,\n PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH,\n PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH,\n GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS,\n GENERATOR_INDEX__FUNCTION_DATA,\n GENERATOR_INDEX__PUBLIC_DATA_READ,\n GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST,\n GENERATOR_INDEX__CALL_CONTEXT,\n GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS,\n GENERATOR_INDEX__CONTRACT_DEPLOYMENT_DATA,\n};\n\nuse crate::oracle::debug_log;\nuse crate::types::vec::BoundedVec;\nuse crate::types::point::Point;\n\nstruct PrivateGlobalVariables {\n chain_id: Field,\n version: Field,\n}\n\nimpl PrivateGlobalVariables {\n fn serialize(self) -> [Field; 2] {\n [self.chain_id, self.version]\n }\n}\n\nstruct PublicGlobalVariables {\n chain_id: Field,\n version: Field,\n block_number: Field,\n timestamp: Field,\n}\n\nimpl PublicGlobalVariables {\n fn serialize(self) -> [Field; 4] {\n [self.chain_id, self.version, self.block_number, self.timestamp]\n }\n}\n\nstruct ContractDeploymentData {\n deployer_public_key: Point,\n constructor_vk_hash : Field,\n function_tree_root : Field,\n contract_address_salt : Field,\n portal_contract_address : Field,\n}\n\nimpl ContractDeploymentData {\n fn serialize(self) -> [Field; CONTRACT_DEPLOYMENT_DATA_LENGTH] {\n [\n self.deployer_public_key.x,\n self.deployer_public_key.y,\n self.constructor_vk_hash,\n self.function_tree_root,\n self.contract_address_salt,\n self.portal_contract_address,\n ]\n }\n\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__CONTRACT_DEPLOYMENT_DATA)[0]\n }\n}\n\n// PrivateContextInputs are expected to be provided to each private function\nstruct PrivateContextInputs {\n call_context : CallContext,\n block_data: HistoricBlockData,\n\n contract_deployment_data: ContractDeploymentData,\n\n private_global_variables: PrivateGlobalVariables,\n}\n\n// PublicContextInputs are expected to be provided to each public function\nstruct PublicContextInputs {\n call_context: CallContext,\n block_data: HistoricBlockData,\n\n public_global_variables: PublicGlobalVariables,\n}\n\nstruct CallContext {\n msg_sender : Field,\n storage_contract_address : Field,\n portal_contract_address : Field,\n\n is_delegate_call : bool,\n is_static_call : bool,\n is_contract_deployment: bool,\n}\n\nimpl CallContext {\n fn serialize(self) -> [Field; CALL_CONTEXT_LENGTH] {\n [\n self.msg_sender,\n self.storage_contract_address,\n self.portal_contract_address,\n self.is_delegate_call as Field,\n self.is_static_call as Field,\n self.is_contract_deployment as Field,\n ]\n }\n\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__CALL_CONTEXT)[0]\n }\n}\n\nstruct HistoricBlockData {\n private_data_tree_root : Field,\n nullifier_tree_root : Field,\n contract_tree_root : Field,\n l1_to_l2_messages_tree_root : Field,\n blocks_tree_root: Field,\n public_data_tree_root: Field,\n global_variables_hash: Field,\n}\n\nimpl HistoricBlockData {\n // NOTE: this order must match the order in `private_circuit_public_inputs.hpp`\n fn serialize(self) -> [Field; HISTORIC_BLOCK_DATA_LENGTH] {\n [\n self.private_data_tree_root,\n self.nullifier_tree_root,\n self.contract_tree_root,\n self.l1_to_l2_messages_tree_root,\n self.blocks_tree_root,\n self.public_data_tree_root,\n self.global_variables_hash,\n ]\n }\n\n fn empty() -> Self {\n Self { private_data_tree_root: 0, nullifier_tree_root: 0, contract_tree_root: 0, l1_to_l2_messages_tree_root: 0, blocks_tree_root: 0, public_data_tree_root: 0, global_variables_hash: 0 }\n }\n}\n\nstruct FunctionData {\n function_selector: Field,\n is_internal: bool,\n is_private: bool,\n is_constructor: bool,\n}\n\nimpl FunctionData {\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator([\n self.function_selector,\n self.is_internal as Field,\n self.is_private as Field,\n self.is_constructor as Field,\n ], GENERATOR_INDEX__FUNCTION_DATA)[0]\n }\n}\n\nstruct PrivateCircuitPublicInputs {\n call_context: CallContext,\n args_hash: Field,\n return_values: [Field; RETURN_VALUES_LENGTH],\n read_requests: [Field; crate::abi::MAX_READ_REQUESTS_PER_CALL],\n new_commitments: [Field; MAX_NEW_COMMITMENTS_PER_CALL],\n new_nullifiers: [Field; MAX_NEW_NULLIFIERS_PER_CALL],\n nullified_commitments: [Field; MAX_NEW_NULLIFIERS_PER_CALL],\n private_call_stack: [Field; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL],\n public_call_stack: [Field; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL],\n new_l2_to_l1_msgs: [Field; MAX_NEW_L2_TO_L1_MSGS_PER_CALL],\n // Explore introducing a new type like uint256 (similar to Point), so it's more explicit that\n // we're talking about a single number backed by two field elements.\n encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256],\n unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256],\n encrypted_log_preimages_length: Field,\n unencrypted_log_preimages_length: Field,\n block_data: HistoricBlockData,\n contract_deployment_data: ContractDeploymentData,\n chain_id: Field,\n version: Field,\n}\n\nimpl PrivateCircuitPublicInputs {\n fn hash(self) -> Field {\n let mut fields: BoundedVec = BoundedVec::new(0); \n fields.push(self.call_context.hash());\n fields.push(self.args_hash);\n fields.push_array(self.return_values);\n fields.push_array(self.read_requests);\n fields.push_array(self.new_commitments);\n fields.push_array(self.new_nullifiers);\n fields.push_array(self.nullified_commitments);\n fields.push_array(self.private_call_stack);\n fields.push_array(self.public_call_stack);\n fields.push_array(self.new_l2_to_l1_msgs);\n fields.push_array(self.encrypted_logs_hash);\n fields.push_array(self.unencrypted_logs_hash);\n fields.push(self.encrypted_log_preimages_length);\n fields.push(self.unencrypted_log_preimages_length);\n fields.push_array(self.block_data.serialize());\n fields.push(self.contract_deployment_data.hash());\n fields.push(self.chain_id);\n fields.push(self.version);\n\n dep::std::hash::pedersen_with_separator(fields.storage, GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS)[0]\n }\n\n fn serialize(self) -> [Field; PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH] {\n let mut fields: BoundedVec = BoundedVec::new(0); \n fields.push_array(self.call_context.serialize());\n fields.push(self.args_hash);\n fields.push_array(self.return_values);\n fields.push_array(self.read_requests);\n fields.push_array(self.new_commitments);\n fields.push_array(self.new_nullifiers);\n fields.push_array(self.private_call_stack);\n fields.push_array(self.public_call_stack);\n fields.push_array(self.new_l2_to_l1_msgs);\n fields.push_array(self.encrypted_logs_hash);\n fields.push_array(self.unencrypted_logs_hash);\n fields.push(self.encrypted_log_preimages_length);\n fields.push(self.unencrypted_log_preimages_length);\n fields.push_array(self.block_data.serialize());\n fields.push_array(self.contract_deployment_data.serialize());\n fields.push(self.chain_id);\n fields.push(self.version);\n fields.storage\n }\n}\n\nstruct ContractStorageRead {\n storage_slot: Field,\n value: Field,\n}\n\nimpl ContractStorageRead {\n fn serialize(self) -> [Field; CONTRACT_STORAGE_READ_LENGTH] {\n [self.storage_slot, self.value]\n }\n\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__PUBLIC_DATA_READ)[0]\n }\n\n fn empty() -> Self {\n Self { storage_slot: 0, value: 0 }\n }\n}\n\nstruct ContractStorageUpdateRequest {\n storage_slot: Field,\n old_value: Field,\n new_value: Field,\n}\n\nimpl ContractStorageUpdateRequest {\n fn serialize(self) -> [Field; CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH] {\n [self.storage_slot, self.old_value, self.new_value]\n }\n\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST)[0]\n }\n\n fn empty() -> Self {\n Self { storage_slot: 0, old_value: 0, new_value: 0 }\n }\n}\n\n\nstruct PublicCircuitPublicInputs {\n call_context: CallContext,\n args_hash: Field,\n return_values: [Field; RETURN_VALUES_LENGTH],\n contract_storage_update_requests: [ContractStorageUpdateRequest; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL],\n contract_storage_read: [ContractStorageRead; MAX_PUBLIC_DATA_READS_PER_CALL],\n public_call_stack: [Field; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL],\n new_commitments: [Field; MAX_NEW_COMMITMENTS_PER_CALL],\n new_nullifiers: [Field; crate::abi::MAX_NEW_NULLIFIERS_PER_CALL],\n new_l2_to_l1_msgs: [Field; crate::abi::MAX_NEW_L2_TO_L1_MSGS_PER_CALL],\n unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256],\n unencrypted_log_preimages_length: Field,\n block_data: HistoricBlockData,\n prover_address: Field,\n\n // TODO: include globals in here and check them elsewhere\n // https://github.com/AztecProtocol/aztec-packages/issues/1567\n}\n\nimpl PublicCircuitPublicInputs {\n \n fn hash(self) -> Field {\n let mut inputs: BoundedVec = BoundedVec::new(0);\n inputs.push(self.call_context.hash());\n inputs.push(self.args_hash);\n inputs.push_array(self.return_values);\n for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL {\n inputs.push(self.contract_storage_update_requests[i].hash());\n }\n for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL {\n inputs.push(self.contract_storage_read[i].hash());\n }\n inputs.push_array(self.public_call_stack);\n inputs.push_array(self.new_commitments);\n inputs.push_array(self.new_nullifiers);\n inputs.push_array(self.new_l2_to_l1_msgs);\n\n // We do not include block_data since it's not in the cpp hash\n\n inputs.push_array(self.unencrypted_logs_hash);\n inputs.push(self.unencrypted_log_preimages_length);\n inputs.push_array(self.block_data.serialize()); // see https://github.com/AztecProtocol/aztec-packages/issues/1473\n inputs.push(self.prover_address);\n\n dep::std::hash::pedersen_with_separator(inputs.storage, GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS)[0]\n }\n\n fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] {\n let mut fields: BoundedVec = BoundedVec::new(0); \n fields.push_array(self.call_context.serialize()); \n fields.push(self.args_hash);\n fields.push_array(self.return_values);\n for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL {\n fields.push_array(self.contract_storage_update_requests[i].serialize());\n }\n for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL {\n fields.push_array(self.contract_storage_read[i].serialize());\n }\n fields.push_array(self.public_call_stack);\n fields.push_array(self.new_commitments);\n fields.push_array(self.new_nullifiers);\n fields.push_array(self.new_l2_to_l1_msgs);\n fields.push_array(self.unencrypted_logs_hash);\n fields.push(self.unencrypted_log_preimages_length);\n fields.push_array(self.block_data.serialize());\n fields.push(self.prover_address);\n fields.storage\n }\n}\n\nglobal ARGS_HASH_CHUNK_LENGTH: u32 = 32;\nglobal ARGS_HASH_CHUNK_COUNT: u32 = 16;\n\nfn hash_args(args: [Field; N]) -> Field {\n if args.len() == 0 {\n 0\n } else {\n let mut chunks_hashes = [0; ARGS_HASH_CHUNK_COUNT];\n for i in 0..ARGS_HASH_CHUNK_COUNT {\n let mut chunk_hash = 0;\n let start_chunk_index = i * ARGS_HASH_CHUNK_LENGTH;\n if start_chunk_index < (args.len() as u32) {\n let mut chunk_args = [0; ARGS_HASH_CHUNK_LENGTH];\n for j in 0..ARGS_HASH_CHUNK_LENGTH {\n let item_index = i * ARGS_HASH_CHUNK_LENGTH + j;\n if item_index < (args.len() as u32) {\n chunk_args[j] = args[item_index];\n }\n }\n chunk_hash = dep::std::hash::pedersen_with_separator(chunk_args, GENERATOR_INDEX__FUNCTION_ARGS)[0];\n }\n chunks_hashes[i] = chunk_hash;\n }\n dep::std::hash::pedersen_with_separator(chunks_hashes, GENERATOR_INDEX__FUNCTION_ARGS)[0]\n }\n}\n", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/abi" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/abi" }, "32": { "source": "use crate::constants_gen::{\n EMPTY_NULLIFIED_COMMITMENT,\n MAX_NEW_COMMITMENTS_PER_CALL,\n MAX_NEW_L2_TO_L1_MSGS_PER_CALL,\n MAX_NEW_NULLIFIERS_PER_CALL,\n MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL,\n MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,\n MAX_PUBLIC_DATA_READS_PER_CALL,\n MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,\n MAX_READ_REQUESTS_PER_CALL,\n NUM_FIELDS_PER_SHA256,\n RETURN_VALUES_LENGTH,\n};\n\nuse crate::abi;\n\nuse crate::abi::{\n hash_args,\n CallContext,\n ContractDeploymentData,\n HistoricBlockData,\n FunctionData,\n PrivateCircuitPublicInputs,\n PublicCircuitPublicInputs,\n};\n\n// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n// use dep::std::collections::vec::Vec;\n\n// l1 to l2 messaging\nuse crate::messaging::process_l1_to_l2_message;\nuse crate::private_call_stack_item::PrivateCallStackItem;\nuse crate::public_call_stack_item::PublicCallStackItem;\n\nuse crate::types::{\n vec::BoundedVec,\n point::Point,\n};\n\nuse crate::utils::arr_copy_slice;\n\nuse crate::oracle::{\n arguments,\n call_private_function::call_private_function_internal,\n public_call::call_public_function_internal,\n enqueue_public_function_call::enqueue_public_function_call_internal,\n context::get_portal_address,\n};\n\n\n// When finished, one can call .finish() to convert back to the abi\nstruct PrivateContext {\n inputs: abi::PrivateContextInputs,\n\n args_hash : Field,\n return_values : BoundedVec,\n\n read_requests: BoundedVec,\n\n new_commitments: BoundedVec,\n new_nullifiers: BoundedVec,\n nullified_commitments: BoundedVec,\n\n private_call_stack : BoundedVec,\n public_call_stack : BoundedVec,\n new_l2_to_l1_msgs : BoundedVec,\n\n block_data: HistoricBlockData,\n\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n // encrypted_logs_preimages: Vec,\n // unencrypted_logs_preimages: Vec,\n}\n\nimpl PrivateContext {\n fn new(inputs: abi::PrivateContextInputs, args_hash: Field) -> PrivateContext {\n PrivateContext {\n inputs: inputs,\n\n args_hash: args_hash,\n return_values: BoundedVec::new(0),\n\n read_requests: BoundedVec::new(0),\n\n new_commitments: BoundedVec::new(0),\n new_nullifiers: BoundedVec::new(0),\n nullified_commitments: BoundedVec::new(0),\n\n block_data: inputs.block_data,\n\n private_call_stack: BoundedVec::new(0),\n public_call_stack: BoundedVec::new(0),\n new_l2_to_l1_msgs: BoundedVec::new(0),\n\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n // encrypted_logs_preimages: Vec::new(),\n // unencrypted_logs_preimages: Vec::new(),\n }\n }\n\n fn msg_sender(self) -> Field {\n self.inputs.call_context.msg_sender\n }\n\n fn this_address(self) -> Field {\n self.inputs.call_context.storage_contract_address\n }\n\n fn this_portal_address(self) -> Field {\n self.inputs.call_context.portal_contract_address\n }\n\n fn chain_id(self) -> Field {\n self.inputs.private_global_variables.chain_id\n }\n\n fn version(self) -> Field {\n self.inputs.private_global_variables.version\n }\n\n fn finish(self) -> abi::PrivateCircuitPublicInputs {\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n let encrypted_logs_hash = [0; NUM_FIELDS_PER_SHA256];\n let unencrypted_logs_hash = [0; NUM_FIELDS_PER_SHA256];\n let encrypted_log_preimages_length = 0;\n let unencrypted_log_preimages_length = 0;\n\n let priv_circuit_pub_inputs = abi::PrivateCircuitPublicInputs {\n call_context: self.inputs.call_context,\n args_hash: self.args_hash,\n return_values: self.return_values.storage,\n read_requests: self.read_requests.storage,\n new_commitments: self.new_commitments.storage,\n new_nullifiers: self.new_nullifiers.storage,\n nullified_commitments: self.nullified_commitments.storage,\n private_call_stack: self.private_call_stack.storage,\n public_call_stack: self.public_call_stack.storage,\n new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage,\n encrypted_logs_hash: encrypted_logs_hash,\n unencrypted_logs_hash: unencrypted_logs_hash,\n encrypted_log_preimages_length: encrypted_log_preimages_length,\n unencrypted_log_preimages_length: unencrypted_log_preimages_length,\n block_data: self.block_data,\n contract_deployment_data: self.inputs.contract_deployment_data,\n chain_id: self.inputs.private_global_variables.chain_id,\n version: self.inputs.private_global_variables.version,\n };\n priv_circuit_pub_inputs\n }\n\n fn push_read_request(&mut self, read_request: Field) {\n self.read_requests.push(read_request);\n }\n\n fn push_new_note_hash(&mut self, note_hash: Field) {\n self.new_commitments.push(note_hash);\n }\n\n fn push_new_nullifier(&mut self, nullifier: Field, nullified_commitment: Field) {\n self.new_nullifiers.push(nullifier);\n self.nullified_commitments.push(nullified_commitment);\n }\n\n fn message_portal(&mut self, content: Field) {\n self.new_l2_to_l1_msgs.push(content);\n }\n\n // PrivateContextInputs must be temporarily passed in to prevent too many unknowns\n // Note this returns self to get around an issue where mutable structs do not maintain mutations unless reassigned\n fn consume_l1_to_l2_message(&mut self, inputs: abi::PrivateContextInputs, msg_key: Field, content: Field, secret: Field) {\n let nullifier = process_l1_to_l2_message(inputs.block_data.l1_to_l2_messages_tree_root, inputs.call_context.storage_contract_address, msg_key, content, secret);\n\n // Push nullifier (and the \"commitment\" corresponding to this can be \"empty\")\n self.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT)\n }\n\n fn accumulate_encrypted_logs(&mut self, log: [Field; N]) {\n let _void1 = self.inputs;\n let _void2 = log;\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n }\n\n fn accumulate_unencrypted_logs(&mut self, log: T) {\n let _void1 = self.inputs;\n let _void2 = log;\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n }\n\n fn call_private_function(\n &mut self,\n contract_address: Field, \n function_selector: Field, \n args: [Field; ARGS_COUNT]\n ) -> [Field; RETURN_VALUES_LENGTH] {\n let args_hash = hash_args(args);\n assert(args_hash == arguments::pack_arguments(args));\n self.call_private_function_with_packed_args(contract_address, function_selector, args_hash)\n }\n\n fn call_private_function_no_args(\n &mut self,\n contract_address: Field, \n function_selector: Field, \n ) -> [Field; RETURN_VALUES_LENGTH] {\n self.call_private_function_with_packed_args(contract_address, function_selector, 0)\n }\n\n fn call_private_function_with_packed_args(\n &mut self,\n contract_address: Field,\n function_selector: Field,\n args_hash: Field\n ) -> [Field; RETURN_VALUES_LENGTH] {\n let fields = call_private_function_internal(\n contract_address, \n function_selector, \n args_hash\n );\n let item = PrivateCallStackItem {\n contract_address: fields[0],\n function_data: FunctionData {\n function_selector: fields[1],\n is_internal: fields[2] as bool,\n is_private: fields[3] as bool,\n is_constructor: fields[4] as bool,\n },\n public_inputs: PrivateCircuitPublicInputs {\n call_context: CallContext {\n msg_sender : fields[5],\n storage_contract_address : fields[6],\n portal_contract_address : fields[7],\n \n is_delegate_call : fields[8] as bool,\n is_static_call : fields[9] as bool,\n is_contract_deployment: fields[10] as bool,\n },\n // TODO handle the offsets as a variable incremented during extraction?\n args_hash: fields[11],\n return_values: arr_copy_slice(fields, [0; RETURN_VALUES_LENGTH], 12),\n read_requests: arr_copy_slice(fields, [0; MAX_READ_REQUESTS_PER_CALL], 16),\n new_commitments: arr_copy_slice(fields, [0; MAX_NEW_COMMITMENTS_PER_CALL], 20),\n new_nullifiers: arr_copy_slice(fields, [0; MAX_NEW_NULLIFIERS_PER_CALL], 24),\n nullified_commitments: arr_copy_slice(fields, [0; MAX_NEW_NULLIFIERS_PER_CALL], 28),\n private_call_stack: arr_copy_slice(fields, [0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL], 32),\n public_call_stack: arr_copy_slice(fields, [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], 36),\n new_l2_to_l1_msgs: arr_copy_slice(fields, [0; MAX_NEW_L2_TO_L1_MSGS_PER_CALL], 40),\n encrypted_logs_hash: arr_copy_slice(fields, [0; NUM_FIELDS_PER_SHA256], 42),\n unencrypted_logs_hash: arr_copy_slice(fields, [0; NUM_FIELDS_PER_SHA256], 44),\n encrypted_log_preimages_length: fields[46],\n unencrypted_log_preimages_length: fields[47],\n block_data: HistoricBlockData {\n // Must match order in `private_circuit_public_inputs.hpp`\n private_data_tree_root : fields[48],\n nullifier_tree_root : fields[49],\n contract_tree_root : fields[50],\n l1_to_l2_messages_tree_root : fields[51],\n blocks_tree_root : fields[52],\n public_data_tree_root: fields[53],\n global_variables_hash: fields[54],\n },\n contract_deployment_data: ContractDeploymentData {\n deployer_public_key: Point::new(fields[55], fields[56]),\n constructor_vk_hash : fields[57],\n function_tree_root : fields[58],\n contract_address_salt : fields[59],\n portal_contract_address : fields[60],\n },\n chain_id: fields[61],\n version: fields[62],\n },\n is_execution_request: fields[63] as bool,\n };\n assert(contract_address == item.contract_address);\n assert(function_selector == item.function_data.function_selector);\n\n assert(args_hash == item.public_inputs.args_hash);\n\n assert(item.is_execution_request == false);\n\n // Assert that the call context of the enqueued call generated by the oracle matches our request.\n // We are issuing a regular call which is not delegate, static, or deployment. We also constrain\n // the msg_sender in the nested call to be equal to our address, and the execution context address\n // for the nested call to be equal to the address we actually called.\n assert(item.public_inputs.call_context.is_delegate_call == false);\n assert(item.public_inputs.call_context.is_static_call == false);\n assert(item.public_inputs.call_context.is_contract_deployment == false);\n assert(item.public_inputs.call_context.msg_sender == self.inputs.call_context.storage_contract_address);\n assert(item.public_inputs.call_context.storage_contract_address == contract_address);\n\n self.private_call_stack.push(item.hash());\n\n item.public_inputs.return_values\n }\n\n fn call_public_function(\n &mut self,\n contract_address: Field, \n function_selector: Field, \n args: [Field; ARGS_COUNT]\n ) {\n let args_hash = hash_args(args);\n assert(args_hash == arguments::pack_arguments(args));\n self.call_public_function_with_packed_args(contract_address, function_selector, args_hash)\n }\n\n fn call_public_function_no_args(\n &mut self,\n contract_address: Field, \n function_selector: Field,\n ) {\n self.call_public_function_with_packed_args(contract_address, function_selector, 0)\n }\n\n fn call_public_function_with_packed_args(\n &mut self,\n contract_address: Field,\n function_selector: Field,\n args_hash: Field\n ) {\n let fields = enqueue_public_function_call_internal(\n contract_address, \n function_selector, \n args_hash\n );\n let item = PublicCallStackItem {\n contract_address: fields[0],\n function_data: FunctionData {\n function_selector: fields[1],\n is_internal: fields[2] as bool,\n is_private: fields[3] as bool,\n is_constructor: fields[4] as bool,\n },\n public_inputs: PublicCircuitPublicInputs {\n call_context: CallContext {\n msg_sender : fields[5],\n storage_contract_address : fields[6],\n portal_contract_address : fields[7],\n \n is_delegate_call : fields[8] as bool,\n is_static_call : fields[9] as bool,\n is_contract_deployment: fields[10] as bool,\n },\n args_hash: fields[11],\n return_values: [0; RETURN_VALUES_LENGTH],\n contract_storage_update_requests: [ContractStorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL],\n contract_storage_read: [ContractStorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL],\n public_call_stack: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL],\n new_commitments: [0; MAX_NEW_COMMITMENTS_PER_CALL],\n new_nullifiers: [0; MAX_NEW_NULLIFIERS_PER_CALL],\n new_l2_to_l1_msgs:[0; MAX_NEW_L2_TO_L1_MSGS_PER_CALL],\n unencrypted_logs_hash:[0; NUM_FIELDS_PER_SHA256],\n unencrypted_log_preimages_length: 0,\n block_data: HistoricBlockData::empty(),\n prover_address: 0,\n },\n is_execution_request: true,\n };\n\n assert(contract_address == item.contract_address);\n assert(function_selector == item.function_data.function_selector);\n \n assert(args_hash == item.public_inputs.args_hash);\n\n // Assert that the call context of the enqueued call generated by the oracle matches our request.\n // We are issuing a regular call which is not delegate, static, or deployment. We also constrain\n // the msg_sender in the nested call to be equal to our address, and the execution context address\n // for the nested call to be equal to the address we actually called.\n assert(item.public_inputs.call_context.is_delegate_call == false);\n assert(item.public_inputs.call_context.is_static_call == false);\n assert(item.public_inputs.call_context.is_contract_deployment == false);\n assert(item.public_inputs.call_context.msg_sender == self.inputs.call_context.storage_contract_address);\n assert(item.public_inputs.call_context.storage_contract_address == contract_address);\n\n self.public_call_stack.push(item.hash());\n }\n}\n\nuse crate::abi::{\n ContractStorageRead,\n ContractStorageUpdateRequest\n};\n\nstruct PublicContext {\n inputs: abi::PublicContextInputs,\n\n args_hash : Field,\n return_values : BoundedVec,\n\n contract_storage_update_requests: BoundedVec,\n contract_storage_read: BoundedVec,\n public_call_stack: BoundedVec,\n\n new_commitments: BoundedVec,\n new_nullifiers: BoundedVec,\n\n new_l2_to_l1_msgs: BoundedVec,\n\n unencrypted_logs_hash: BoundedVec,\n unencrypted_logs_preimages_length: Field,\n\n block_data: HistoricBlockData,\n prover_address: Field,\n}\n\nimpl PublicContext {\n fn new(inputs: abi::PublicContextInputs, args_hash: Field) -> PublicContext {\n let empty_storage_read = ContractStorageRead::empty();\n let empty_storage_update = ContractStorageUpdateRequest::empty();\n PublicContext {\n inputs: inputs,\n\n args_hash: args_hash,\n return_values: BoundedVec::new(0),\n\n contract_storage_update_requests: BoundedVec::new(empty_storage_update),\n contract_storage_read: BoundedVec::new(empty_storage_read),\n public_call_stack: BoundedVec::new(0),\n\n new_commitments: BoundedVec::new(0),\n new_nullifiers: BoundedVec::new(0),\n\n new_l2_to_l1_msgs: BoundedVec::new(0),\n\n \n unencrypted_logs_hash: BoundedVec::new(0),\n unencrypted_logs_preimages_length: 0,\n\n block_data: inputs.block_data,\n prover_address: 0,\n\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n // encrypted_logs_preimages: Vec::new(),\n // unencrypted_logs_preimages: Vec::new(),\n }\n }\n\n fn msg_sender(self) -> Field {\n self.inputs.call_context.msg_sender\n }\n\n fn this_address(self) -> Field {\n self.inputs.call_context.storage_contract_address\n }\n\n fn this_portal_address(self) -> Field {\n self.inputs.call_context.portal_contract_address\n }\n\n fn chain_id(self) -> Field {\n self.inputs.public_global_variables.chain_id\n }\n\n fn version(self) -> Field {\n self.inputs.public_global_variables.version\n }\n\n fn block_number(self) -> Field {\n self.inputs.public_global_variables.block_number\n }\n\n fn timestamp(self) -> Field {\n self.inputs.public_global_variables.timestamp\n }\n\n fn finish(self) -> abi::PublicCircuitPublicInputs {\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n let unencrypted_logs_hash = [0; NUM_FIELDS_PER_SHA256];\n let unencrypted_log_preimages_length = 0;\n\n\n // Compute the public call stack hashes\n let pub_circuit_pub_inputs = abi::PublicCircuitPublicInputs {\n call_context: self.inputs.call_context, // Done\n args_hash: self.args_hash, // Done\n contract_storage_update_requests: self.contract_storage_update_requests.storage,\n contract_storage_read: self.contract_storage_read.storage,\n return_values: self.return_values.storage,\n new_commitments: self.new_commitments.storage,\n new_nullifiers: self.new_nullifiers.storage,\n public_call_stack: self.public_call_stack.storage,\n new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage,\n unencrypted_logs_hash: unencrypted_logs_hash,\n unencrypted_log_preimages_length: unencrypted_log_preimages_length,\n block_data: self.inputs.block_data,\n prover_address: self.prover_address,\n };\n pub_circuit_pub_inputs\n }\n\n fn push_new_note_hash(&mut self, note_hash: Field) {\n self.new_commitments.push(note_hash);\n }\n\n fn push_new_nullifier(&mut self, nullifier: Field, _nullified_commitment: Field) {\n self.new_nullifiers.push(nullifier);\n }\n\n fn message_portal(&mut self, content: Field) {\n self.new_l2_to_l1_msgs.push(content);\n }\n\n // PrivateContextInputs must be temporarily passed in to prevent too many unknowns\n // Note this returns self to get around an issue where mutable structs do not maintain mutations unless reassigned\n fn consume_l1_to_l2_message(&mut self, msg_key: Field, content: Field, secret: Field) {\n let this = (*self).this_address();\n let nullifier = process_l1_to_l2_message(self.block_data.l1_to_l2_messages_tree_root, this, msg_key, content, secret);\n\n // Push nullifier (and the \"commitment\" corresponding to this can be \"empty\")\n self.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT)\n }\n\n fn accumulate_encrypted_logs(&mut self, log: [Field; N]) {\n let _void1 = self;\n let _void2 = log;\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n }\n\n fn accumulate_unencrypted_logs(&mut self, log: T) {\n let _void1 = self;\n let _void2 = log;\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n }\n\n fn call_public_function(\n _self: Self,\n contract_address: Field, \n function_selector: Field,\n args: [Field; ARGS_COUNT],\n ) -> [Field; RETURN_VALUES_LENGTH] {\n let args_hash = abi::hash_args(args);\n assert(args_hash == arguments::pack_arguments(args));\n call_public_function_internal(\n contract_address, \n function_selector, \n args_hash,\n )\n }\n\n fn call_public_function_no_args(\n _self: Self,\n contract_address: Field, \n function_selector: Field,\n ) -> [Field; RETURN_VALUES_LENGTH] {\n call_public_function_internal(\n contract_address, \n function_selector, \n 0,\n )\n }\n\n}", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/context" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/context" }, "33": { "source": "use crate::context::PrivateContext;\nuse crate::oracle;\nuse crate::types::point::Point;\n\nfn emit_encrypted_log(\n context: &mut PrivateContext,\n contract_address: Field,\n storage_slot: Field,\n encryption_pub_key: Point,\n log: [Field; N],\n) {\n let _ = oracle::logs::emit_encrypted_log(contract_address, storage_slot, encryption_pub_key, log);\n context.accumulate_encrypted_logs(log);\n}\n\nfn emit_unencrypted_log(\n context: &mut PrivateContext,\n log: T,\n) {\n let _ = oracle::logs::emit_unencrypted_log(log);\n context.accumulate_unencrypted_logs(log);\n}\n", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/log" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/log" }, "39": { "source": "use dep::std::option::Option;\nuse crate::abi::PublicContextInputs;\nuse crate::context::{\n PrivateContext,\n PublicContext,\n};\nuse crate::note::{\n note_header::NoteHeader,\n note_interface::NoteInterface,\n utils::compute_inner_note_hash,\n};\nuse crate::oracle::notes::{notify_created_note, notify_nullified_note};\nuse crate::constants_gen::EMPTY_NULLIFIED_COMMITMENT;\n\nfn create_note(\n context: &mut PrivateContext,\n storage_slot: Field,\n note: &mut Note,\n note_interface: NoteInterface,\n) {\n let contract_address = (*context).this_address();\n\n let header = NoteHeader { contract_address, storage_slot, nonce: 0 };\n let set_header = note_interface.set_header;\n set_header(note, header);\n let inner_note_hash = compute_inner_note_hash(note_interface, *note);\n\n let serialise = note_interface.serialise;\n let preimage = serialise(*note);\n assert(notify_created_note(storage_slot, preimage, inner_note_hash) == 0);\n\n context.push_new_note_hash(inner_note_hash);\n}\n\nfn create_note_hash_from_public(\n context: &mut PublicContext,\n storage_slot: Field,\n note: &mut Note,\n note_interface: NoteInterface,\n) {\n let contract_address = (*context).this_address();\n\n let header = NoteHeader { contract_address, storage_slot, nonce: 0 };\n let set_header = note_interface.set_header;\n set_header(note, header);\n let inner_note_hash = compute_inner_note_hash(note_interface, *note);\n\n context.push_new_note_hash(inner_note_hash);\n}\n\nfn destroy_note(\n context: &mut PrivateContext,\n storage_slot: Field,\n note: Note,\n note_interface: NoteInterface,\n) {\n let mut nullifier = 0;\n let mut nullified_commitment: Field = EMPTY_NULLIFIED_COMMITMENT;\n let compute_nullifier = note_interface.compute_nullifier;\n nullifier = compute_nullifier(note);\n\n let serialise = note_interface.serialise;\n let preimage = serialise(note);\n\n // We also need the note commitment corresponding to the \"nullifier\"\n let get_header = note_interface.get_header;\n let header = get_header(note);\n // 0 nonce implies \"transient\" nullifier (must nullify a commitment in this TX).\n // `nullified_commitment` is used to inform the kernel which pending commitment\n // the nullifier corresponds to so they can be matched and both squashed/deleted.\n // nonzero nonce implies \"persistable\" nullifier (nullifies a persistent/in-tree\n // commitment) in which case `nullified_commitment` is not used since the kernel\n // just siloes and forwards the nullier to its output.\n if (header.nonce == 0) {\n // TODO(suyash): Can we reuse the note commitment computed in `compute_nullifier`?\n nullified_commitment = compute_inner_note_hash(note_interface, note);\n }\n assert(notify_nullified_note(storage_slot, nullifier, preimage, nullified_commitment) == 0);\n\n context.push_new_nullifier(nullifier, nullified_commitment)\n}", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/note/lifecycle" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/note/lifecycle" }, "40": { "source": "use dep::std::option::Option;\nuse crate::constants_gen::{\n MAX_READ_REQUESTS_PER_CALL,\n GET_NOTE_ORACLE_RETURN_LENGTH,\n GET_NOTES_ORACLE_RETURN_LENGTH,\n MAX_NOTES_PER_PAGE,\n VIEW_NOTE_ORACLE_RETURN_LENGTH,\n};\nuse crate::context::PrivateContext;\nuse crate::note::{\n note_getter_options::{NoteGetterOptions, Select, Sort},\n note_interface::NoteInterface,\n note_header::NoteHeader,\n note_viewer_options::NoteViewerOptions,\n utils::compute_note_hash_for_read_or_nullify,\n utils::compute_unique_siloed_note_hash,\n utils::compute_inner_note_hash,\n utils::compute_siloed_note_hash,\n};\nuse crate::messaging::get_commitment_getter_data::make_commitment_getter_data;\nuse crate::oracle;\nuse crate::types::vec::BoundedVec;\n\nfn check_note_header(\n context: PrivateContext,\n storage_slot: Field,\n note_interface: NoteInterface,\n note: Note,\n) {\n let get_header = note_interface.get_header;\n let header = get_header(note);\n let contract_address = context.this_address();\n assert(header.contract_address == contract_address);\n assert(header.storage_slot == storage_slot);\n}\n\nfn ensure_note_exists(\n context: &mut PrivateContext,\n storage_slot: Field,\n note_interface: NoteInterface,\n note: &mut Note,\n) {\n let saved_note = get_note_internal(storage_slot, note_interface);\n\n // Only copy over the header to the original note to make sure the preimage is the same.\n let get_header = note_interface.get_header;\n let set_header = note_interface.set_header;\n let note_header = get_header(saved_note);\n set_header(note, note_header);\n\n check_note_header(*context, storage_slot, note_interface, *note);\n\n let note_hash_for_read_request = compute_note_hash_for_read_or_nullify(note_interface, *note);\n context.push_read_request(note_hash_for_read_request);\n}\n\n// Ensure a note's hash exists in the tree without retrieving the entire\n// notes via the oracle.\n// Modifies the note by populating it with header info.\nfn ensure_note_hash_exists(\n context: &mut PrivateContext,\n storage_slot: Field,\n note_interface: NoteInterface,\n note: &mut Note,\n) {\n // Initialize header of note. Must be done before computing note hashes as it initializes the:\n // - storage slot (used in inner note hash)\n // - the contract address (used in siloed note hash)\n // - and the nonce (used in the unique siloed note hash)\n let set_header = note_interface.set_header;\n let note_header = NoteHeader {\n contract_address: (*context).this_address(),\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): should be\n // real nonce (once public kernel applies nonces).\n nonce: 0,\n storage_slot\n };\n set_header(note, note_header);\n\n // Get a note from oracle and early out if it doesn't exist.\n let inner_note_hash = compute_inner_note_hash(note_interface, *note);\n\n let raw_oracle_ret = oracle::get_commitment::get_commitment(inner_note_hash);\n let deserialized_oracle_ret = make_commitment_getter_data(raw_oracle_ret, 0);\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): should be\n // unique_siloed_note_hash once public kernel applies nonces\n let saved_siloed_note_hash = deserialized_oracle_ret.message;\n\n assert(saved_siloed_note_hash != 0); // TODO(dbanks12): necessary?\n\n check_note_header(*context, storage_slot, note_interface, *note);\n\n // Ensure that the note hash retrieved from oracle matches the one computed from note.\n let computed_siloed_note_hash = compute_siloed_note_hash(note_interface, *note);\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): should be\n // compute_note_hash_for_read_or_nullify once public kernel applies nonces\n assert(computed_siloed_note_hash == saved_siloed_note_hash);\n\n context.push_read_request(computed_siloed_note_hash);\n}\n\nfn get_note(\n context: &mut PrivateContext,\n storage_slot: Field,\n note_interface: NoteInterface,\n) -> Note {\n let note = get_note_internal(storage_slot, note_interface);\n\n check_note_header(*context, storage_slot, note_interface, note);\n\n let note_hash_for_read_request = compute_note_hash_for_read_or_nullify(note_interface, note);\n\n context.push_read_request(note_hash_for_read_request);\n note\n}\n\nfn get_notes(\n context: &mut PrivateContext,\n storage_slot: Field,\n note_interface: NoteInterface,\n options: NoteGetterOptions,\n) -> [Option; MAX_READ_REQUESTS_PER_CALL] {\n let opt_notes = get_notes_internal(storage_slot, note_interface, options);\n for i in 0..opt_notes.len() {\n let opt_note = opt_notes[i];\n let mut note_hash_for_read_request = 0;\n if opt_note.is_some() {\n let note = opt_note.unwrap_unchecked();\n check_note_header(*context, storage_slot, note_interface, note);\n note_hash_for_read_request = compute_note_hash_for_read_or_nullify(note_interface, note);\n };\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1410): test to ensure\n // failure if malicious oracle injects 0 nonce here for a \"pre-existing\" note.\n context.push_read_request(note_hash_for_read_request);\n };\n\n // TODO(#1660)\n // Move it back to get_notes_internal and only make read request for selected notes.\n let filter = options.filter;\n let filter_args = options.filter_args;\n filter(opt_notes, filter_args)\n}\n\nunconstrained fn get_note_internal(\n storage_slot: Field,\n note_interface: NoteInterface,\n) -> Note {\n let placeholder_note = [Option::none()];\n let placeholder_fields = [0; GET_NOTE_ORACLE_RETURN_LENGTH];\n oracle::notes::get_notes(\n storage_slot,\n note_interface,\n 0,\n [],\n [],\n [],\n [],\n 1, // limit\n 0, // offset\n placeholder_note,\n placeholder_fields,\n )[0].unwrap() // Notice: we don't allow dummies to be returned from get_note (singular).\n}\n\nunconstrained fn get_notes_internal(\n storage_slot: Field,\n note_interface: NoteInterface,\n options: NoteGetterOptions,\n) -> [Option; MAX_READ_REQUESTS_PER_CALL] {\n let (num_selects, select_by, select_values, sort_by, sort_order) = flatten_options(options.selects, options.sorts);\n let placeholder_opt_notes = [Option::none(); MAX_READ_REQUESTS_PER_CALL];\n let placeholder_fields = [0; GET_NOTES_ORACLE_RETURN_LENGTH];\n oracle::notes::get_notes(\n storage_slot,\n note_interface,\n num_selects,\n select_by,\n select_values,\n sort_by,\n sort_order,\n options.limit,\n options.offset,\n placeholder_opt_notes,\n placeholder_fields,\n )\n}\n\nunconstrained fn view_notes(\n storage_slot: Field,\n note_interface: NoteInterface,\n options: NoteViewerOptions,\n) -> [Option; MAX_NOTES_PER_PAGE] {\n let (num_selects, select_by, select_values, sort_by, sort_order) = flatten_options(options.selects, options.sorts);\n let placeholder_opt_notes = [Option::none(); MAX_NOTES_PER_PAGE];\n let placeholder_fields = [0; VIEW_NOTE_ORACLE_RETURN_LENGTH];\n oracle::notes::get_notes(\n storage_slot,\n note_interface,\n num_selects,\n select_by,\n select_values,\n sort_by,\n sort_order,\n options.limit,\n options.offset,\n placeholder_opt_notes,\n placeholder_fields,\n )\n}\n\nunconstrained fn flatten_options(\n selects: BoundedVec, N>,\n sorts: BoundedVec, N>,\n) -> (u8, [u8; N], [Field; N], [u8; N], [u2; N]) {\n let mut num_selects = 0;\n let mut select_by = [0; N];\n let mut select_values = [0; N];\n for i in 0..selects.len {\n let select = selects.get(i);\n if select.is_some() {\n select_by[num_selects] = select.unwrap_unchecked().field_index;\n select_values[num_selects] = select.unwrap_unchecked().value;\n num_selects += 1;\n };\n };\n\n let mut sort_by = [0; N];\n let mut sort_order = [0; N];\n for i in 0..sorts.len {\n let sort = sorts.get(i);\n if sort.is_some() {\n sort_by[i] = sort.unwrap_unchecked().field_index;\n sort_order[i] = sort.unwrap_unchecked().order;\n };\n };\n\n (num_selects, select_by, select_values, sort_by, sort_order)\n}", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/note/note_getter" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/note/note_getter" }, "42": { "source": "use dep::std::hash::{pedersen, pedersen_with_separator};\nuse crate::constants_gen::{GENERATOR_INDEX__UNIQUE_COMMITMENT, GENERATOR_INDEX__SILOED_COMMITMENT};\n\nfn compute_inner_hash(storage_slot: Field, note_hash: Field) -> Field {\n // TODO(#1205) Do we need a generator index here?\n pedersen([storage_slot, note_hash])[0]\n}\n\nfn compute_siloed_hash(contract_address: Field, inner_note_hash: Field) -> Field {\n let inputs = [contract_address, inner_note_hash];\n pedersen_with_separator(inputs, GENERATOR_INDEX__SILOED_COMMITMENT)[0]\n}\n\nfn compute_unique_hash(nonce: Field, siloed_note_hash: Field) -> Field {\n let inputs = [nonce, siloed_note_hash];\n pedersen_with_separator(inputs, GENERATOR_INDEX__UNIQUE_COMMITMENT)[0]\n}\n", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/note/note_hash" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/note/note_hash" }, "46": { "source": "use crate::note::{\n note_hash::{compute_inner_hash, compute_siloed_hash, compute_unique_hash},\n note_header::NoteHeader,\n note_interface::NoteInterface,\n};\nuse crate::utils::arr_copy_slice;\n\nfn compute_inner_note_hash(\n note_interface: NoteInterface,\n note: Note,\n) -> Field {\n let get_header = note_interface.get_header;\n let header = get_header(note);\n\n let compute_note_hash = note_interface.compute_note_hash;\n let note_hash = compute_note_hash(note);\n\n compute_inner_hash(header.storage_slot, note_hash)\n}\n\nfn compute_siloed_note_hash(\n note_interface: NoteInterface,\n note_with_header: Note,\n) -> Field {\n let get_header = note_interface.get_header;\n let header = get_header(note_with_header);\n\n let inner_note_hash = compute_inner_note_hash(note_interface, note_with_header);\n\n compute_siloed_hash(header.contract_address, inner_note_hash)\n}\n\nfn compute_unique_siloed_note_hash(\n note_interface: NoteInterface,\n note_with_header: Note,\n) -> Field {\n let get_header = note_interface.get_header;\n let header = get_header(note_with_header);\n\n let siloed_note_hash = compute_siloed_note_hash(note_interface, note_with_header);\n\n compute_unique_hash(header.nonce, siloed_note_hash)\n}\n\nfn compute_note_hash_for_read_or_nullify(\n note_interface: NoteInterface,\n note_with_header: Note,\n) -> Field {\n let get_header = note_interface.get_header;\n let header = get_header(note_with_header);\n\n if (header.nonce == 0) {\n // when nonce is zero, that means we are reading a pending note (doesn't have a nonce yet),\n // so we just read the inner_note_hash (kernel will silo by contract address)\n compute_inner_note_hash(note_interface, note_with_header)\n } else {\n // When nonce is nonzero, that means we are reading a settled note (from tree) created in a\n // previous TX. So we need the unique_siloed_note_hash which has already been hashed with\n // contract address and then nonce. This hash will match the existing leaf in the private\n // data tree, so the kernel can just perform a membership check directly on this hash/leaf.\n compute_unique_siloed_note_hash(note_interface, note_with_header)\n }\n\n}\n\nfn compute_note_hash_and_nullifier(\n note_interface: NoteInterface,\n note_header: NoteHeader,\n preimage: [Field; S],\n) -> [Field; 4] {\n let deserialise = note_interface.deserialise;\n let set_header = note_interface.set_header;\n let mut note = deserialise(arr_copy_slice(preimage, [0; N], 0));\n set_header(&mut note, note_header);\n\n let compute_note_hash = note_interface.compute_note_hash;\n let note_hash = compute_note_hash(note);\n let inner_note_hash = compute_inner_hash(note_header.storage_slot, note_hash);\n\n let siloed_note_hash = compute_siloed_hash(note_header.contract_address, inner_note_hash);\n\n let unique_siloed_note_hash = compute_unique_hash(note_header.nonce, siloed_note_hash);\n\n let compute_nullifier = note_interface.compute_nullifier;\n let inner_nullifier = compute_nullifier(note);\n\n [inner_note_hash, siloed_note_hash, unique_siloed_note_hash, inner_nullifier]\n}\n", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/note/utils" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/note/utils" }, "48": { "source": "use dep::std::hash::pedersen_with_separator;\nuse crate::context::PrivateContext;\nuse crate::note::{\n lifecycle::create_note,\n note_getter::{get_note, view_notes},\n note_interface::NoteInterface,\n note_viewer_options::NoteViewerOptions,\n};\nuse crate::oracle;\nuse crate::constants_gen::{\n GENERATOR_INDEX__INITIALISATION_NULLIFIER,\n EMPTY_NULLIFIED_COMMITMENT,\n};\n\nstruct ImmutableSingleton {\n storage_slot: Field,\n note_interface: NoteInterface,\n}\n\nimpl ImmutableSingleton {\n fn new(storage_slot: Field, note_interface: NoteInterface) -> Self {\n ImmutableSingleton { storage_slot, note_interface }\n }\n\n unconstrained fn is_initialised(self) -> bool {\n let nullifier = self.compute_initialisation_nullifier();\n oracle::notes::is_nullifier_emitted(nullifier)\n }\n\n fn initialise(self, context: &mut PrivateContext, note: &mut Note) {\n // Nullify the storage slot.\n let nullifier = self.compute_initialisation_nullifier();\n context.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT);\n\n create_note(context, self.storage_slot, note, self.note_interface);\n }\n\n fn compute_initialisation_nullifier(self) -> Field {\n pedersen_with_separator([self.storage_slot], GENERATOR_INDEX__INITIALISATION_NULLIFIER)[0]\n }\n \n fn get_note(self, context: &mut PrivateContext) -> Note {\n let storage_slot = self.storage_slot;\n get_note(context, storage_slot, self.note_interface)\n }\n\n unconstrained fn view_note(self) -> Note {\n let options = NoteViewerOptions::new().set_limit(1);\n view_notes(self.storage_slot, self.note_interface, options)[0].unwrap()\n }\n}", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/state_vars/immutable_singleton" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/state_vars/immutable_singleton" }, "55": { "source": "\nstruct BoundedVec {\n storage: [T; MaxLen],\n len: Field,\n}\n\nimpl BoundedVec {\n fn new(initial_value: T) -> Self {\n BoundedVec { storage: [initial_value; MaxLen], len: 0 }\n }\n\n fn get(mut self: Self, index: Field) -> T {\n assert(index as u64 < self.len as u64);\n self.storage[index]\n }\n\n fn push(&mut self, elem: T) {\n assert(self.len as u64 < MaxLen as u64);\n\n self.storage[self.len] = elem;\n self.len += 1;\n }\n\n fn push_array(&mut self, array: [T; Len]) {\n let newLen = self.len + array.len();\n assert(newLen as u64 <= MaxLen as u64);\n for i in 0..array.len() {\n self.storage[self.len + i] = array[i];\n }\n self.len = newLen;\n }\n\n fn pop(&mut self) -> T {\n assert(self.len as u64 > 0);\n\n let elem = self.storage[self.len - 1];\n self.len -= 1;\n elem\n }\n}\n\n// #[test]\n// fn test_vec() {\n// let vec: BoundedVec = BoundedVec::new(0);\n// assert(vec.len == 0);\n// let vec1 = vec.push(1);\n// assert(vec1.len == 1);\n// let vec2 = vec1.push(1);\n// assert(vec2.len == 2);\n// let vec3 = vec2.push(1);\n// assert(vec3.len == 3);\n// let x = vec3.pop();\n// assert(x == 1);\n// }", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/types/vec" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/types/vec" }, "70": { "source": "use crate::types::point::Point;\nuse dep::std::hash;\nuse crate::constants_gen::GENERATOR_INDEX__CONTRACT_ADDRESS;\n\n#[oracle(getPublicKey)]\nfn get_public_key_oracle(_address: Field) -> [Field; 3] {}\n\nunconstrained fn get_public_key_internal(address: Field) -> [Field; 3] {\n get_public_key_oracle(address)\n}\n\nfn get_public_key(address: Field) -> Point {\n let result = get_public_key_internal(address);\n let pub_key_x = result[0];\n let pub_key_y = result[1];\n let partial_address = result[2];\n \n let calculated_address = hash::pedersen_with_separator([pub_key_x, pub_key_y, partial_address], GENERATOR_INDEX__CONTRACT_ADDRESS)[0];\n assert(calculated_address == address);\n \n Point::new(pub_key_x, pub_key_y)\n}\n", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/oracle/get_public_key" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/oracle/get_public_key" }, "78": { "source": "use crate::abi;\nuse crate::types::vec::BoundedVec;\nuse crate::context::PrivateContext;\nuse crate::private_call_stack_item::PrivateCallStackItem;\nuse crate::public_call_stack_item::PublicCallStackItem; \n\nglobal ACCOUNT_MAX_PRIVATE_CALLS: Field = 2;\nglobal ACCOUNT_MAX_PUBLIC_CALLS: Field = 2;\nglobal ACCOUNT_MAX_CALLS: Field = 4;\n// 1 (ARGS_HASH) + 1 (FUNCTION_SELECTOR) + 1 (TARGET_ADDRESS)\nglobal FUNCTION_CALL_SIZE: Field = 3;\n\nstruct FunctionCall {\n args_hash: Field,\n function_selector: Field,\n target_address: Field,\n}\n\nimpl FunctionCall {\n fn serialize(self) -> [Field; FUNCTION_CALL_SIZE] {\n [self.args_hash, self.function_selector, self.target_address]\n }\n}\n\n// FUNCTION_CALL_SIZE * (ACCOUNT_MAX_PUBLIC_CALLS + ACCOUNT_MAX_PRIVATE_CALLS) + 1\nglobal ENTRYPOINT_PAYLOAD_SIZE: Field = 13;\nglobal ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES: Field = 416;\n\nstruct EntrypointPayload {\n // Noir doesnt support nested arrays or structs yet so we flatten everything\n flattened_args_hashes: [Field; ACCOUNT_MAX_CALLS],\n flattened_selectors: [Field; ACCOUNT_MAX_CALLS],\n flattened_targets: [Field; ACCOUNT_MAX_CALLS],\n nonce: Field,\n}\n\nimpl EntrypointPayload {\n // TODO(#1207) Do we need a generator index?\n fn hash(self) -> Field {\n dep::std::hash::pedersen(self.serialize())[0]\n }\n\n // Serializes the entrypoint struct\n fn serialize(self) -> [Field; ENTRYPOINT_PAYLOAD_SIZE] {\n let mut fields: BoundedVec = BoundedVec::new(0); \n fields.push_array(self.flattened_args_hashes);\n fields.push_array(self.flattened_selectors);\n fields.push_array(self.flattened_targets);\n fields.push(self.nonce);\n fields.storage\n }\n\n // Serializes the payload as an array of bytes. Useful for hashing with sha256.\n fn to_be_bytes(self) -> [u8; ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES] {\n let mut bytes: [u8; ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES] = [0; ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES];\n\n let args_len = self.flattened_args_hashes.len();\n let selectors_len = self.flattened_selectors.len();\n let targets_len = self.flattened_targets.len();\n\n for i in 0..args_len {\n let item_bytes = self.flattened_args_hashes[i].to_be_bytes(32);\n for j in 0..32 { \n bytes[i * 32 + j] = item_bytes[j];\n }\n }\n\n for i in 0..selectors_len {\n let item_bytes = self.flattened_selectors[i].to_be_bytes(32);\n for j in 0..32 { \n bytes[args_len * 32 + i * 32 + j] = item_bytes[j];\n }\n }\n\n for i in 0..targets_len {\n let item_bytes = self.flattened_targets[i].to_be_bytes(32);\n for j in 0..32 { \n bytes[(args_len + selectors_len) * 32 + i * 32 + j] = item_bytes[j];\n }\n }\n \n let item_bytes = self.nonce.to_be_bytes(32);\n for j in 0..32 { \n bytes[(args_len + selectors_len + targets_len) * 32 + j] = item_bytes[j];\n }\n\n bytes\n }\n\n // Executes all private and public calls \n fn execute_calls(self, context: &mut PrivateContext) {\n for i in 0..ACCOUNT_MAX_PRIVATE_CALLS {\n let target_address = self.flattened_targets[i];\n if target_address != 0 {\n let function_selector = self.flattened_selectors[i];\n let args_hash = self.flattened_args_hashes[i];\n let _callStackItem = context.call_private_function_with_packed_args(target_address, function_selector, args_hash);\n }\n }\n for i in ACCOUNT_MAX_PRIVATE_CALLS..ACCOUNT_MAX_CALLS {\n let target_address = self.flattened_targets[i];\n if target_address != 0 {\n let function_selector = self.flattened_selectors[i];\n let args_hash = self.flattened_args_hashes[i];\n let _callStackItem = context.call_public_function_with_packed_args(target_address, function_selector, args_hash);\n }\n }\n }\n}", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/entrypoint" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/entrypoint" } } } diff --git a/yarn-project/aztec.js/src/abis/schnorr_account_contract.json b/yarn-project/aztec.js/src/abis/schnorr_account_contract.json index 251a685cdcf8..580e30ab0dc9 100644 --- a/yarn-project/aztec.js/src/abis/schnorr_account_contract.json +++ b/yarn-project/aztec.js/src/abis/schnorr_account_contract.json @@ -154,7 +154,7 @@ "fileMap": { "0": { "source": "mod storage;\nmod public_key_note;\n\n// Account contract that uses Schnorr signatures for authentication.\n// The signing key is stored in an immutable private note and should be different from the encryption/nullifying key.\ncontract SchnorrAccount {\n use dep::std;\n use dep::aztec::entrypoint;\n use dep::aztec::entrypoint::EntrypointPayload;\n use dep::aztec::abi;\n use dep::aztec::abi::PrivateContextInputs;\n use dep::aztec::abi::CallContext;\n use dep::aztec::private_call_stack_item::PrivateCallStackItem;\n use dep::aztec::public_call_stack_item::PublicCallStackItem;\n use dep::aztec::context::PrivateContext;\n use dep::aztec::log::emit_encrypted_log;\n use dep::aztec::oracle::get_public_key::get_public_key;\n use dep::aztec::types::vec::BoundedVec;\n use dep::aztec::types::point::Point;\n use dep::aztec::note::utils as note_utils;\n use dep::aztec::note::note_header::NoteHeader;\n use dep::aztec::constants_gen::MAX_NOTE_FIELDS_LENGTH;\n use dep::aztec::constants_gen::GENERATOR_INDEX__CONTRACT_ADDRESS;\n use dep::aztec::constants_gen::GENERATOR_INDEX__SIGNATURE_PAYLOAD;\n\n use crate::storage::Storage;\n use crate::public_key_note::PublicKeyNote;\n use crate::public_key_note::PublicKeyNoteMethods;\n use crate::public_key_note::PUBLIC_KEY_NOTE_LEN;\n\n // docs:start:entrypoint\n\n fn entrypoint(\n inputs: pub PrivateContextInputs,\n payload: pub EntrypointPayload, // contains a set of arguments, selectors, targets and a nonce\n signature: pub [u8;64], // schnorr signature of the payload hash\n ) -> distinct pub abi::PrivateCircuitPublicInputs {\n // Initialize context\n // ENTRYPOINT_PAYLOAD_SIZE(13) + 64\n let mut args: BoundedVec = BoundedVec::new(0);\n args.push_array(payload.serialize());\n for byte in signature { args.push(byte as Field); }\n let mut context = PrivateContext::new(inputs, abi::hash_args(args.storage));\n\n // Load public key from storage\n let storage = Storage::init();\n let public_key = storage.signing_public_key.get_note(&mut context);\n\n // Verify payload signature\n let payload_fields: [Field; entrypoint::ENTRYPOINT_PAYLOAD_SIZE] = payload.serialize();\n let message_field: Field = std::hash::pedersen_with_separator(payload_fields, GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0];\n let message_bytes = message_field.to_be_bytes(32);\n\n // Verify signature of the payload bytes\n let verification = std::schnorr::verify_signature(public_key.x, public_key.y, signature, message_bytes);\n assert(verification == true);\n\n // docs:end:entrypoint\n\n // Execute calls\n payload.execute_calls(&mut context);\n\n context.finish()\n }\n\n // Constructs the contract\n fn constructor(\n inputs: pub PrivateContextInputs,\n signing_pub_key_x: pub Field,\n signing_pub_key_y: pub Field,\n ) -> distinct pub abi::PrivateCircuitPublicInputs {\n let storage = Storage::init();\n \n let mut context = PrivateContext::new(inputs, abi::hash_args([signing_pub_key_x, signing_pub_key_y]));\n \n let this = context.this_address();\n let mut pub_key_note = PublicKeyNote::new(signing_pub_key_x, signing_pub_key_y, this);\n storage.signing_public_key.initialise(&mut context, &mut pub_key_note);\n \n emit_encrypted_log(\n &mut context,\n this,\n storage.signing_public_key.storage_slot,\n get_public_key(this),\n pub_key_note.serialise(),\n );\n\n context.finish()\n }\n\n // Computes notes hash and nullifier.\n // Note 1: Needs to be defined by every contract producing logs.\n // Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.\n unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; PUBLIC_KEY_NOTE_LEN]) -> [Field; 4] {\n assert(storage_slot == 1);\n let note_header = NoteHeader { contract_address, nonce, storage_slot };\n note_utils::compute_note_hash_and_nullifier(PublicKeyNoteMethods, note_header, preimage)\n }\n}\n", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-contracts/src/contracts/schnorr_account_contract/src/main" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-contracts/src/contracts/schnorr_account_contract/src/main" }, "3": { "source": "mod poseidon;\n\n#[foreign(sha256)]\nfn sha256(_input : [u8; N]) -> [u8; 32] {}\n\n#[foreign(blake2s)]\nfn blake2s(_input : [u8; N]) -> [u8; 32] {}\n\nfn pedersen(input : [Field; N]) -> [Field; 2] {\n pedersen_with_separator(input, 0)\n}\n\n#[foreign(pedersen)]\nfn pedersen_with_separator(_input : [Field; N], _separator : u32) -> [Field; 2] {}\n\n#[foreign(hash_to_field_128_security)]\nfn hash_to_field(_input : [Field; N]) -> Field {}\n\n#[foreign(keccak256)]\nfn keccak256(_input : [u8; N], _message_size: u32) -> [u8; 32] {}\n\n// mimc-p/p implementation\n// constants are (publicly generated) random numbers, for instance using keccak as a ROM.\n// You must use constants generated for the native field\n// Rounds number should be ~ log(p)/log(exp)\n// For 254 bit primes, exponent 7 and 91 rounds seems to be recommended\nfn mimc(x: Field, k: Field, constants: [Field; N], exp : Field) -> Field {\n //round 0\n let mut t = x + k;\n let mut h = t.pow_32(exp);\n //next rounds\n for i in 1 .. constants.len() {\n t = h + k + constants[i];\n h = t.pow_32(exp);\n };\n h + k\n}\n\nglobal MIMC_BN254_ROUNDS = 91;\n\n//mimc implementation with hardcoded parameters for BN254 curve.\nfn mimc_bn254(array: [Field; N]) -> Field {\n //mimc parameters\n let exponent = 7;\n //generated from seed \"mimc\" using keccak256 \n let constants: [Field; MIMC_BN254_ROUNDS] = [\n 0, \n 20888961410941983456478427210666206549300505294776164667214940546594746570981,\n 15265126113435022738560151911929040668591755459209400716467504685752745317193,\n 8334177627492981984476504167502758309043212251641796197711684499645635709656,\n 1374324219480165500871639364801692115397519265181803854177629327624133579404,\n 11442588683664344394633565859260176446561886575962616332903193988751292992472,\n 2558901189096558760448896669327086721003508630712968559048179091037845349145,\n 11189978595292752354820141775598510151189959177917284797737745690127318076389,\n 3262966573163560839685415914157855077211340576201936620532175028036746741754,\n 17029914891543225301403832095880481731551830725367286980611178737703889171730,\n 4614037031668406927330683909387957156531244689520944789503628527855167665518,\n 19647356996769918391113967168615123299113119185942498194367262335168397100658,\n 5040699236106090655289931820723926657076483236860546282406111821875672148900,\n 2632385916954580941368956176626336146806721642583847728103570779270161510514,\n 17691411851977575435597871505860208507285462834710151833948561098560743654671,\n 11482807709115676646560379017491661435505951727793345550942389701970904563183,\n 8360838254132998143349158726141014535383109403565779450210746881879715734773,\n 12663821244032248511491386323242575231591777785787269938928497649288048289525,\n 3067001377342968891237590775929219083706800062321980129409398033259904188058,\n 8536471869378957766675292398190944925664113548202769136103887479787957959589,\n 19825444354178182240559170937204690272111734703605805530888940813160705385792,\n 16703465144013840124940690347975638755097486902749048533167980887413919317592,\n 13061236261277650370863439564453267964462486225679643020432589226741411380501,\n 10864774797625152707517901967943775867717907803542223029967000416969007792571,\n 10035653564014594269791753415727486340557376923045841607746250017541686319774,\n 3446968588058668564420958894889124905706353937375068998436129414772610003289,\n 4653317306466493184743870159523234588955994456998076243468148492375236846006,\n 8486711143589723036499933521576871883500223198263343024003617825616410932026,\n 250710584458582618659378487568129931785810765264752039738223488321597070280,\n 2104159799604932521291371026105311735948154964200596636974609406977292675173,\n 16313562605837709339799839901240652934758303521543693857533755376563489378839,\n 6032365105133504724925793806318578936233045029919447519826248813478479197288,\n 14025118133847866722315446277964222215118620050302054655768867040006542798474,\n 7400123822125662712777833064081316757896757785777291653271747396958201309118,\n 1744432620323851751204287974553233986555641872755053103823939564833813704825,\n 8316378125659383262515151597439205374263247719876250938893842106722210729522,\n 6739722627047123650704294650168547689199576889424317598327664349670094847386,\n 21211457866117465531949733809706514799713333930924902519246949506964470524162,\n 13718112532745211817410303291774369209520657938741992779396229864894885156527,\n 5264534817993325015357427094323255342713527811596856940387954546330728068658,\n 18884137497114307927425084003812022333609937761793387700010402412840002189451,\n 5148596049900083984813839872929010525572543381981952060869301611018636120248,\n 19799686398774806587970184652860783461860993790013219899147141137827718662674,\n 19240878651604412704364448729659032944342952609050243268894572835672205984837,\n 10546185249390392695582524554167530669949955276893453512788278945742408153192,\n 5507959600969845538113649209272736011390582494851145043668969080335346810411,\n 18177751737739153338153217698774510185696788019377850245260475034576050820091,\n 19603444733183990109492724100282114612026332366576932662794133334264283907557,\n 10548274686824425401349248282213580046351514091431715597441736281987273193140,\n 1823201861560942974198127384034483127920205835821334101215923769688644479957,\n 11867589662193422187545516240823411225342068709600734253659804646934346124945,\n 18718569356736340558616379408444812528964066420519677106145092918482774343613,\n 10530777752259630125564678480897857853807637120039176813174150229243735996839,\n 20486583726592018813337145844457018474256372770211860618687961310422228379031,\n 12690713110714036569415168795200156516217175005650145422920562694422306200486,\n 17386427286863519095301372413760745749282643730629659997153085139065756667205,\n 2216432659854733047132347621569505613620980842043977268828076165669557467682,\n 6309765381643925252238633914530877025934201680691496500372265330505506717193,\n 20806323192073945401862788605803131761175139076694468214027227878952047793390,\n 4037040458505567977365391535756875199663510397600316887746139396052445718861,\n 19948974083684238245321361840704327952464170097132407924861169241740046562673,\n 845322671528508199439318170916419179535949348988022948153107378280175750024,\n 16222384601744433420585982239113457177459602187868460608565289920306145389382,\n 10232118865851112229330353999139005145127746617219324244541194256766741433339,\n 6699067738555349409504843460654299019000594109597429103342076743347235369120,\n 6220784880752427143725783746407285094967584864656399181815603544365010379208,\n 6129250029437675212264306655559561251995722990149771051304736001195288083309,\n 10773245783118750721454994239248013870822765715268323522295722350908043393604,\n 4490242021765793917495398271905043433053432245571325177153467194570741607167,\n 19596995117319480189066041930051006586888908165330319666010398892494684778526,\n 837850695495734270707668553360118467905109360511302468085569220634750561083,\n 11803922811376367215191737026157445294481406304781326649717082177394185903907,\n 10201298324909697255105265958780781450978049256931478989759448189112393506592,\n 13564695482314888817576351063608519127702411536552857463682060761575100923924,\n 9262808208636973454201420823766139682381973240743541030659775288508921362724,\n 173271062536305557219323722062711383294158572562695717740068656098441040230,\n 18120430890549410286417591505529104700901943324772175772035648111937818237369,\n 20484495168135072493552514219686101965206843697794133766912991150184337935627,\n 19155651295705203459475805213866664350848604323501251939850063308319753686505,\n 11971299749478202793661982361798418342615500543489781306376058267926437157297,\n 18285310723116790056148596536349375622245669010373674803854111592441823052978,\n 7069216248902547653615508023941692395371990416048967468982099270925308100727,\n 6465151453746412132599596984628739550147379072443683076388208843341824127379,\n 16143532858389170960690347742477978826830511669766530042104134302796355145785,\n 19362583304414853660976404410208489566967618125972377176980367224623492419647,\n 1702213613534733786921602839210290505213503664731919006932367875629005980493,\n 10781825404476535814285389902565833897646945212027592373510689209734812292327,\n 4212716923652881254737947578600828255798948993302968210248673545442808456151,\n 7594017890037021425366623750593200398174488805473151513558919864633711506220,\n 18979889247746272055963929241596362599320706910852082477600815822482192194401,\n 13602139229813231349386885113156901793661719180900395818909719758150455500533,\n ];\n\n let mut r = 0;\n for elem in array {\n let h = mimc(elem, r, constants, exponent);\n r = r + elem + h;\n }\n r\n}\n", @@ -166,47 +166,47 @@ }, "31": { "source": "use crate::constants_gen::{\n RETURN_VALUES_LENGTH,\n MAX_READ_REQUESTS_PER_CALL,\n MAX_NEW_COMMITMENTS_PER_CALL,\n MAX_NEW_NULLIFIERS_PER_CALL,\n MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL,\n MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,\n MAX_NEW_L2_TO_L1_MSGS_PER_CALL,\n NUM_FIELDS_PER_SHA256,\n MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,\n MAX_PUBLIC_DATA_READS_PER_CALL,\n GENERATOR_INDEX__FUNCTION_ARGS,\n HISTORIC_BLOCK_DATA_LENGTH,\n CONTRACT_DEPLOYMENT_DATA_LENGTH,\n CALL_CONTEXT_LENGTH,\n PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH,\n PRIVATE_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH,\n CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH,\n CONTRACT_STORAGE_READ_LENGTH,\n PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH,\n PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH,\n GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS,\n GENERATOR_INDEX__FUNCTION_DATA,\n GENERATOR_INDEX__PUBLIC_DATA_READ,\n GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST,\n GENERATOR_INDEX__CALL_CONTEXT,\n GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS,\n GENERATOR_INDEX__CONTRACT_DEPLOYMENT_DATA,\n};\n\nuse crate::oracle::debug_log;\nuse crate::types::vec::BoundedVec;\nuse crate::types::point::Point;\n\nstruct PrivateGlobalVariables {\n chain_id: Field,\n version: Field,\n}\n\nimpl PrivateGlobalVariables {\n fn serialize(self) -> [Field; 2] {\n [self.chain_id, self.version]\n }\n}\n\nstruct PublicGlobalVariables {\n chain_id: Field,\n version: Field,\n block_number: Field,\n timestamp: Field,\n}\n\nimpl PublicGlobalVariables {\n fn serialize(self) -> [Field; 4] {\n [self.chain_id, self.version, self.block_number, self.timestamp]\n }\n}\n\nstruct ContractDeploymentData {\n deployer_public_key: Point,\n constructor_vk_hash : Field,\n function_tree_root : Field,\n contract_address_salt : Field,\n portal_contract_address : Field,\n}\n\nimpl ContractDeploymentData {\n fn serialize(self) -> [Field; CONTRACT_DEPLOYMENT_DATA_LENGTH] {\n [\n self.deployer_public_key.x,\n self.deployer_public_key.y,\n self.constructor_vk_hash,\n self.function_tree_root,\n self.contract_address_salt,\n self.portal_contract_address,\n ]\n }\n\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__CONTRACT_DEPLOYMENT_DATA)[0]\n }\n}\n\n// PrivateContextInputs are expected to be provided to each private function\nstruct PrivateContextInputs {\n call_context : CallContext,\n block_data: HistoricBlockData,\n\n contract_deployment_data: ContractDeploymentData,\n\n private_global_variables: PrivateGlobalVariables,\n}\n\n// PublicContextInputs are expected to be provided to each public function\nstruct PublicContextInputs {\n call_context: CallContext,\n block_data: HistoricBlockData,\n\n public_global_variables: PublicGlobalVariables,\n}\n\nstruct CallContext {\n msg_sender : Field,\n storage_contract_address : Field,\n portal_contract_address : Field,\n\n is_delegate_call : bool,\n is_static_call : bool,\n is_contract_deployment: bool,\n}\n\nimpl CallContext {\n fn serialize(self) -> [Field; CALL_CONTEXT_LENGTH] {\n [\n self.msg_sender,\n self.storage_contract_address,\n self.portal_contract_address,\n self.is_delegate_call as Field,\n self.is_static_call as Field,\n self.is_contract_deployment as Field,\n ]\n }\n\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__CALL_CONTEXT)[0]\n }\n}\n\nstruct HistoricBlockData {\n private_data_tree_root : Field,\n nullifier_tree_root : Field,\n contract_tree_root : Field,\n l1_to_l2_messages_tree_root : Field,\n blocks_tree_root: Field,\n public_data_tree_root: Field,\n global_variables_hash: Field,\n}\n\nimpl HistoricBlockData {\n // NOTE: this order must match the order in `private_circuit_public_inputs.hpp`\n fn serialize(self) -> [Field; HISTORIC_BLOCK_DATA_LENGTH] {\n [\n self.private_data_tree_root,\n self.nullifier_tree_root,\n self.contract_tree_root,\n self.l1_to_l2_messages_tree_root,\n self.blocks_tree_root,\n self.public_data_tree_root,\n self.global_variables_hash,\n ]\n }\n\n fn empty() -> Self {\n Self { private_data_tree_root: 0, nullifier_tree_root: 0, contract_tree_root: 0, l1_to_l2_messages_tree_root: 0, blocks_tree_root: 0, public_data_tree_root: 0, global_variables_hash: 0 }\n }\n}\n\nstruct FunctionData {\n function_selector: Field,\n is_internal: bool,\n is_private: bool,\n is_constructor: bool,\n}\n\nimpl FunctionData {\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator([\n self.function_selector,\n self.is_internal as Field,\n self.is_private as Field,\n self.is_constructor as Field,\n ], GENERATOR_INDEX__FUNCTION_DATA)[0]\n }\n}\n\nstruct PrivateCircuitPublicInputs {\n call_context: CallContext,\n args_hash: Field,\n return_values: [Field; RETURN_VALUES_LENGTH],\n read_requests: [Field; crate::abi::MAX_READ_REQUESTS_PER_CALL],\n new_commitments: [Field; MAX_NEW_COMMITMENTS_PER_CALL],\n new_nullifiers: [Field; MAX_NEW_NULLIFIERS_PER_CALL],\n nullified_commitments: [Field; MAX_NEW_NULLIFIERS_PER_CALL],\n private_call_stack: [Field; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL],\n public_call_stack: [Field; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL],\n new_l2_to_l1_msgs: [Field; MAX_NEW_L2_TO_L1_MSGS_PER_CALL],\n // Explore introducing a new type like uint256 (similar to Point), so it's more explicit that\n // we're talking about a single number backed by two field elements.\n encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256],\n unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256],\n encrypted_log_preimages_length: Field,\n unencrypted_log_preimages_length: Field,\n block_data: HistoricBlockData,\n contract_deployment_data: ContractDeploymentData,\n chain_id: Field,\n version: Field,\n}\n\nimpl PrivateCircuitPublicInputs {\n fn hash(self) -> Field {\n let mut fields: BoundedVec = BoundedVec::new(0); \n fields.push(self.call_context.hash());\n fields.push(self.args_hash);\n fields.push_array(self.return_values);\n fields.push_array(self.read_requests);\n fields.push_array(self.new_commitments);\n fields.push_array(self.new_nullifiers);\n fields.push_array(self.nullified_commitments);\n fields.push_array(self.private_call_stack);\n fields.push_array(self.public_call_stack);\n fields.push_array(self.new_l2_to_l1_msgs);\n fields.push_array(self.encrypted_logs_hash);\n fields.push_array(self.unencrypted_logs_hash);\n fields.push(self.encrypted_log_preimages_length);\n fields.push(self.unencrypted_log_preimages_length);\n fields.push_array(self.block_data.serialize());\n fields.push(self.contract_deployment_data.hash());\n fields.push(self.chain_id);\n fields.push(self.version);\n\n dep::std::hash::pedersen_with_separator(fields.storage, GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS)[0]\n }\n\n fn serialize(self) -> [Field; PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH] {\n let mut fields: BoundedVec = BoundedVec::new(0); \n fields.push_array(self.call_context.serialize());\n fields.push(self.args_hash);\n fields.push_array(self.return_values);\n fields.push_array(self.read_requests);\n fields.push_array(self.new_commitments);\n fields.push_array(self.new_nullifiers);\n fields.push_array(self.private_call_stack);\n fields.push_array(self.public_call_stack);\n fields.push_array(self.new_l2_to_l1_msgs);\n fields.push_array(self.encrypted_logs_hash);\n fields.push_array(self.unencrypted_logs_hash);\n fields.push(self.encrypted_log_preimages_length);\n fields.push(self.unencrypted_log_preimages_length);\n fields.push_array(self.block_data.serialize());\n fields.push_array(self.contract_deployment_data.serialize());\n fields.push(self.chain_id);\n fields.push(self.version);\n fields.storage\n }\n}\n\nstruct ContractStorageRead {\n storage_slot: Field,\n value: Field,\n}\n\nimpl ContractStorageRead {\n fn serialize(self) -> [Field; CONTRACT_STORAGE_READ_LENGTH] {\n [self.storage_slot, self.value]\n }\n\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__PUBLIC_DATA_READ)[0]\n }\n\n fn empty() -> Self {\n Self { storage_slot: 0, value: 0 }\n }\n}\n\nstruct ContractStorageUpdateRequest {\n storage_slot: Field,\n old_value: Field,\n new_value: Field,\n}\n\nimpl ContractStorageUpdateRequest {\n fn serialize(self) -> [Field; CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH] {\n [self.storage_slot, self.old_value, self.new_value]\n }\n\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST)[0]\n }\n\n fn empty() -> Self {\n Self { storage_slot: 0, old_value: 0, new_value: 0 }\n }\n}\n\n\nstruct PublicCircuitPublicInputs {\n call_context: CallContext,\n args_hash: Field,\n return_values: [Field; RETURN_VALUES_LENGTH],\n contract_storage_update_requests: [ContractStorageUpdateRequest; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL],\n contract_storage_read: [ContractStorageRead; MAX_PUBLIC_DATA_READS_PER_CALL],\n public_call_stack: [Field; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL],\n new_commitments: [Field; MAX_NEW_COMMITMENTS_PER_CALL],\n new_nullifiers: [Field; crate::abi::MAX_NEW_NULLIFIERS_PER_CALL],\n new_l2_to_l1_msgs: [Field; crate::abi::MAX_NEW_L2_TO_L1_MSGS_PER_CALL],\n unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256],\n unencrypted_log_preimages_length: Field,\n block_data: HistoricBlockData,\n prover_address: Field,\n\n // TODO: include globals in here and check them elsewhere\n // https://github.com/AztecProtocol/aztec-packages/issues/1567\n}\n\nimpl PublicCircuitPublicInputs {\n \n fn hash(self) -> Field {\n let mut inputs: BoundedVec = BoundedVec::new(0);\n inputs.push(self.call_context.hash());\n inputs.push(self.args_hash);\n inputs.push_array(self.return_values);\n for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL {\n inputs.push(self.contract_storage_update_requests[i].hash());\n }\n for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL {\n inputs.push(self.contract_storage_read[i].hash());\n }\n inputs.push_array(self.public_call_stack);\n inputs.push_array(self.new_commitments);\n inputs.push_array(self.new_nullifiers);\n inputs.push_array(self.new_l2_to_l1_msgs);\n\n // We do not include block_data since it's not in the cpp hash\n\n inputs.push_array(self.unencrypted_logs_hash);\n inputs.push(self.unencrypted_log_preimages_length);\n inputs.push_array(self.block_data.serialize()); // see https://github.com/AztecProtocol/aztec-packages/issues/1473\n inputs.push(self.prover_address);\n\n dep::std::hash::pedersen_with_separator(inputs.storage, GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS)[0]\n }\n\n fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] {\n let mut fields: BoundedVec = BoundedVec::new(0); \n fields.push_array(self.call_context.serialize()); \n fields.push(self.args_hash);\n fields.push_array(self.return_values);\n for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL {\n fields.push_array(self.contract_storage_update_requests[i].serialize());\n }\n for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL {\n fields.push_array(self.contract_storage_read[i].serialize());\n }\n fields.push_array(self.public_call_stack);\n fields.push_array(self.new_commitments);\n fields.push_array(self.new_nullifiers);\n fields.push_array(self.new_l2_to_l1_msgs);\n fields.push_array(self.unencrypted_logs_hash);\n fields.push(self.unencrypted_log_preimages_length);\n fields.push_array(self.block_data.serialize());\n fields.push(self.prover_address);\n fields.storage\n }\n}\n\nglobal ARGS_HASH_CHUNK_LENGTH: u32 = 32;\nglobal ARGS_HASH_CHUNK_COUNT: u32 = 16;\n\nfn hash_args(args: [Field; N]) -> Field {\n if args.len() == 0 {\n 0\n } else {\n let mut chunks_hashes = [0; ARGS_HASH_CHUNK_COUNT];\n for i in 0..ARGS_HASH_CHUNK_COUNT {\n let mut chunk_hash = 0;\n let start_chunk_index = i * ARGS_HASH_CHUNK_LENGTH;\n if start_chunk_index < (args.len() as u32) {\n let mut chunk_args = [0; ARGS_HASH_CHUNK_LENGTH];\n for j in 0..ARGS_HASH_CHUNK_LENGTH {\n let item_index = i * ARGS_HASH_CHUNK_LENGTH + j;\n if item_index < (args.len() as u32) {\n chunk_args[j] = args[item_index];\n }\n }\n chunk_hash = dep::std::hash::pedersen_with_separator(chunk_args, GENERATOR_INDEX__FUNCTION_ARGS)[0];\n }\n chunks_hashes[i] = chunk_hash;\n }\n dep::std::hash::pedersen_with_separator(chunks_hashes, GENERATOR_INDEX__FUNCTION_ARGS)[0]\n }\n}\n", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/abi" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/abi" }, "32": { "source": "use crate::constants_gen::{\n EMPTY_NULLIFIED_COMMITMENT,\n MAX_NEW_COMMITMENTS_PER_CALL,\n MAX_NEW_L2_TO_L1_MSGS_PER_CALL,\n MAX_NEW_NULLIFIERS_PER_CALL,\n MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL,\n MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,\n MAX_PUBLIC_DATA_READS_PER_CALL,\n MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,\n MAX_READ_REQUESTS_PER_CALL,\n NUM_FIELDS_PER_SHA256,\n RETURN_VALUES_LENGTH,\n};\n\nuse crate::abi;\n\nuse crate::abi::{\n hash_args,\n CallContext,\n ContractDeploymentData,\n HistoricBlockData,\n FunctionData,\n PrivateCircuitPublicInputs,\n PublicCircuitPublicInputs,\n};\n\n// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n// use dep::std::collections::vec::Vec;\n\n// l1 to l2 messaging\nuse crate::messaging::process_l1_to_l2_message;\nuse crate::private_call_stack_item::PrivateCallStackItem;\nuse crate::public_call_stack_item::PublicCallStackItem;\n\nuse crate::types::{\n vec::BoundedVec,\n point::Point,\n};\n\nuse crate::utils::arr_copy_slice;\n\nuse crate::oracle::{\n arguments,\n call_private_function::call_private_function_internal,\n public_call::call_public_function_internal,\n enqueue_public_function_call::enqueue_public_function_call_internal,\n context::get_portal_address,\n};\n\n\n// When finished, one can call .finish() to convert back to the abi\nstruct PrivateContext {\n inputs: abi::PrivateContextInputs,\n\n args_hash : Field,\n return_values : BoundedVec,\n\n read_requests: BoundedVec,\n\n new_commitments: BoundedVec,\n new_nullifiers: BoundedVec,\n nullified_commitments: BoundedVec,\n\n private_call_stack : BoundedVec,\n public_call_stack : BoundedVec,\n new_l2_to_l1_msgs : BoundedVec,\n\n block_data: HistoricBlockData,\n\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n // encrypted_logs_preimages: Vec,\n // unencrypted_logs_preimages: Vec,\n}\n\nimpl PrivateContext {\n fn new(inputs: abi::PrivateContextInputs, args_hash: Field) -> PrivateContext {\n PrivateContext {\n inputs: inputs,\n\n args_hash: args_hash,\n return_values: BoundedVec::new(0),\n\n read_requests: BoundedVec::new(0),\n\n new_commitments: BoundedVec::new(0),\n new_nullifiers: BoundedVec::new(0),\n nullified_commitments: BoundedVec::new(0),\n\n block_data: inputs.block_data,\n\n private_call_stack: BoundedVec::new(0),\n public_call_stack: BoundedVec::new(0),\n new_l2_to_l1_msgs: BoundedVec::new(0),\n\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n // encrypted_logs_preimages: Vec::new(),\n // unencrypted_logs_preimages: Vec::new(),\n }\n }\n\n fn msg_sender(self) -> Field {\n self.inputs.call_context.msg_sender\n }\n\n fn this_address(self) -> Field {\n self.inputs.call_context.storage_contract_address\n }\n\n fn this_portal_address(self) -> Field {\n self.inputs.call_context.portal_contract_address\n }\n\n fn chain_id(self) -> Field {\n self.inputs.private_global_variables.chain_id\n }\n\n fn version(self) -> Field {\n self.inputs.private_global_variables.version\n }\n\n fn finish(self) -> abi::PrivateCircuitPublicInputs {\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n let encrypted_logs_hash = [0; NUM_FIELDS_PER_SHA256];\n let unencrypted_logs_hash = [0; NUM_FIELDS_PER_SHA256];\n let encrypted_log_preimages_length = 0;\n let unencrypted_log_preimages_length = 0;\n\n let priv_circuit_pub_inputs = abi::PrivateCircuitPublicInputs {\n call_context: self.inputs.call_context,\n args_hash: self.args_hash,\n return_values: self.return_values.storage,\n read_requests: self.read_requests.storage,\n new_commitments: self.new_commitments.storage,\n new_nullifiers: self.new_nullifiers.storage,\n nullified_commitments: self.nullified_commitments.storage,\n private_call_stack: self.private_call_stack.storage,\n public_call_stack: self.public_call_stack.storage,\n new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage,\n encrypted_logs_hash: encrypted_logs_hash,\n unencrypted_logs_hash: unencrypted_logs_hash,\n encrypted_log_preimages_length: encrypted_log_preimages_length,\n unencrypted_log_preimages_length: unencrypted_log_preimages_length,\n block_data: self.block_data,\n contract_deployment_data: self.inputs.contract_deployment_data,\n chain_id: self.inputs.private_global_variables.chain_id,\n version: self.inputs.private_global_variables.version,\n };\n priv_circuit_pub_inputs\n }\n\n fn push_read_request(&mut self, read_request: Field) {\n self.read_requests.push(read_request);\n }\n\n fn push_new_note_hash(&mut self, note_hash: Field) {\n self.new_commitments.push(note_hash);\n }\n\n fn push_new_nullifier(&mut self, nullifier: Field, nullified_commitment: Field) {\n self.new_nullifiers.push(nullifier);\n self.nullified_commitments.push(nullified_commitment);\n }\n\n fn message_portal(&mut self, content: Field) {\n self.new_l2_to_l1_msgs.push(content);\n }\n\n // PrivateContextInputs must be temporarily passed in to prevent too many unknowns\n // Note this returns self to get around an issue where mutable structs do not maintain mutations unless reassigned\n fn consume_l1_to_l2_message(&mut self, inputs: abi::PrivateContextInputs, msg_key: Field, content: Field, secret: Field) {\n let nullifier = process_l1_to_l2_message(inputs.block_data.l1_to_l2_messages_tree_root, inputs.call_context.storage_contract_address, msg_key, content, secret);\n\n // Push nullifier (and the \"commitment\" corresponding to this can be \"empty\")\n self.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT)\n }\n\n fn accumulate_encrypted_logs(&mut self, log: [Field; N]) {\n let _void1 = self.inputs;\n let _void2 = log;\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n }\n\n fn accumulate_unencrypted_logs(&mut self, log: T) {\n let _void1 = self.inputs;\n let _void2 = log;\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n }\n\n fn call_private_function(\n &mut self,\n contract_address: Field, \n function_selector: Field, \n args: [Field; ARGS_COUNT]\n ) -> [Field; RETURN_VALUES_LENGTH] {\n let args_hash = hash_args(args);\n assert(args_hash == arguments::pack_arguments(args));\n self.call_private_function_with_packed_args(contract_address, function_selector, args_hash)\n }\n\n fn call_private_function_no_args(\n &mut self,\n contract_address: Field, \n function_selector: Field, \n ) -> [Field; RETURN_VALUES_LENGTH] {\n self.call_private_function_with_packed_args(contract_address, function_selector, 0)\n }\n\n fn call_private_function_with_packed_args(\n &mut self,\n contract_address: Field,\n function_selector: Field,\n args_hash: Field\n ) -> [Field; RETURN_VALUES_LENGTH] {\n let fields = call_private_function_internal(\n contract_address, \n function_selector, \n args_hash\n );\n let item = PrivateCallStackItem {\n contract_address: fields[0],\n function_data: FunctionData {\n function_selector: fields[1],\n is_internal: fields[2] as bool,\n is_private: fields[3] as bool,\n is_constructor: fields[4] as bool,\n },\n public_inputs: PrivateCircuitPublicInputs {\n call_context: CallContext {\n msg_sender : fields[5],\n storage_contract_address : fields[6],\n portal_contract_address : fields[7],\n \n is_delegate_call : fields[8] as bool,\n is_static_call : fields[9] as bool,\n is_contract_deployment: fields[10] as bool,\n },\n // TODO handle the offsets as a variable incremented during extraction?\n args_hash: fields[11],\n return_values: arr_copy_slice(fields, [0; RETURN_VALUES_LENGTH], 12),\n read_requests: arr_copy_slice(fields, [0; MAX_READ_REQUESTS_PER_CALL], 16),\n new_commitments: arr_copy_slice(fields, [0; MAX_NEW_COMMITMENTS_PER_CALL], 20),\n new_nullifiers: arr_copy_slice(fields, [0; MAX_NEW_NULLIFIERS_PER_CALL], 24),\n nullified_commitments: arr_copy_slice(fields, [0; MAX_NEW_NULLIFIERS_PER_CALL], 28),\n private_call_stack: arr_copy_slice(fields, [0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL], 32),\n public_call_stack: arr_copy_slice(fields, [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], 36),\n new_l2_to_l1_msgs: arr_copy_slice(fields, [0; MAX_NEW_L2_TO_L1_MSGS_PER_CALL], 40),\n encrypted_logs_hash: arr_copy_slice(fields, [0; NUM_FIELDS_PER_SHA256], 42),\n unencrypted_logs_hash: arr_copy_slice(fields, [0; NUM_FIELDS_PER_SHA256], 44),\n encrypted_log_preimages_length: fields[46],\n unencrypted_log_preimages_length: fields[47],\n block_data: HistoricBlockData {\n // Must match order in `private_circuit_public_inputs.hpp`\n private_data_tree_root : fields[48],\n nullifier_tree_root : fields[49],\n contract_tree_root : fields[50],\n l1_to_l2_messages_tree_root : fields[51],\n blocks_tree_root : fields[52],\n public_data_tree_root: fields[53],\n global_variables_hash: fields[54],\n },\n contract_deployment_data: ContractDeploymentData {\n deployer_public_key: Point::new(fields[55], fields[56]),\n constructor_vk_hash : fields[57],\n function_tree_root : fields[58],\n contract_address_salt : fields[59],\n portal_contract_address : fields[60],\n },\n chain_id: fields[61],\n version: fields[62],\n },\n is_execution_request: fields[63] as bool,\n };\n assert(contract_address == item.contract_address);\n assert(function_selector == item.function_data.function_selector);\n\n assert(args_hash == item.public_inputs.args_hash);\n\n assert(item.is_execution_request == false);\n\n // Assert that the call context of the enqueued call generated by the oracle matches our request.\n // We are issuing a regular call which is not delegate, static, or deployment. We also constrain\n // the msg_sender in the nested call to be equal to our address, and the execution context address\n // for the nested call to be equal to the address we actually called.\n assert(item.public_inputs.call_context.is_delegate_call == false);\n assert(item.public_inputs.call_context.is_static_call == false);\n assert(item.public_inputs.call_context.is_contract_deployment == false);\n assert(item.public_inputs.call_context.msg_sender == self.inputs.call_context.storage_contract_address);\n assert(item.public_inputs.call_context.storage_contract_address == contract_address);\n\n self.private_call_stack.push(item.hash());\n\n item.public_inputs.return_values\n }\n\n fn call_public_function(\n &mut self,\n contract_address: Field, \n function_selector: Field, \n args: [Field; ARGS_COUNT]\n ) {\n let args_hash = hash_args(args);\n assert(args_hash == arguments::pack_arguments(args));\n self.call_public_function_with_packed_args(contract_address, function_selector, args_hash)\n }\n\n fn call_public_function_no_args(\n &mut self,\n contract_address: Field, \n function_selector: Field,\n ) {\n self.call_public_function_with_packed_args(contract_address, function_selector, 0)\n }\n\n fn call_public_function_with_packed_args(\n &mut self,\n contract_address: Field,\n function_selector: Field,\n args_hash: Field\n ) {\n let fields = enqueue_public_function_call_internal(\n contract_address, \n function_selector, \n args_hash\n );\n let item = PublicCallStackItem {\n contract_address: fields[0],\n function_data: FunctionData {\n function_selector: fields[1],\n is_internal: fields[2] as bool,\n is_private: fields[3] as bool,\n is_constructor: fields[4] as bool,\n },\n public_inputs: PublicCircuitPublicInputs {\n call_context: CallContext {\n msg_sender : fields[5],\n storage_contract_address : fields[6],\n portal_contract_address : fields[7],\n \n is_delegate_call : fields[8] as bool,\n is_static_call : fields[9] as bool,\n is_contract_deployment: fields[10] as bool,\n },\n args_hash: fields[11],\n return_values: [0; RETURN_VALUES_LENGTH],\n contract_storage_update_requests: [ContractStorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL],\n contract_storage_read: [ContractStorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL],\n public_call_stack: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL],\n new_commitments: [0; MAX_NEW_COMMITMENTS_PER_CALL],\n new_nullifiers: [0; MAX_NEW_NULLIFIERS_PER_CALL],\n new_l2_to_l1_msgs:[0; MAX_NEW_L2_TO_L1_MSGS_PER_CALL],\n unencrypted_logs_hash:[0; NUM_FIELDS_PER_SHA256],\n unencrypted_log_preimages_length: 0,\n block_data: HistoricBlockData::empty(),\n prover_address: 0,\n },\n is_execution_request: true,\n };\n\n assert(contract_address == item.contract_address);\n assert(function_selector == item.function_data.function_selector);\n \n assert(args_hash == item.public_inputs.args_hash);\n\n // Assert that the call context of the enqueued call generated by the oracle matches our request.\n // We are issuing a regular call which is not delegate, static, or deployment. We also constrain\n // the msg_sender in the nested call to be equal to our address, and the execution context address\n // for the nested call to be equal to the address we actually called.\n assert(item.public_inputs.call_context.is_delegate_call == false);\n assert(item.public_inputs.call_context.is_static_call == false);\n assert(item.public_inputs.call_context.is_contract_deployment == false);\n assert(item.public_inputs.call_context.msg_sender == self.inputs.call_context.storage_contract_address);\n assert(item.public_inputs.call_context.storage_contract_address == contract_address);\n\n self.public_call_stack.push(item.hash());\n }\n}\n\nuse crate::abi::{\n ContractStorageRead,\n ContractStorageUpdateRequest\n};\n\nstruct PublicContext {\n inputs: abi::PublicContextInputs,\n\n args_hash : Field,\n return_values : BoundedVec,\n\n contract_storage_update_requests: BoundedVec,\n contract_storage_read: BoundedVec,\n public_call_stack: BoundedVec,\n\n new_commitments: BoundedVec,\n new_nullifiers: BoundedVec,\n\n new_l2_to_l1_msgs: BoundedVec,\n\n unencrypted_logs_hash: BoundedVec,\n unencrypted_logs_preimages_length: Field,\n\n block_data: HistoricBlockData,\n prover_address: Field,\n}\n\nimpl PublicContext {\n fn new(inputs: abi::PublicContextInputs, args_hash: Field) -> PublicContext {\n let empty_storage_read = ContractStorageRead::empty();\n let empty_storage_update = ContractStorageUpdateRequest::empty();\n PublicContext {\n inputs: inputs,\n\n args_hash: args_hash,\n return_values: BoundedVec::new(0),\n\n contract_storage_update_requests: BoundedVec::new(empty_storage_update),\n contract_storage_read: BoundedVec::new(empty_storage_read),\n public_call_stack: BoundedVec::new(0),\n\n new_commitments: BoundedVec::new(0),\n new_nullifiers: BoundedVec::new(0),\n\n new_l2_to_l1_msgs: BoundedVec::new(0),\n\n \n unencrypted_logs_hash: BoundedVec::new(0),\n unencrypted_logs_preimages_length: 0,\n\n block_data: inputs.block_data,\n prover_address: 0,\n\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n // encrypted_logs_preimages: Vec::new(),\n // unencrypted_logs_preimages: Vec::new(),\n }\n }\n\n fn msg_sender(self) -> Field {\n self.inputs.call_context.msg_sender\n }\n\n fn this_address(self) -> Field {\n self.inputs.call_context.storage_contract_address\n }\n\n fn this_portal_address(self) -> Field {\n self.inputs.call_context.portal_contract_address\n }\n\n fn chain_id(self) -> Field {\n self.inputs.public_global_variables.chain_id\n }\n\n fn version(self) -> Field {\n self.inputs.public_global_variables.version\n }\n\n fn block_number(self) -> Field {\n self.inputs.public_global_variables.block_number\n }\n\n fn timestamp(self) -> Field {\n self.inputs.public_global_variables.timestamp\n }\n\n fn finish(self) -> abi::PublicCircuitPublicInputs {\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n let unencrypted_logs_hash = [0; NUM_FIELDS_PER_SHA256];\n let unencrypted_log_preimages_length = 0;\n\n\n // Compute the public call stack hashes\n let pub_circuit_pub_inputs = abi::PublicCircuitPublicInputs {\n call_context: self.inputs.call_context, // Done\n args_hash: self.args_hash, // Done\n contract_storage_update_requests: self.contract_storage_update_requests.storage,\n contract_storage_read: self.contract_storage_read.storage,\n return_values: self.return_values.storage,\n new_commitments: self.new_commitments.storage,\n new_nullifiers: self.new_nullifiers.storage,\n public_call_stack: self.public_call_stack.storage,\n new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage,\n unencrypted_logs_hash: unencrypted_logs_hash,\n unencrypted_log_preimages_length: unencrypted_log_preimages_length,\n block_data: self.inputs.block_data,\n prover_address: self.prover_address,\n };\n pub_circuit_pub_inputs\n }\n\n fn push_new_note_hash(&mut self, note_hash: Field) {\n self.new_commitments.push(note_hash);\n }\n\n fn push_new_nullifier(&mut self, nullifier: Field, _nullified_commitment: Field) {\n self.new_nullifiers.push(nullifier);\n }\n\n fn message_portal(&mut self, content: Field) {\n self.new_l2_to_l1_msgs.push(content);\n }\n\n // PrivateContextInputs must be temporarily passed in to prevent too many unknowns\n // Note this returns self to get around an issue where mutable structs do not maintain mutations unless reassigned\n fn consume_l1_to_l2_message(&mut self, msg_key: Field, content: Field, secret: Field) {\n let this = (*self).this_address();\n let nullifier = process_l1_to_l2_message(self.block_data.l1_to_l2_messages_tree_root, this, msg_key, content, secret);\n\n // Push nullifier (and the \"commitment\" corresponding to this can be \"empty\")\n self.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT)\n }\n\n fn accumulate_encrypted_logs(&mut self, log: [Field; N]) {\n let _void1 = self;\n let _void2 = log;\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n }\n\n fn accumulate_unencrypted_logs(&mut self, log: T) {\n let _void1 = self;\n let _void2 = log;\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n }\n\n fn call_public_function(\n _self: Self,\n contract_address: Field, \n function_selector: Field,\n args: [Field; ARGS_COUNT],\n ) -> [Field; RETURN_VALUES_LENGTH] {\n let args_hash = abi::hash_args(args);\n assert(args_hash == arguments::pack_arguments(args));\n call_public_function_internal(\n contract_address, \n function_selector, \n args_hash,\n )\n }\n\n fn call_public_function_no_args(\n _self: Self,\n contract_address: Field, \n function_selector: Field,\n ) -> [Field; RETURN_VALUES_LENGTH] {\n call_public_function_internal(\n contract_address, \n function_selector, \n 0,\n )\n }\n\n}", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/context" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/context" }, "33": { "source": "use crate::context::PrivateContext;\nuse crate::oracle;\nuse crate::types::point::Point;\n\nfn emit_encrypted_log(\n context: &mut PrivateContext,\n contract_address: Field,\n storage_slot: Field,\n encryption_pub_key: Point,\n log: [Field; N],\n) {\n let _ = oracle::logs::emit_encrypted_log(contract_address, storage_slot, encryption_pub_key, log);\n context.accumulate_encrypted_logs(log);\n}\n\nfn emit_unencrypted_log(\n context: &mut PrivateContext,\n log: T,\n) {\n let _ = oracle::logs::emit_unencrypted_log(log);\n context.accumulate_unencrypted_logs(log);\n}\n", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/log" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/log" }, "39": { "source": "use dep::std::option::Option;\nuse crate::abi::PublicContextInputs;\nuse crate::context::{\n PrivateContext,\n PublicContext,\n};\nuse crate::note::{\n note_header::NoteHeader,\n note_interface::NoteInterface,\n utils::compute_inner_note_hash,\n};\nuse crate::oracle::notes::{notify_created_note, notify_nullified_note};\nuse crate::constants_gen::EMPTY_NULLIFIED_COMMITMENT;\n\nfn create_note(\n context: &mut PrivateContext,\n storage_slot: Field,\n note: &mut Note,\n note_interface: NoteInterface,\n) {\n let contract_address = (*context).this_address();\n\n let header = NoteHeader { contract_address, storage_slot, nonce: 0 };\n let set_header = note_interface.set_header;\n set_header(note, header);\n let inner_note_hash = compute_inner_note_hash(note_interface, *note);\n\n let serialise = note_interface.serialise;\n let preimage = serialise(*note);\n assert(notify_created_note(storage_slot, preimage, inner_note_hash) == 0);\n\n context.push_new_note_hash(inner_note_hash);\n}\n\nfn create_note_hash_from_public(\n context: &mut PublicContext,\n storage_slot: Field,\n note: &mut Note,\n note_interface: NoteInterface,\n) {\n let contract_address = (*context).this_address();\n\n let header = NoteHeader { contract_address, storage_slot, nonce: 0 };\n let set_header = note_interface.set_header;\n set_header(note, header);\n let inner_note_hash = compute_inner_note_hash(note_interface, *note);\n\n context.push_new_note_hash(inner_note_hash);\n}\n\nfn destroy_note(\n context: &mut PrivateContext,\n storage_slot: Field,\n note: Note,\n note_interface: NoteInterface,\n) {\n let mut nullifier = 0;\n let mut nullified_commitment: Field = EMPTY_NULLIFIED_COMMITMENT;\n let compute_nullifier = note_interface.compute_nullifier;\n nullifier = compute_nullifier(note);\n\n let serialise = note_interface.serialise;\n let preimage = serialise(note);\n\n // We also need the note commitment corresponding to the \"nullifier\"\n let get_header = note_interface.get_header;\n let header = get_header(note);\n // 0 nonce implies \"transient\" nullifier (must nullify a commitment in this TX).\n // `nullified_commitment` is used to inform the kernel which pending commitment\n // the nullifier corresponds to so they can be matched and both squashed/deleted.\n // nonzero nonce implies \"persistable\" nullifier (nullifies a persistent/in-tree\n // commitment) in which case `nullified_commitment` is not used since the kernel\n // just siloes and forwards the nullier to its output.\n if (header.nonce == 0) {\n // TODO(suyash): Can we reuse the note commitment computed in `compute_nullifier`?\n nullified_commitment = compute_inner_note_hash(note_interface, note);\n }\n assert(notify_nullified_note(storage_slot, nullifier, preimage, nullified_commitment) == 0);\n\n context.push_new_nullifier(nullifier, nullified_commitment)\n}", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/note/lifecycle" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/note/lifecycle" }, "40": { "source": "use dep::std::option::Option;\nuse crate::constants_gen::{\n MAX_READ_REQUESTS_PER_CALL,\n GET_NOTE_ORACLE_RETURN_LENGTH,\n GET_NOTES_ORACLE_RETURN_LENGTH,\n MAX_NOTES_PER_PAGE,\n VIEW_NOTE_ORACLE_RETURN_LENGTH,\n};\nuse crate::context::PrivateContext;\nuse crate::note::{\n note_getter_options::{NoteGetterOptions, Select, Sort},\n note_interface::NoteInterface,\n note_header::NoteHeader,\n note_viewer_options::NoteViewerOptions,\n utils::compute_note_hash_for_read_or_nullify,\n utils::compute_unique_siloed_note_hash,\n utils::compute_inner_note_hash,\n utils::compute_siloed_note_hash,\n};\nuse crate::messaging::get_commitment_getter_data::make_commitment_getter_data;\nuse crate::oracle;\nuse crate::types::vec::BoundedVec;\n\nfn check_note_header(\n context: PrivateContext,\n storage_slot: Field,\n note_interface: NoteInterface,\n note: Note,\n) {\n let get_header = note_interface.get_header;\n let header = get_header(note);\n let contract_address = context.this_address();\n assert(header.contract_address == contract_address);\n assert(header.storage_slot == storage_slot);\n}\n\nfn ensure_note_exists(\n context: &mut PrivateContext,\n storage_slot: Field,\n note_interface: NoteInterface,\n note: &mut Note,\n) {\n let saved_note = get_note_internal(storage_slot, note_interface);\n\n // Only copy over the header to the original note to make sure the preimage is the same.\n let get_header = note_interface.get_header;\n let set_header = note_interface.set_header;\n let note_header = get_header(saved_note);\n set_header(note, note_header);\n\n check_note_header(*context, storage_slot, note_interface, *note);\n\n let note_hash_for_read_request = compute_note_hash_for_read_or_nullify(note_interface, *note);\n context.push_read_request(note_hash_for_read_request);\n}\n\n// Ensure a note's hash exists in the tree without retrieving the entire\n// notes via the oracle.\n// Modifies the note by populating it with header info.\nfn ensure_note_hash_exists(\n context: &mut PrivateContext,\n storage_slot: Field,\n note_interface: NoteInterface,\n note: &mut Note,\n) {\n // Initialize header of note. Must be done before computing note hashes as it initializes the:\n // - storage slot (used in inner note hash)\n // - the contract address (used in siloed note hash)\n // - and the nonce (used in the unique siloed note hash)\n let set_header = note_interface.set_header;\n let note_header = NoteHeader {\n contract_address: (*context).this_address(),\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): should be\n // real nonce (once public kernel applies nonces).\n nonce: 0,\n storage_slot\n };\n set_header(note, note_header);\n\n // Get a note from oracle and early out if it doesn't exist.\n let inner_note_hash = compute_inner_note_hash(note_interface, *note);\n\n let raw_oracle_ret = oracle::get_commitment::get_commitment(inner_note_hash);\n let deserialized_oracle_ret = make_commitment_getter_data(raw_oracle_ret, 0);\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): should be\n // unique_siloed_note_hash once public kernel applies nonces\n let saved_siloed_note_hash = deserialized_oracle_ret.message;\n\n assert(saved_siloed_note_hash != 0); // TODO(dbanks12): necessary?\n\n check_note_header(*context, storage_slot, note_interface, *note);\n\n // Ensure that the note hash retrieved from oracle matches the one computed from note.\n let computed_siloed_note_hash = compute_siloed_note_hash(note_interface, *note);\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): should be\n // compute_note_hash_for_read_or_nullify once public kernel applies nonces\n assert(computed_siloed_note_hash == saved_siloed_note_hash);\n\n context.push_read_request(computed_siloed_note_hash);\n}\n\nfn get_note(\n context: &mut PrivateContext,\n storage_slot: Field,\n note_interface: NoteInterface,\n) -> Note {\n let note = get_note_internal(storage_slot, note_interface);\n\n check_note_header(*context, storage_slot, note_interface, note);\n\n let note_hash_for_read_request = compute_note_hash_for_read_or_nullify(note_interface, note);\n\n context.push_read_request(note_hash_for_read_request);\n note\n}\n\nfn get_notes(\n context: &mut PrivateContext,\n storage_slot: Field,\n note_interface: NoteInterface,\n options: NoteGetterOptions,\n) -> [Option; MAX_READ_REQUESTS_PER_CALL] {\n let opt_notes = get_notes_internal(storage_slot, note_interface, options);\n for i in 0..opt_notes.len() {\n let opt_note = opt_notes[i];\n let mut note_hash_for_read_request = 0;\n if opt_note.is_some() {\n let note = opt_note.unwrap_unchecked();\n check_note_header(*context, storage_slot, note_interface, note);\n note_hash_for_read_request = compute_note_hash_for_read_or_nullify(note_interface, note);\n };\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1410): test to ensure\n // failure if malicious oracle injects 0 nonce here for a \"pre-existing\" note.\n context.push_read_request(note_hash_for_read_request);\n };\n\n // TODO(#1660)\n // Move it back to get_notes_internal and only make read request for selected notes.\n let filter = options.filter;\n let filter_args = options.filter_args;\n filter(opt_notes, filter_args)\n}\n\nunconstrained fn get_note_internal(\n storage_slot: Field,\n note_interface: NoteInterface,\n) -> Note {\n let placeholder_note = [Option::none()];\n let placeholder_fields = [0; GET_NOTE_ORACLE_RETURN_LENGTH];\n oracle::notes::get_notes(\n storage_slot,\n note_interface,\n 0,\n [],\n [],\n [],\n [],\n 1, // limit\n 0, // offset\n placeholder_note,\n placeholder_fields,\n )[0].unwrap() // Notice: we don't allow dummies to be returned from get_note (singular).\n}\n\nunconstrained fn get_notes_internal(\n storage_slot: Field,\n note_interface: NoteInterface,\n options: NoteGetterOptions,\n) -> [Option; MAX_READ_REQUESTS_PER_CALL] {\n let (num_selects, select_by, select_values, sort_by, sort_order) = flatten_options(options.selects, options.sorts);\n let placeholder_opt_notes = [Option::none(); MAX_READ_REQUESTS_PER_CALL];\n let placeholder_fields = [0; GET_NOTES_ORACLE_RETURN_LENGTH];\n oracle::notes::get_notes(\n storage_slot,\n note_interface,\n num_selects,\n select_by,\n select_values,\n sort_by,\n sort_order,\n options.limit,\n options.offset,\n placeholder_opt_notes,\n placeholder_fields,\n )\n}\n\nunconstrained fn view_notes(\n storage_slot: Field,\n note_interface: NoteInterface,\n options: NoteViewerOptions,\n) -> [Option; MAX_NOTES_PER_PAGE] {\n let (num_selects, select_by, select_values, sort_by, sort_order) = flatten_options(options.selects, options.sorts);\n let placeholder_opt_notes = [Option::none(); MAX_NOTES_PER_PAGE];\n let placeholder_fields = [0; VIEW_NOTE_ORACLE_RETURN_LENGTH];\n oracle::notes::get_notes(\n storage_slot,\n note_interface,\n num_selects,\n select_by,\n select_values,\n sort_by,\n sort_order,\n options.limit,\n options.offset,\n placeholder_opt_notes,\n placeholder_fields,\n )\n}\n\nunconstrained fn flatten_options(\n selects: BoundedVec, N>,\n sorts: BoundedVec, N>,\n) -> (u8, [u8; N], [Field; N], [u8; N], [u2; N]) {\n let mut num_selects = 0;\n let mut select_by = [0; N];\n let mut select_values = [0; N];\n for i in 0..selects.len {\n let select = selects.get(i);\n if select.is_some() {\n select_by[num_selects] = select.unwrap_unchecked().field_index;\n select_values[num_selects] = select.unwrap_unchecked().value;\n num_selects += 1;\n };\n };\n\n let mut sort_by = [0; N];\n let mut sort_order = [0; N];\n for i in 0..sorts.len {\n let sort = sorts.get(i);\n if sort.is_some() {\n sort_by[i] = sort.unwrap_unchecked().field_index;\n sort_order[i] = sort.unwrap_unchecked().order;\n };\n };\n\n (num_selects, select_by, select_values, sort_by, sort_order)\n}", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/note/note_getter" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/note/note_getter" }, "42": { "source": "use dep::std::hash::{pedersen, pedersen_with_separator};\nuse crate::constants_gen::{GENERATOR_INDEX__UNIQUE_COMMITMENT, GENERATOR_INDEX__SILOED_COMMITMENT};\n\nfn compute_inner_hash(storage_slot: Field, note_hash: Field) -> Field {\n // TODO(#1205) Do we need a generator index here?\n pedersen([storage_slot, note_hash])[0]\n}\n\nfn compute_siloed_hash(contract_address: Field, inner_note_hash: Field) -> Field {\n let inputs = [contract_address, inner_note_hash];\n pedersen_with_separator(inputs, GENERATOR_INDEX__SILOED_COMMITMENT)[0]\n}\n\nfn compute_unique_hash(nonce: Field, siloed_note_hash: Field) -> Field {\n let inputs = [nonce, siloed_note_hash];\n pedersen_with_separator(inputs, GENERATOR_INDEX__UNIQUE_COMMITMENT)[0]\n}\n", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/note/note_hash" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/note/note_hash" }, "46": { "source": "use crate::note::{\n note_hash::{compute_inner_hash, compute_siloed_hash, compute_unique_hash},\n note_header::NoteHeader,\n note_interface::NoteInterface,\n};\nuse crate::utils::arr_copy_slice;\n\nfn compute_inner_note_hash(\n note_interface: NoteInterface,\n note: Note,\n) -> Field {\n let get_header = note_interface.get_header;\n let header = get_header(note);\n\n let compute_note_hash = note_interface.compute_note_hash;\n let note_hash = compute_note_hash(note);\n\n compute_inner_hash(header.storage_slot, note_hash)\n}\n\nfn compute_siloed_note_hash(\n note_interface: NoteInterface,\n note_with_header: Note,\n) -> Field {\n let get_header = note_interface.get_header;\n let header = get_header(note_with_header);\n\n let inner_note_hash = compute_inner_note_hash(note_interface, note_with_header);\n\n compute_siloed_hash(header.contract_address, inner_note_hash)\n}\n\nfn compute_unique_siloed_note_hash(\n note_interface: NoteInterface,\n note_with_header: Note,\n) -> Field {\n let get_header = note_interface.get_header;\n let header = get_header(note_with_header);\n\n let siloed_note_hash = compute_siloed_note_hash(note_interface, note_with_header);\n\n compute_unique_hash(header.nonce, siloed_note_hash)\n}\n\nfn compute_note_hash_for_read_or_nullify(\n note_interface: NoteInterface,\n note_with_header: Note,\n) -> Field {\n let get_header = note_interface.get_header;\n let header = get_header(note_with_header);\n\n if (header.nonce == 0) {\n // when nonce is zero, that means we are reading a pending note (doesn't have a nonce yet),\n // so we just read the inner_note_hash (kernel will silo by contract address)\n compute_inner_note_hash(note_interface, note_with_header)\n } else {\n // When nonce is nonzero, that means we are reading a settled note (from tree) created in a\n // previous TX. So we need the unique_siloed_note_hash which has already been hashed with\n // contract address and then nonce. This hash will match the existing leaf in the private\n // data tree, so the kernel can just perform a membership check directly on this hash/leaf.\n compute_unique_siloed_note_hash(note_interface, note_with_header)\n }\n\n}\n\nfn compute_note_hash_and_nullifier(\n note_interface: NoteInterface,\n note_header: NoteHeader,\n preimage: [Field; S],\n) -> [Field; 4] {\n let deserialise = note_interface.deserialise;\n let set_header = note_interface.set_header;\n let mut note = deserialise(arr_copy_slice(preimage, [0; N], 0));\n set_header(&mut note, note_header);\n\n let compute_note_hash = note_interface.compute_note_hash;\n let note_hash = compute_note_hash(note);\n let inner_note_hash = compute_inner_hash(note_header.storage_slot, note_hash);\n\n let siloed_note_hash = compute_siloed_hash(note_header.contract_address, inner_note_hash);\n\n let unique_siloed_note_hash = compute_unique_hash(note_header.nonce, siloed_note_hash);\n\n let compute_nullifier = note_interface.compute_nullifier;\n let inner_nullifier = compute_nullifier(note);\n\n [inner_note_hash, siloed_note_hash, unique_siloed_note_hash, inner_nullifier]\n}\n", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/note/utils" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/note/utils" }, "48": { "source": "use dep::std::hash::pedersen_with_separator;\nuse crate::context::PrivateContext;\nuse crate::note::{\n lifecycle::create_note,\n note_getter::{get_note, view_notes},\n note_interface::NoteInterface,\n note_viewer_options::NoteViewerOptions,\n};\nuse crate::oracle;\nuse crate::constants_gen::{\n GENERATOR_INDEX__INITIALISATION_NULLIFIER,\n EMPTY_NULLIFIED_COMMITMENT,\n};\n\nstruct ImmutableSingleton {\n storage_slot: Field,\n note_interface: NoteInterface,\n}\n\nimpl ImmutableSingleton {\n fn new(storage_slot: Field, note_interface: NoteInterface) -> Self {\n ImmutableSingleton { storage_slot, note_interface }\n }\n\n unconstrained fn is_initialised(self) -> bool {\n let nullifier = self.compute_initialisation_nullifier();\n oracle::notes::is_nullifier_emitted(nullifier)\n }\n\n fn initialise(self, context: &mut PrivateContext, note: &mut Note) {\n // Nullify the storage slot.\n let nullifier = self.compute_initialisation_nullifier();\n context.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT);\n\n create_note(context, self.storage_slot, note, self.note_interface);\n }\n\n fn compute_initialisation_nullifier(self) -> Field {\n pedersen_with_separator([self.storage_slot], GENERATOR_INDEX__INITIALISATION_NULLIFIER)[0]\n }\n \n fn get_note(self, context: &mut PrivateContext) -> Note {\n let storage_slot = self.storage_slot;\n get_note(context, storage_slot, self.note_interface)\n }\n\n unconstrained fn view_note(self) -> Note {\n let options = NoteViewerOptions::new().set_limit(1);\n view_notes(self.storage_slot, self.note_interface, options)[0].unwrap()\n }\n}", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/state_vars/immutable_singleton" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/state_vars/immutable_singleton" }, "55": { "source": "\nstruct BoundedVec {\n storage: [T; MaxLen],\n len: Field,\n}\n\nimpl BoundedVec {\n fn new(initial_value: T) -> Self {\n BoundedVec { storage: [initial_value; MaxLen], len: 0 }\n }\n\n fn get(mut self: Self, index: Field) -> T {\n assert(index as u64 < self.len as u64);\n self.storage[index]\n }\n\n fn push(&mut self, elem: T) {\n assert(self.len as u64 < MaxLen as u64);\n\n self.storage[self.len] = elem;\n self.len += 1;\n }\n\n fn push_array(&mut self, array: [T; Len]) {\n let newLen = self.len + array.len();\n assert(newLen as u64 <= MaxLen as u64);\n for i in 0..array.len() {\n self.storage[self.len + i] = array[i];\n }\n self.len = newLen;\n }\n\n fn pop(&mut self) -> T {\n assert(self.len as u64 > 0);\n\n let elem = self.storage[self.len - 1];\n self.len -= 1;\n elem\n }\n}\n\n// #[test]\n// fn test_vec() {\n// let vec: BoundedVec = BoundedVec::new(0);\n// assert(vec.len == 0);\n// let vec1 = vec.push(1);\n// assert(vec1.len == 1);\n// let vec2 = vec1.push(1);\n// assert(vec2.len == 2);\n// let vec3 = vec2.push(1);\n// assert(vec3.len == 3);\n// let x = vec3.pop();\n// assert(x == 1);\n// }", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/types/vec" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/types/vec" }, "70": { "source": "use crate::types::point::Point;\nuse dep::std::hash;\nuse crate::constants_gen::GENERATOR_INDEX__CONTRACT_ADDRESS;\n\n#[oracle(getPublicKey)]\nfn get_public_key_oracle(_address: Field) -> [Field; 3] {}\n\nunconstrained fn get_public_key_internal(address: Field) -> [Field; 3] {\n get_public_key_oracle(address)\n}\n\nfn get_public_key(address: Field) -> Point {\n let result = get_public_key_internal(address);\n let pub_key_x = result[0];\n let pub_key_y = result[1];\n let partial_address = result[2];\n \n let calculated_address = hash::pedersen_with_separator([pub_key_x, pub_key_y, partial_address], GENERATOR_INDEX__CONTRACT_ADDRESS)[0];\n assert(calculated_address == address);\n \n Point::new(pub_key_x, pub_key_y)\n}\n", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/oracle/get_public_key" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/oracle/get_public_key" }, "78": { "source": "use crate::abi;\nuse crate::types::vec::BoundedVec;\nuse crate::context::PrivateContext;\nuse crate::private_call_stack_item::PrivateCallStackItem;\nuse crate::public_call_stack_item::PublicCallStackItem; \n\nglobal ACCOUNT_MAX_PRIVATE_CALLS: Field = 2;\nglobal ACCOUNT_MAX_PUBLIC_CALLS: Field = 2;\nglobal ACCOUNT_MAX_CALLS: Field = 4;\n// 1 (ARGS_HASH) + 1 (FUNCTION_SELECTOR) + 1 (TARGET_ADDRESS)\nglobal FUNCTION_CALL_SIZE: Field = 3;\n\nstruct FunctionCall {\n args_hash: Field,\n function_selector: Field,\n target_address: Field,\n}\n\nimpl FunctionCall {\n fn serialize(self) -> [Field; FUNCTION_CALL_SIZE] {\n [self.args_hash, self.function_selector, self.target_address]\n }\n}\n\n// FUNCTION_CALL_SIZE * (ACCOUNT_MAX_PUBLIC_CALLS + ACCOUNT_MAX_PRIVATE_CALLS) + 1\nglobal ENTRYPOINT_PAYLOAD_SIZE: Field = 13;\nglobal ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES: Field = 416;\n\nstruct EntrypointPayload {\n // Noir doesnt support nested arrays or structs yet so we flatten everything\n flattened_args_hashes: [Field; ACCOUNT_MAX_CALLS],\n flattened_selectors: [Field; ACCOUNT_MAX_CALLS],\n flattened_targets: [Field; ACCOUNT_MAX_CALLS],\n nonce: Field,\n}\n\nimpl EntrypointPayload {\n // TODO(#1207) Do we need a generator index?\n fn hash(self) -> Field {\n dep::std::hash::pedersen(self.serialize())[0]\n }\n\n // Serializes the entrypoint struct\n fn serialize(self) -> [Field; ENTRYPOINT_PAYLOAD_SIZE] {\n let mut fields: BoundedVec = BoundedVec::new(0); \n fields.push_array(self.flattened_args_hashes);\n fields.push_array(self.flattened_selectors);\n fields.push_array(self.flattened_targets);\n fields.push(self.nonce);\n fields.storage\n }\n\n // Serializes the payload as an array of bytes. Useful for hashing with sha256.\n fn to_be_bytes(self) -> [u8; ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES] {\n let mut bytes: [u8; ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES] = [0; ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES];\n\n let args_len = self.flattened_args_hashes.len();\n let selectors_len = self.flattened_selectors.len();\n let targets_len = self.flattened_targets.len();\n\n for i in 0..args_len {\n let item_bytes = self.flattened_args_hashes[i].to_be_bytes(32);\n for j in 0..32 { \n bytes[i * 32 + j] = item_bytes[j];\n }\n }\n\n for i in 0..selectors_len {\n let item_bytes = self.flattened_selectors[i].to_be_bytes(32);\n for j in 0..32 { \n bytes[args_len * 32 + i * 32 + j] = item_bytes[j];\n }\n }\n\n for i in 0..targets_len {\n let item_bytes = self.flattened_targets[i].to_be_bytes(32);\n for j in 0..32 { \n bytes[(args_len + selectors_len) * 32 + i * 32 + j] = item_bytes[j];\n }\n }\n \n let item_bytes = self.nonce.to_be_bytes(32);\n for j in 0..32 { \n bytes[(args_len + selectors_len + targets_len) * 32 + j] = item_bytes[j];\n }\n\n bytes\n }\n\n // Executes all private and public calls \n fn execute_calls(self, context: &mut PrivateContext) {\n for i in 0..ACCOUNT_MAX_PRIVATE_CALLS {\n let target_address = self.flattened_targets[i];\n if target_address != 0 {\n let function_selector = self.flattened_selectors[i];\n let args_hash = self.flattened_args_hashes[i];\n let _callStackItem = context.call_private_function_with_packed_args(target_address, function_selector, args_hash);\n }\n }\n for i in ACCOUNT_MAX_PRIVATE_CALLS..ACCOUNT_MAX_CALLS {\n let target_address = self.flattened_targets[i];\n if target_address != 0 {\n let function_selector = self.flattened_selectors[i];\n let args_hash = self.flattened_args_hashes[i];\n let _callStackItem = context.call_public_function_with_packed_args(target_address, function_selector, args_hash);\n }\n }\n }\n}", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/entrypoint" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/entrypoint" } } } diff --git a/yarn-project/aztec.js/src/abis/schnorr_single_key_account_contract.json b/yarn-project/aztec.js/src/abis/schnorr_single_key_account_contract.json index 583099042825..5da5dcb1dec5 100644 --- a/yarn-project/aztec.js/src/abis/schnorr_single_key_account_contract.json +++ b/yarn-project/aztec.js/src/abis/schnorr_single_key_account_contract.json @@ -108,7 +108,7 @@ "fileMap": { "0": { "source": "// Account contract that uses Schnorr signatures for authentication. The signing key is the same as the\n// encryption key, and as such is not stored in the contract but part of the address preimage, so it can\n// be verified by passing in the partial address.\ncontract SchnorrSingleKeyAccount {\n use dep::std;\n use dep::aztec::entrypoint;\n use dep::aztec::entrypoint::EntrypointPayload;\n use dep::aztec::abi;\n use dep::aztec::abi::PrivateContextInputs;\n use dep::aztec::abi::CallContext;\n use dep::aztec::private_call_stack_item::PrivateCallStackItem;\n use dep::aztec::public_call_stack_item::PublicCallStackItem;\n use dep::aztec::context::PrivateContext;\n use dep::aztec::types::vec::BoundedVec;\n use dep::aztec::types::point::Point;\n use dep::aztec::constants_gen::GENERATOR_INDEX__CONTRACT_ADDRESS;\n use dep::aztec::constants_gen::GENERATOR_INDEX__SIGNATURE_PAYLOAD;\n\n fn entrypoint(\n inputs: pub PrivateContextInputs,\n payload: pub EntrypointPayload, // contains a set of arguments, selectors, targets and a nonce\n owner: pub [u8;64], // pubkey x and y coordinates concatenated\n signature: pub [u8;64], // schnorr signature of the payload hash\n partial_address: pub Field,\n ) -> distinct pub abi::PrivateCircuitPublicInputs {\n // Initialize context\n // ENTRYPOINT_PAYLOAD_SIZE(13) + 64 + 64 + 1\n let mut args: BoundedVec = BoundedVec::new(0);\n args.push_array(payload.serialize());\n for byte in owner { args.push(byte as Field); }\n for byte in signature { args.push(byte as Field); }\n args.push(partial_address);\n let mut context = PrivateContext::new(inputs, abi::hash_args(args.storage));\n\n // Verify payload signature\n let payload_fields: [Field; entrypoint::ENTRYPOINT_PAYLOAD_SIZE] = payload.serialize();\n let message_field: Field = std::hash::pedersen_with_separator(payload_fields, GENERATOR_INDEX__SIGNATURE_PAYLOAD)[0];\n let message_bytes = message_field.to_be_bytes(32);\n\n // Convert owner pubkey into fields\n let mut x: Field = 0;\n let mut y: Field = 0;\n let mut mul: Field = 1;\n for i in 0..32 {\n let bytex: Field = owner[31 - i] as Field;\n x = x + (bytex * mul);\n let bytey: Field = owner[63 - i] as Field;\n y = y + (bytey * mul);\n mul *= 256;\n }\n \n // Verify signature of the payload hash\n // TODO: Find out why this signature verification never fails\n let verification = std::schnorr::verify_signature(x, y, signature, message_bytes);\n assert(verification == true);\n\n // Verify public key against address\n let reproduced_address = dep::std::hash::pedersen_with_separator([x, y, partial_address], GENERATOR_INDEX__CONTRACT_ADDRESS)[0];\n assert(reproduced_address == context.this_address());\n\n // Execute calls\n payload.execute_calls(&mut context);\n\n context.finish()\n }\n\n // Constructs the contract\n fn constructor(\n inputs: pub PrivateContextInputs,\n ) -> distinct pub abi::PrivateCircuitPublicInputs {\n // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.\n PrivateContext::new(inputs, 0).finish()\n }\n}\n", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/main" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/main" }, "18": { "source": "\nimpl Field {\n #[builtin(to_le_bits)]\n fn to_le_bits(_x : Field, _bit_size: u32) -> [u1] {}\n #[builtin(to_be_bits)]\n fn to_be_bits(_x : Field, _bit_size: u32) -> [u1] {}\n\n fn to_le_bytes(x : Field, byte_size: u32) -> [u8] {\n x.to_le_radix(256, byte_size)\n }\n fn to_be_bytes(x : Field, byte_size: u32) -> [u8] {\n x.to_be_radix(256, byte_size)\n }\n\n #[builtin(to_le_radix)]\n //decompose _x into a _result_len vector over the _radix basis\n //_radix must be less than 256\n fn to_le_radix(_x : Field, _radix: u32, _result_len: u32) -> [u8] {}\n #[builtin(to_be_radix)]\n fn to_be_radix(_x : Field, _radix: u32, _result_len: u32) -> [u8] {}\n\n // Returns self to the power of the given exponent value.\n // Caution: we assume the exponent fits into 32 bits\n // using a bigger bit size impacts negatively the performance and should be done only if the exponent does not fit in 32 bits\n fn pow_32(self, exponent: Field) -> Field {\n let mut r: Field = 1;\n let b = exponent.to_le_bits(32);\n\n for i in 1..33 {\n r *= r;\n r = (b[32-i] as Field) * (r * self) + (1 - b[32-i] as Field) * r;\n }\n r\n }\n\n // Parity of (prime) Field element, i.e. sgn0(x mod p) = 0 if x ∈ {0, ..., p-1} is even, otherwise sgn0(x mod p) = 1.\n fn sgn0(self) -> u1 {\n self as u1\n }\n}\n\n#[builtin(modulus_num_bits)]\nfn modulus_num_bits() -> Field {}\n\n#[builtin(modulus_be_bits)]\nfn modulus_be_bits() -> [u1] {}\n\n#[builtin(modulus_le_bits)]\nfn modulus_le_bits() -> [u1] {}\n\n#[builtin(modulus_be_bytes)]\nfn modulus_be_bytes() -> [u8] {}\n\n#[builtin(modulus_le_bytes)]\nfn modulus_le_bytes() -> [u8] {}\n", @@ -116,23 +116,23 @@ }, "31": { "source": "use crate::constants_gen::{\n RETURN_VALUES_LENGTH,\n MAX_READ_REQUESTS_PER_CALL,\n MAX_NEW_COMMITMENTS_PER_CALL,\n MAX_NEW_NULLIFIERS_PER_CALL,\n MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL,\n MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,\n MAX_NEW_L2_TO_L1_MSGS_PER_CALL,\n NUM_FIELDS_PER_SHA256,\n MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,\n MAX_PUBLIC_DATA_READS_PER_CALL,\n GENERATOR_INDEX__FUNCTION_ARGS,\n HISTORIC_BLOCK_DATA_LENGTH,\n CONTRACT_DEPLOYMENT_DATA_LENGTH,\n CALL_CONTEXT_LENGTH,\n PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH,\n PRIVATE_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH,\n CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH,\n CONTRACT_STORAGE_READ_LENGTH,\n PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH,\n PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH,\n GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS,\n GENERATOR_INDEX__FUNCTION_DATA,\n GENERATOR_INDEX__PUBLIC_DATA_READ,\n GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST,\n GENERATOR_INDEX__CALL_CONTEXT,\n GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS,\n GENERATOR_INDEX__CONTRACT_DEPLOYMENT_DATA,\n};\n\nuse crate::oracle::debug_log;\nuse crate::types::vec::BoundedVec;\nuse crate::types::point::Point;\n\nstruct PrivateGlobalVariables {\n chain_id: Field,\n version: Field,\n}\n\nimpl PrivateGlobalVariables {\n fn serialize(self) -> [Field; 2] {\n [self.chain_id, self.version]\n }\n}\n\nstruct PublicGlobalVariables {\n chain_id: Field,\n version: Field,\n block_number: Field,\n timestamp: Field,\n}\n\nimpl PublicGlobalVariables {\n fn serialize(self) -> [Field; 4] {\n [self.chain_id, self.version, self.block_number, self.timestamp]\n }\n}\n\nstruct ContractDeploymentData {\n deployer_public_key: Point,\n constructor_vk_hash : Field,\n function_tree_root : Field,\n contract_address_salt : Field,\n portal_contract_address : Field,\n}\n\nimpl ContractDeploymentData {\n fn serialize(self) -> [Field; CONTRACT_DEPLOYMENT_DATA_LENGTH] {\n [\n self.deployer_public_key.x,\n self.deployer_public_key.y,\n self.constructor_vk_hash,\n self.function_tree_root,\n self.contract_address_salt,\n self.portal_contract_address,\n ]\n }\n\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__CONTRACT_DEPLOYMENT_DATA)[0]\n }\n}\n\n// PrivateContextInputs are expected to be provided to each private function\nstruct PrivateContextInputs {\n call_context : CallContext,\n block_data: HistoricBlockData,\n\n contract_deployment_data: ContractDeploymentData,\n\n private_global_variables: PrivateGlobalVariables,\n}\n\n// PublicContextInputs are expected to be provided to each public function\nstruct PublicContextInputs {\n call_context: CallContext,\n block_data: HistoricBlockData,\n\n public_global_variables: PublicGlobalVariables,\n}\n\nstruct CallContext {\n msg_sender : Field,\n storage_contract_address : Field,\n portal_contract_address : Field,\n\n is_delegate_call : bool,\n is_static_call : bool,\n is_contract_deployment: bool,\n}\n\nimpl CallContext {\n fn serialize(self) -> [Field; CALL_CONTEXT_LENGTH] {\n [\n self.msg_sender,\n self.storage_contract_address,\n self.portal_contract_address,\n self.is_delegate_call as Field,\n self.is_static_call as Field,\n self.is_contract_deployment as Field,\n ]\n }\n\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__CALL_CONTEXT)[0]\n }\n}\n\nstruct HistoricBlockData {\n private_data_tree_root : Field,\n nullifier_tree_root : Field,\n contract_tree_root : Field,\n l1_to_l2_messages_tree_root : Field,\n blocks_tree_root: Field,\n public_data_tree_root: Field,\n global_variables_hash: Field,\n}\n\nimpl HistoricBlockData {\n // NOTE: this order must match the order in `private_circuit_public_inputs.hpp`\n fn serialize(self) -> [Field; HISTORIC_BLOCK_DATA_LENGTH] {\n [\n self.private_data_tree_root,\n self.nullifier_tree_root,\n self.contract_tree_root,\n self.l1_to_l2_messages_tree_root,\n self.blocks_tree_root,\n self.public_data_tree_root,\n self.global_variables_hash,\n ]\n }\n\n fn empty() -> Self {\n Self { private_data_tree_root: 0, nullifier_tree_root: 0, contract_tree_root: 0, l1_to_l2_messages_tree_root: 0, blocks_tree_root: 0, public_data_tree_root: 0, global_variables_hash: 0 }\n }\n}\n\nstruct FunctionData {\n function_selector: Field,\n is_internal: bool,\n is_private: bool,\n is_constructor: bool,\n}\n\nimpl FunctionData {\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator([\n self.function_selector,\n self.is_internal as Field,\n self.is_private as Field,\n self.is_constructor as Field,\n ], GENERATOR_INDEX__FUNCTION_DATA)[0]\n }\n}\n\nstruct PrivateCircuitPublicInputs {\n call_context: CallContext,\n args_hash: Field,\n return_values: [Field; RETURN_VALUES_LENGTH],\n read_requests: [Field; crate::abi::MAX_READ_REQUESTS_PER_CALL],\n new_commitments: [Field; MAX_NEW_COMMITMENTS_PER_CALL],\n new_nullifiers: [Field; MAX_NEW_NULLIFIERS_PER_CALL],\n nullified_commitments: [Field; MAX_NEW_NULLIFIERS_PER_CALL],\n private_call_stack: [Field; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL],\n public_call_stack: [Field; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL],\n new_l2_to_l1_msgs: [Field; MAX_NEW_L2_TO_L1_MSGS_PER_CALL],\n // Explore introducing a new type like uint256 (similar to Point), so it's more explicit that\n // we're talking about a single number backed by two field elements.\n encrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256],\n unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256],\n encrypted_log_preimages_length: Field,\n unencrypted_log_preimages_length: Field,\n block_data: HistoricBlockData,\n contract_deployment_data: ContractDeploymentData,\n chain_id: Field,\n version: Field,\n}\n\nimpl PrivateCircuitPublicInputs {\n fn hash(self) -> Field {\n let mut fields: BoundedVec = BoundedVec::new(0); \n fields.push(self.call_context.hash());\n fields.push(self.args_hash);\n fields.push_array(self.return_values);\n fields.push_array(self.read_requests);\n fields.push_array(self.new_commitments);\n fields.push_array(self.new_nullifiers);\n fields.push_array(self.nullified_commitments);\n fields.push_array(self.private_call_stack);\n fields.push_array(self.public_call_stack);\n fields.push_array(self.new_l2_to_l1_msgs);\n fields.push_array(self.encrypted_logs_hash);\n fields.push_array(self.unencrypted_logs_hash);\n fields.push(self.encrypted_log_preimages_length);\n fields.push(self.unencrypted_log_preimages_length);\n fields.push_array(self.block_data.serialize());\n fields.push(self.contract_deployment_data.hash());\n fields.push(self.chain_id);\n fields.push(self.version);\n\n dep::std::hash::pedersen_with_separator(fields.storage, GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS)[0]\n }\n\n fn serialize(self) -> [Field; PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH] {\n let mut fields: BoundedVec = BoundedVec::new(0); \n fields.push_array(self.call_context.serialize());\n fields.push(self.args_hash);\n fields.push_array(self.return_values);\n fields.push_array(self.read_requests);\n fields.push_array(self.new_commitments);\n fields.push_array(self.new_nullifiers);\n fields.push_array(self.private_call_stack);\n fields.push_array(self.public_call_stack);\n fields.push_array(self.new_l2_to_l1_msgs);\n fields.push_array(self.encrypted_logs_hash);\n fields.push_array(self.unencrypted_logs_hash);\n fields.push(self.encrypted_log_preimages_length);\n fields.push(self.unencrypted_log_preimages_length);\n fields.push_array(self.block_data.serialize());\n fields.push_array(self.contract_deployment_data.serialize());\n fields.push(self.chain_id);\n fields.push(self.version);\n fields.storage\n }\n}\n\nstruct ContractStorageRead {\n storage_slot: Field,\n value: Field,\n}\n\nimpl ContractStorageRead {\n fn serialize(self) -> [Field; CONTRACT_STORAGE_READ_LENGTH] {\n [self.storage_slot, self.value]\n }\n\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__PUBLIC_DATA_READ)[0]\n }\n\n fn empty() -> Self {\n Self { storage_slot: 0, value: 0 }\n }\n}\n\nstruct ContractStorageUpdateRequest {\n storage_slot: Field,\n old_value: Field,\n new_value: Field,\n}\n\nimpl ContractStorageUpdateRequest {\n fn serialize(self) -> [Field; CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH] {\n [self.storage_slot, self.old_value, self.new_value]\n }\n\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator(self.serialize(), GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST)[0]\n }\n\n fn empty() -> Self {\n Self { storage_slot: 0, old_value: 0, new_value: 0 }\n }\n}\n\n\nstruct PublicCircuitPublicInputs {\n call_context: CallContext,\n args_hash: Field,\n return_values: [Field; RETURN_VALUES_LENGTH],\n contract_storage_update_requests: [ContractStorageUpdateRequest; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL],\n contract_storage_read: [ContractStorageRead; MAX_PUBLIC_DATA_READS_PER_CALL],\n public_call_stack: [Field; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL],\n new_commitments: [Field; MAX_NEW_COMMITMENTS_PER_CALL],\n new_nullifiers: [Field; crate::abi::MAX_NEW_NULLIFIERS_PER_CALL],\n new_l2_to_l1_msgs: [Field; crate::abi::MAX_NEW_L2_TO_L1_MSGS_PER_CALL],\n unencrypted_logs_hash: [Field; NUM_FIELDS_PER_SHA256],\n unencrypted_log_preimages_length: Field,\n block_data: HistoricBlockData,\n prover_address: Field,\n\n // TODO: include globals in here and check them elsewhere\n // https://github.com/AztecProtocol/aztec-packages/issues/1567\n}\n\nimpl PublicCircuitPublicInputs {\n \n fn hash(self) -> Field {\n let mut inputs: BoundedVec = BoundedVec::new(0);\n inputs.push(self.call_context.hash());\n inputs.push(self.args_hash);\n inputs.push_array(self.return_values);\n for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL {\n inputs.push(self.contract_storage_update_requests[i].hash());\n }\n for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL {\n inputs.push(self.contract_storage_read[i].hash());\n }\n inputs.push_array(self.public_call_stack);\n inputs.push_array(self.new_commitments);\n inputs.push_array(self.new_nullifiers);\n inputs.push_array(self.new_l2_to_l1_msgs);\n\n // We do not include block_data since it's not in the cpp hash\n\n inputs.push_array(self.unencrypted_logs_hash);\n inputs.push(self.unencrypted_log_preimages_length);\n inputs.push_array(self.block_data.serialize()); // see https://github.com/AztecProtocol/aztec-packages/issues/1473\n inputs.push(self.prover_address);\n\n dep::std::hash::pedersen_with_separator(inputs.storage, GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS)[0]\n }\n\n fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] {\n let mut fields: BoundedVec = BoundedVec::new(0); \n fields.push_array(self.call_context.serialize()); \n fields.push(self.args_hash);\n fields.push_array(self.return_values);\n for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL {\n fields.push_array(self.contract_storage_update_requests[i].serialize());\n }\n for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL {\n fields.push_array(self.contract_storage_read[i].serialize());\n }\n fields.push_array(self.public_call_stack);\n fields.push_array(self.new_commitments);\n fields.push_array(self.new_nullifiers);\n fields.push_array(self.new_l2_to_l1_msgs);\n fields.push_array(self.unencrypted_logs_hash);\n fields.push(self.unencrypted_log_preimages_length);\n fields.push_array(self.block_data.serialize());\n fields.push(self.prover_address);\n fields.storage\n }\n}\n\nglobal ARGS_HASH_CHUNK_LENGTH: u32 = 32;\nglobal ARGS_HASH_CHUNK_COUNT: u32 = 16;\n\nfn hash_args(args: [Field; N]) -> Field {\n if args.len() == 0 {\n 0\n } else {\n let mut chunks_hashes = [0; ARGS_HASH_CHUNK_COUNT];\n for i in 0..ARGS_HASH_CHUNK_COUNT {\n let mut chunk_hash = 0;\n let start_chunk_index = i * ARGS_HASH_CHUNK_LENGTH;\n if start_chunk_index < (args.len() as u32) {\n let mut chunk_args = [0; ARGS_HASH_CHUNK_LENGTH];\n for j in 0..ARGS_HASH_CHUNK_LENGTH {\n let item_index = i * ARGS_HASH_CHUNK_LENGTH + j;\n if item_index < (args.len() as u32) {\n chunk_args[j] = args[item_index];\n }\n }\n chunk_hash = dep::std::hash::pedersen_with_separator(chunk_args, GENERATOR_INDEX__FUNCTION_ARGS)[0];\n }\n chunks_hashes[i] = chunk_hash;\n }\n dep::std::hash::pedersen_with_separator(chunks_hashes, GENERATOR_INDEX__FUNCTION_ARGS)[0]\n }\n}\n", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/abi" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/abi" }, "32": { "source": "use crate::constants_gen::{\n EMPTY_NULLIFIED_COMMITMENT,\n MAX_NEW_COMMITMENTS_PER_CALL,\n MAX_NEW_L2_TO_L1_MSGS_PER_CALL,\n MAX_NEW_NULLIFIERS_PER_CALL,\n MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL,\n MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,\n MAX_PUBLIC_DATA_READS_PER_CALL,\n MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,\n MAX_READ_REQUESTS_PER_CALL,\n NUM_FIELDS_PER_SHA256,\n RETURN_VALUES_LENGTH,\n};\n\nuse crate::abi;\n\nuse crate::abi::{\n hash_args,\n CallContext,\n ContractDeploymentData,\n HistoricBlockData,\n FunctionData,\n PrivateCircuitPublicInputs,\n PublicCircuitPublicInputs,\n};\n\n// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n// use dep::std::collections::vec::Vec;\n\n// l1 to l2 messaging\nuse crate::messaging::process_l1_to_l2_message;\nuse crate::private_call_stack_item::PrivateCallStackItem;\nuse crate::public_call_stack_item::PublicCallStackItem;\n\nuse crate::types::{\n vec::BoundedVec,\n point::Point,\n};\n\nuse crate::utils::arr_copy_slice;\n\nuse crate::oracle::{\n arguments,\n call_private_function::call_private_function_internal,\n public_call::call_public_function_internal,\n enqueue_public_function_call::enqueue_public_function_call_internal,\n context::get_portal_address,\n};\n\n\n// When finished, one can call .finish() to convert back to the abi\nstruct PrivateContext {\n inputs: abi::PrivateContextInputs,\n\n args_hash : Field,\n return_values : BoundedVec,\n\n read_requests: BoundedVec,\n\n new_commitments: BoundedVec,\n new_nullifiers: BoundedVec,\n nullified_commitments: BoundedVec,\n\n private_call_stack : BoundedVec,\n public_call_stack : BoundedVec,\n new_l2_to_l1_msgs : BoundedVec,\n\n block_data: HistoricBlockData,\n\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n // encrypted_logs_preimages: Vec,\n // unencrypted_logs_preimages: Vec,\n}\n\nimpl PrivateContext {\n fn new(inputs: abi::PrivateContextInputs, args_hash: Field) -> PrivateContext {\n PrivateContext {\n inputs: inputs,\n\n args_hash: args_hash,\n return_values: BoundedVec::new(0),\n\n read_requests: BoundedVec::new(0),\n\n new_commitments: BoundedVec::new(0),\n new_nullifiers: BoundedVec::new(0),\n nullified_commitments: BoundedVec::new(0),\n\n block_data: inputs.block_data,\n\n private_call_stack: BoundedVec::new(0),\n public_call_stack: BoundedVec::new(0),\n new_l2_to_l1_msgs: BoundedVec::new(0),\n\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n // encrypted_logs_preimages: Vec::new(),\n // unencrypted_logs_preimages: Vec::new(),\n }\n }\n\n fn msg_sender(self) -> Field {\n self.inputs.call_context.msg_sender\n }\n\n fn this_address(self) -> Field {\n self.inputs.call_context.storage_contract_address\n }\n\n fn this_portal_address(self) -> Field {\n self.inputs.call_context.portal_contract_address\n }\n\n fn chain_id(self) -> Field {\n self.inputs.private_global_variables.chain_id\n }\n\n fn version(self) -> Field {\n self.inputs.private_global_variables.version\n }\n\n fn finish(self) -> abi::PrivateCircuitPublicInputs {\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n let encrypted_logs_hash = [0; NUM_FIELDS_PER_SHA256];\n let unencrypted_logs_hash = [0; NUM_FIELDS_PER_SHA256];\n let encrypted_log_preimages_length = 0;\n let unencrypted_log_preimages_length = 0;\n\n let priv_circuit_pub_inputs = abi::PrivateCircuitPublicInputs {\n call_context: self.inputs.call_context,\n args_hash: self.args_hash,\n return_values: self.return_values.storage,\n read_requests: self.read_requests.storage,\n new_commitments: self.new_commitments.storage,\n new_nullifiers: self.new_nullifiers.storage,\n nullified_commitments: self.nullified_commitments.storage,\n private_call_stack: self.private_call_stack.storage,\n public_call_stack: self.public_call_stack.storage,\n new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage,\n encrypted_logs_hash: encrypted_logs_hash,\n unencrypted_logs_hash: unencrypted_logs_hash,\n encrypted_log_preimages_length: encrypted_log_preimages_length,\n unencrypted_log_preimages_length: unencrypted_log_preimages_length,\n block_data: self.block_data,\n contract_deployment_data: self.inputs.contract_deployment_data,\n chain_id: self.inputs.private_global_variables.chain_id,\n version: self.inputs.private_global_variables.version,\n };\n priv_circuit_pub_inputs\n }\n\n fn push_read_request(&mut self, read_request: Field) {\n self.read_requests.push(read_request);\n }\n\n fn push_new_note_hash(&mut self, note_hash: Field) {\n self.new_commitments.push(note_hash);\n }\n\n fn push_new_nullifier(&mut self, nullifier: Field, nullified_commitment: Field) {\n self.new_nullifiers.push(nullifier);\n self.nullified_commitments.push(nullified_commitment);\n }\n\n fn message_portal(&mut self, content: Field) {\n self.new_l2_to_l1_msgs.push(content);\n }\n\n // PrivateContextInputs must be temporarily passed in to prevent too many unknowns\n // Note this returns self to get around an issue where mutable structs do not maintain mutations unless reassigned\n fn consume_l1_to_l2_message(&mut self, inputs: abi::PrivateContextInputs, msg_key: Field, content: Field, secret: Field) {\n let nullifier = process_l1_to_l2_message(inputs.block_data.l1_to_l2_messages_tree_root, inputs.call_context.storage_contract_address, msg_key, content, secret);\n\n // Push nullifier (and the \"commitment\" corresponding to this can be \"empty\")\n self.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT)\n }\n\n fn accumulate_encrypted_logs(&mut self, log: [Field; N]) {\n let _void1 = self.inputs;\n let _void2 = log;\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n }\n\n fn accumulate_unencrypted_logs(&mut self, log: T) {\n let _void1 = self.inputs;\n let _void2 = log;\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n }\n\n fn call_private_function(\n &mut self,\n contract_address: Field, \n function_selector: Field, \n args: [Field; ARGS_COUNT]\n ) -> [Field; RETURN_VALUES_LENGTH] {\n let args_hash = hash_args(args);\n assert(args_hash == arguments::pack_arguments(args));\n self.call_private_function_with_packed_args(contract_address, function_selector, args_hash)\n }\n\n fn call_private_function_no_args(\n &mut self,\n contract_address: Field, \n function_selector: Field, \n ) -> [Field; RETURN_VALUES_LENGTH] {\n self.call_private_function_with_packed_args(contract_address, function_selector, 0)\n }\n\n fn call_private_function_with_packed_args(\n &mut self,\n contract_address: Field,\n function_selector: Field,\n args_hash: Field\n ) -> [Field; RETURN_VALUES_LENGTH] {\n let fields = call_private_function_internal(\n contract_address, \n function_selector, \n args_hash\n );\n let item = PrivateCallStackItem {\n contract_address: fields[0],\n function_data: FunctionData {\n function_selector: fields[1],\n is_internal: fields[2] as bool,\n is_private: fields[3] as bool,\n is_constructor: fields[4] as bool,\n },\n public_inputs: PrivateCircuitPublicInputs {\n call_context: CallContext {\n msg_sender : fields[5],\n storage_contract_address : fields[6],\n portal_contract_address : fields[7],\n \n is_delegate_call : fields[8] as bool,\n is_static_call : fields[9] as bool,\n is_contract_deployment: fields[10] as bool,\n },\n // TODO handle the offsets as a variable incremented during extraction?\n args_hash: fields[11],\n return_values: arr_copy_slice(fields, [0; RETURN_VALUES_LENGTH], 12),\n read_requests: arr_copy_slice(fields, [0; MAX_READ_REQUESTS_PER_CALL], 16),\n new_commitments: arr_copy_slice(fields, [0; MAX_NEW_COMMITMENTS_PER_CALL], 20),\n new_nullifiers: arr_copy_slice(fields, [0; MAX_NEW_NULLIFIERS_PER_CALL], 24),\n nullified_commitments: arr_copy_slice(fields, [0; MAX_NEW_NULLIFIERS_PER_CALL], 28),\n private_call_stack: arr_copy_slice(fields, [0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL], 32),\n public_call_stack: arr_copy_slice(fields, [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL], 36),\n new_l2_to_l1_msgs: arr_copy_slice(fields, [0; MAX_NEW_L2_TO_L1_MSGS_PER_CALL], 40),\n encrypted_logs_hash: arr_copy_slice(fields, [0; NUM_FIELDS_PER_SHA256], 42),\n unencrypted_logs_hash: arr_copy_slice(fields, [0; NUM_FIELDS_PER_SHA256], 44),\n encrypted_log_preimages_length: fields[46],\n unencrypted_log_preimages_length: fields[47],\n block_data: HistoricBlockData {\n // Must match order in `private_circuit_public_inputs.hpp`\n private_data_tree_root : fields[48],\n nullifier_tree_root : fields[49],\n contract_tree_root : fields[50],\n l1_to_l2_messages_tree_root : fields[51],\n blocks_tree_root : fields[52],\n public_data_tree_root: fields[53],\n global_variables_hash: fields[54],\n },\n contract_deployment_data: ContractDeploymentData {\n deployer_public_key: Point::new(fields[55], fields[56]),\n constructor_vk_hash : fields[57],\n function_tree_root : fields[58],\n contract_address_salt : fields[59],\n portal_contract_address : fields[60],\n },\n chain_id: fields[61],\n version: fields[62],\n },\n is_execution_request: fields[63] as bool,\n };\n assert(contract_address == item.contract_address);\n assert(function_selector == item.function_data.function_selector);\n\n assert(args_hash == item.public_inputs.args_hash);\n\n assert(item.is_execution_request == false);\n\n // Assert that the call context of the enqueued call generated by the oracle matches our request.\n // We are issuing a regular call which is not delegate, static, or deployment. We also constrain\n // the msg_sender in the nested call to be equal to our address, and the execution context address\n // for the nested call to be equal to the address we actually called.\n assert(item.public_inputs.call_context.is_delegate_call == false);\n assert(item.public_inputs.call_context.is_static_call == false);\n assert(item.public_inputs.call_context.is_contract_deployment == false);\n assert(item.public_inputs.call_context.msg_sender == self.inputs.call_context.storage_contract_address);\n assert(item.public_inputs.call_context.storage_contract_address == contract_address);\n\n self.private_call_stack.push(item.hash());\n\n item.public_inputs.return_values\n }\n\n fn call_public_function(\n &mut self,\n contract_address: Field, \n function_selector: Field, \n args: [Field; ARGS_COUNT]\n ) {\n let args_hash = hash_args(args);\n assert(args_hash == arguments::pack_arguments(args));\n self.call_public_function_with_packed_args(contract_address, function_selector, args_hash)\n }\n\n fn call_public_function_no_args(\n &mut self,\n contract_address: Field, \n function_selector: Field,\n ) {\n self.call_public_function_with_packed_args(contract_address, function_selector, 0)\n }\n\n fn call_public_function_with_packed_args(\n &mut self,\n contract_address: Field,\n function_selector: Field,\n args_hash: Field\n ) {\n let fields = enqueue_public_function_call_internal(\n contract_address, \n function_selector, \n args_hash\n );\n let item = PublicCallStackItem {\n contract_address: fields[0],\n function_data: FunctionData {\n function_selector: fields[1],\n is_internal: fields[2] as bool,\n is_private: fields[3] as bool,\n is_constructor: fields[4] as bool,\n },\n public_inputs: PublicCircuitPublicInputs {\n call_context: CallContext {\n msg_sender : fields[5],\n storage_contract_address : fields[6],\n portal_contract_address : fields[7],\n \n is_delegate_call : fields[8] as bool,\n is_static_call : fields[9] as bool,\n is_contract_deployment: fields[10] as bool,\n },\n args_hash: fields[11],\n return_values: [0; RETURN_VALUES_LENGTH],\n contract_storage_update_requests: [ContractStorageUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL],\n contract_storage_read: [ContractStorageRead::empty(); MAX_PUBLIC_DATA_READS_PER_CALL],\n public_call_stack: [0; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL],\n new_commitments: [0; MAX_NEW_COMMITMENTS_PER_CALL],\n new_nullifiers: [0; MAX_NEW_NULLIFIERS_PER_CALL],\n new_l2_to_l1_msgs:[0; MAX_NEW_L2_TO_L1_MSGS_PER_CALL],\n unencrypted_logs_hash:[0; NUM_FIELDS_PER_SHA256],\n unencrypted_log_preimages_length: 0,\n block_data: HistoricBlockData::empty(),\n prover_address: 0,\n },\n is_execution_request: true,\n };\n\n assert(contract_address == item.contract_address);\n assert(function_selector == item.function_data.function_selector);\n \n assert(args_hash == item.public_inputs.args_hash);\n\n // Assert that the call context of the enqueued call generated by the oracle matches our request.\n // We are issuing a regular call which is not delegate, static, or deployment. We also constrain\n // the msg_sender in the nested call to be equal to our address, and the execution context address\n // for the nested call to be equal to the address we actually called.\n assert(item.public_inputs.call_context.is_delegate_call == false);\n assert(item.public_inputs.call_context.is_static_call == false);\n assert(item.public_inputs.call_context.is_contract_deployment == false);\n assert(item.public_inputs.call_context.msg_sender == self.inputs.call_context.storage_contract_address);\n assert(item.public_inputs.call_context.storage_contract_address == contract_address);\n\n self.public_call_stack.push(item.hash());\n }\n}\n\nuse crate::abi::{\n ContractStorageRead,\n ContractStorageUpdateRequest\n};\n\nstruct PublicContext {\n inputs: abi::PublicContextInputs,\n\n args_hash : Field,\n return_values : BoundedVec,\n\n contract_storage_update_requests: BoundedVec,\n contract_storage_read: BoundedVec,\n public_call_stack: BoundedVec,\n\n new_commitments: BoundedVec,\n new_nullifiers: BoundedVec,\n\n new_l2_to_l1_msgs: BoundedVec,\n\n unencrypted_logs_hash: BoundedVec,\n unencrypted_logs_preimages_length: Field,\n\n block_data: HistoricBlockData,\n prover_address: Field,\n}\n\nimpl PublicContext {\n fn new(inputs: abi::PublicContextInputs, args_hash: Field) -> PublicContext {\n let empty_storage_read = ContractStorageRead::empty();\n let empty_storage_update = ContractStorageUpdateRequest::empty();\n PublicContext {\n inputs: inputs,\n\n args_hash: args_hash,\n return_values: BoundedVec::new(0),\n\n contract_storage_update_requests: BoundedVec::new(empty_storage_update),\n contract_storage_read: BoundedVec::new(empty_storage_read),\n public_call_stack: BoundedVec::new(0),\n\n new_commitments: BoundedVec::new(0),\n new_nullifiers: BoundedVec::new(0),\n\n new_l2_to_l1_msgs: BoundedVec::new(0),\n\n \n unencrypted_logs_hash: BoundedVec::new(0),\n unencrypted_logs_preimages_length: 0,\n\n block_data: inputs.block_data,\n prover_address: 0,\n\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n // encrypted_logs_preimages: Vec::new(),\n // unencrypted_logs_preimages: Vec::new(),\n }\n }\n\n fn msg_sender(self) -> Field {\n self.inputs.call_context.msg_sender\n }\n\n fn this_address(self) -> Field {\n self.inputs.call_context.storage_contract_address\n }\n\n fn this_portal_address(self) -> Field {\n self.inputs.call_context.portal_contract_address\n }\n\n fn chain_id(self) -> Field {\n self.inputs.public_global_variables.chain_id\n }\n\n fn version(self) -> Field {\n self.inputs.public_global_variables.version\n }\n\n fn block_number(self) -> Field {\n self.inputs.public_global_variables.block_number\n }\n\n fn timestamp(self) -> Field {\n self.inputs.public_global_variables.timestamp\n }\n\n fn finish(self) -> abi::PublicCircuitPublicInputs {\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n let unencrypted_logs_hash = [0; NUM_FIELDS_PER_SHA256];\n let unencrypted_log_preimages_length = 0;\n\n\n // Compute the public call stack hashes\n let pub_circuit_pub_inputs = abi::PublicCircuitPublicInputs {\n call_context: self.inputs.call_context, // Done\n args_hash: self.args_hash, // Done\n contract_storage_update_requests: self.contract_storage_update_requests.storage,\n contract_storage_read: self.contract_storage_read.storage,\n return_values: self.return_values.storage,\n new_commitments: self.new_commitments.storage,\n new_nullifiers: self.new_nullifiers.storage,\n public_call_stack: self.public_call_stack.storage,\n new_l2_to_l1_msgs: self.new_l2_to_l1_msgs.storage,\n unencrypted_logs_hash: unencrypted_logs_hash,\n unencrypted_log_preimages_length: unencrypted_log_preimages_length,\n block_data: self.inputs.block_data,\n prover_address: self.prover_address,\n };\n pub_circuit_pub_inputs\n }\n\n fn push_new_note_hash(&mut self, note_hash: Field) {\n self.new_commitments.push(note_hash);\n }\n\n fn push_new_nullifier(&mut self, nullifier: Field, _nullified_commitment: Field) {\n self.new_nullifiers.push(nullifier);\n }\n\n fn message_portal(&mut self, content: Field) {\n self.new_l2_to_l1_msgs.push(content);\n }\n\n // PrivateContextInputs must be temporarily passed in to prevent too many unknowns\n // Note this returns self to get around an issue where mutable structs do not maintain mutations unless reassigned\n fn consume_l1_to_l2_message(&mut self, msg_key: Field, content: Field, secret: Field) {\n let this = (*self).this_address();\n let nullifier = process_l1_to_l2_message(self.block_data.l1_to_l2_messages_tree_root, this, msg_key, content, secret);\n\n // Push nullifier (and the \"commitment\" corresponding to this can be \"empty\")\n self.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT)\n }\n\n fn accumulate_encrypted_logs(&mut self, log: [Field; N]) {\n let _void1 = self;\n let _void2 = log;\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n }\n\n fn accumulate_unencrypted_logs(&mut self, log: T) {\n let _void1 = self;\n let _void2 = log;\n // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)\n }\n\n fn call_public_function(\n _self: Self,\n contract_address: Field, \n function_selector: Field,\n args: [Field; ARGS_COUNT],\n ) -> [Field; RETURN_VALUES_LENGTH] {\n let args_hash = abi::hash_args(args);\n assert(args_hash == arguments::pack_arguments(args));\n call_public_function_internal(\n contract_address, \n function_selector, \n args_hash,\n )\n }\n\n fn call_public_function_no_args(\n _self: Self,\n contract_address: Field, \n function_selector: Field,\n ) -> [Field; RETURN_VALUES_LENGTH] {\n call_public_function_internal(\n contract_address, \n function_selector, \n 0,\n )\n }\n\n}", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/context" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/context" }, "55": { "source": "\nstruct BoundedVec {\n storage: [T; MaxLen],\n len: Field,\n}\n\nimpl BoundedVec {\n fn new(initial_value: T) -> Self {\n BoundedVec { storage: [initial_value; MaxLen], len: 0 }\n }\n\n fn get(mut self: Self, index: Field) -> T {\n assert(index as u64 < self.len as u64);\n self.storage[index]\n }\n\n fn push(&mut self, elem: T) {\n assert(self.len as u64 < MaxLen as u64);\n\n self.storage[self.len] = elem;\n self.len += 1;\n }\n\n fn push_array(&mut self, array: [T; Len]) {\n let newLen = self.len + array.len();\n assert(newLen as u64 <= MaxLen as u64);\n for i in 0..array.len() {\n self.storage[self.len + i] = array[i];\n }\n self.len = newLen;\n }\n\n fn pop(&mut self) -> T {\n assert(self.len as u64 > 0);\n\n let elem = self.storage[self.len - 1];\n self.len -= 1;\n elem\n }\n}\n\n// #[test]\n// fn test_vec() {\n// let vec: BoundedVec = BoundedVec::new(0);\n// assert(vec.len == 0);\n// let vec1 = vec.push(1);\n// assert(vec1.len == 1);\n// let vec2 = vec1.push(1);\n// assert(vec2.len == 2);\n// let vec3 = vec2.push(1);\n// assert(vec3.len == 3);\n// let x = vec3.pop();\n// assert(x == 1);\n// }", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/types/vec" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/types/vec" }, "61": { "source": "use crate::abi::FunctionData;\nuse crate::abi::PrivateCircuitPublicInputs;\nuse crate::constants_gen::GENERATOR_INDEX__CALL_STACK_ITEM;\n\nstruct PrivateCallStackItem {\n contract_address: Field,\n function_data: FunctionData,\n public_inputs: PrivateCircuitPublicInputs,\n is_execution_request: bool,\n}\n\nimpl PrivateCallStackItem {\n fn hash(self) -> Field {\n dep::std::hash::pedersen_with_separator([\n self.contract_address,\n self.function_data.hash(),\n self.public_inputs.hash(),\n ], GENERATOR_INDEX__CALL_STACK_ITEM)[0]\n }\n}", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/private_call_stack_item" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/private_call_stack_item" }, "78": { "source": "use crate::abi;\nuse crate::types::vec::BoundedVec;\nuse crate::context::PrivateContext;\nuse crate::private_call_stack_item::PrivateCallStackItem;\nuse crate::public_call_stack_item::PublicCallStackItem; \n\nglobal ACCOUNT_MAX_PRIVATE_CALLS: Field = 2;\nglobal ACCOUNT_MAX_PUBLIC_CALLS: Field = 2;\nglobal ACCOUNT_MAX_CALLS: Field = 4;\n// 1 (ARGS_HASH) + 1 (FUNCTION_SELECTOR) + 1 (TARGET_ADDRESS)\nglobal FUNCTION_CALL_SIZE: Field = 3;\n\nstruct FunctionCall {\n args_hash: Field,\n function_selector: Field,\n target_address: Field,\n}\n\nimpl FunctionCall {\n fn serialize(self) -> [Field; FUNCTION_CALL_SIZE] {\n [self.args_hash, self.function_selector, self.target_address]\n }\n}\n\n// FUNCTION_CALL_SIZE * (ACCOUNT_MAX_PUBLIC_CALLS + ACCOUNT_MAX_PRIVATE_CALLS) + 1\nglobal ENTRYPOINT_PAYLOAD_SIZE: Field = 13;\nglobal ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES: Field = 416;\n\nstruct EntrypointPayload {\n // Noir doesnt support nested arrays or structs yet so we flatten everything\n flattened_args_hashes: [Field; ACCOUNT_MAX_CALLS],\n flattened_selectors: [Field; ACCOUNT_MAX_CALLS],\n flattened_targets: [Field; ACCOUNT_MAX_CALLS],\n nonce: Field,\n}\n\nimpl EntrypointPayload {\n // TODO(#1207) Do we need a generator index?\n fn hash(self) -> Field {\n dep::std::hash::pedersen(self.serialize())[0]\n }\n\n // Serializes the entrypoint struct\n fn serialize(self) -> [Field; ENTRYPOINT_PAYLOAD_SIZE] {\n let mut fields: BoundedVec = BoundedVec::new(0); \n fields.push_array(self.flattened_args_hashes);\n fields.push_array(self.flattened_selectors);\n fields.push_array(self.flattened_targets);\n fields.push(self.nonce);\n fields.storage\n }\n\n // Serializes the payload as an array of bytes. Useful for hashing with sha256.\n fn to_be_bytes(self) -> [u8; ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES] {\n let mut bytes: [u8; ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES] = [0; ENTRYPOINT_PAYLOAD_SIZE_IN_BYTES];\n\n let args_len = self.flattened_args_hashes.len();\n let selectors_len = self.flattened_selectors.len();\n let targets_len = self.flattened_targets.len();\n\n for i in 0..args_len {\n let item_bytes = self.flattened_args_hashes[i].to_be_bytes(32);\n for j in 0..32 { \n bytes[i * 32 + j] = item_bytes[j];\n }\n }\n\n for i in 0..selectors_len {\n let item_bytes = self.flattened_selectors[i].to_be_bytes(32);\n for j in 0..32 { \n bytes[args_len * 32 + i * 32 + j] = item_bytes[j];\n }\n }\n\n for i in 0..targets_len {\n let item_bytes = self.flattened_targets[i].to_be_bytes(32);\n for j in 0..32 { \n bytes[(args_len + selectors_len) * 32 + i * 32 + j] = item_bytes[j];\n }\n }\n \n let item_bytes = self.nonce.to_be_bytes(32);\n for j in 0..32 { \n bytes[(args_len + selectors_len + targets_len) * 32 + j] = item_bytes[j];\n }\n\n bytes\n }\n\n // Executes all private and public calls \n fn execute_calls(self, context: &mut PrivateContext) {\n for i in 0..ACCOUNT_MAX_PRIVATE_CALLS {\n let target_address = self.flattened_targets[i];\n if target_address != 0 {\n let function_selector = self.flattened_selectors[i];\n let args_hash = self.flattened_args_hashes[i];\n let _callStackItem = context.call_private_function_with_packed_args(target_address, function_selector, args_hash);\n }\n }\n for i in ACCOUNT_MAX_PRIVATE_CALLS..ACCOUNT_MAX_CALLS {\n let target_address = self.flattened_targets[i];\n if target_address != 0 {\n let function_selector = self.flattened_selectors[i];\n let args_hash = self.flattened_args_hashes[i];\n let _callStackItem = context.call_public_function_with_packed_args(target_address, function_selector, args_hash);\n }\n }\n }\n}", - "path": "/mnt/user-data/lasse/aztec3-packages/yarn-project/noir-libs/noir-aztec/src/entrypoint" + "path": "/mnt/user-data/jan/aztec-packages/yarn-project/noir-libs/noir-aztec/src/entrypoint" } } } diff --git a/yarn-project/end-to-end/src/e2e_2_rpc_servers.test.ts b/yarn-project/end-to-end/src/e2e_2_rpc_servers.test.ts index 444376f1d2b1..64347fc67d0c 100644 --- a/yarn-project/end-to-end/src/e2e_2_rpc_servers.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_rpc_servers.test.ts @@ -7,12 +7,7 @@ import { toBigInt } from '@aztec/foundation/serialize'; import { ChildContract, PrivateTokenContract } from '@aztec/noir-contracts/types'; import { AztecRPC, CompleteAddress, TxStatus } from '@aztec/types'; -import { - expectUnencryptedLogsFromLastBlockToBe, - expectsNumOfEncryptedLogsInTheLastBlockToBe, - setup, - setupAztecRPCServer, -} from './fixtures/utils.js'; +import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup, setupAztecRPCServer } from './fixtures/utils.js'; const { SANDBOX_URL = '' } = process.env; @@ -113,7 +108,6 @@ describe('e2e_2_rpc_servers', () => { await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance); await expectTokenBalance(walletB, tokenAddress, userB.address, 0n); await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1); - await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServerA, ['Balance set in constructor']); // Transfer funds from A to B via RPC server A const contractWithWalletA = await PrivateTokenContract.at(tokenAddress, walletA); @@ -130,7 +124,6 @@ describe('e2e_2_rpc_servers', () => { await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance - transferAmount1); await expectTokenBalance(walletB, tokenAddress, userB.address, transferAmount1); await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2); - await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServerA, ['Coins transferred']); // Transfer funds from B to A via RPC server B const contractWithWalletB = await PrivateTokenContract.at(tokenAddress, walletB); @@ -147,7 +140,6 @@ describe('e2e_2_rpc_servers', () => { await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance - transferAmount1 + transferAmount2); await expectTokenBalance(walletB, tokenAddress, userB.address, transferAmount1 - transferAmount2); await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2); - await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServerA, ['Coins transferred']); }, 120_000); const deployChildContractViaServerA = async () => { diff --git a/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts b/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts index 7ace13af30d0..475dc1263e81 100644 --- a/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts +++ b/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts @@ -6,11 +6,7 @@ import { DebugLogger } from '@aztec/foundation/log'; import { PrivateTokenContract } from '@aztec/noir-contracts/types'; import { AztecRPC, TxStatus } from '@aztec/types'; -import { - expectUnencryptedLogsFromLastBlockToBe, - expectsNumOfEncryptedLogsInTheLastBlockToBe, - setup, -} from './fixtures/utils.js'; +import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/utils.js'; describe('e2e_multiple_accounts_1_enc_key', () => { let aztecNode: AztecNodeService | undefined; @@ -96,7 +92,6 @@ describe('e2e_multiple_accounts_1_enc_key', () => { } await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2); - await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Coins transferred']); logger(`Transfer ${transferAmount} from ${sender} to ${receiver} successful`); }; diff --git a/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts index 03a5df9272e9..72ffa0da02b6 100644 --- a/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts @@ -5,11 +5,7 @@ import { DebugLogger } from '@aztec/foundation/log'; import { PrivateTokenContract } from '@aztec/noir-contracts/types'; import { AztecRPC, CompleteAddress, TxStatus } from '@aztec/types'; -import { - expectUnencryptedLogsFromLastBlockToBe, - expectsNumOfEncryptedLogsInTheLastBlockToBe, - setup, -} from './fixtures/utils.js'; +import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/utils.js'; describe('e2e_private_token_contract', () => { let aztecNode: AztecNodeService | undefined; @@ -58,7 +54,6 @@ describe('e2e_private_token_contract', () => { await expectBalance(receiver, 0n); await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1); - await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Balance set in constructor']); }, 30_000); /** @@ -81,7 +76,6 @@ describe('e2e_private_token_contract', () => { await expectBalance(owner, mintAmount); await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1); - await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Coins minted']); }, 60_000); /** @@ -97,7 +91,6 @@ describe('e2e_private_token_contract', () => { await expectBalance(receiver, 0n); await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1); - await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Balance set in constructor']); const tx = contract.methods.transfer(transferAmount, owner, receiver).send({ origin: owner }); @@ -110,6 +103,5 @@ describe('e2e_private_token_contract', () => { await expectBalance(receiver, transferAmount); await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2); - await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Coins transferred']); }, 60_000); }); diff --git a/yarn-project/end-to-end/src/e2e_public_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_public_token_contract.test.ts index ad40149332b9..ab554767011a 100644 --- a/yarn-project/end-to-end/src/e2e_public_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_token_contract.test.ts @@ -3,11 +3,11 @@ import { AztecRPCServer } from '@aztec/aztec-rpc'; import { AztecAddress, Wallet } from '@aztec/aztec.js'; import { DebugLogger } from '@aztec/foundation/log'; import { PublicTokenContract } from '@aztec/noir-contracts/types'; -import { AztecRPC, CompleteAddress, L2BlockL2Logs, TxStatus } from '@aztec/types'; +import { AztecRPC, CompleteAddress, TxStatus } from '@aztec/types'; import times from 'lodash.times'; -import { setup } from './fixtures/utils.js'; +import { expectUnencryptedLogsFromLastBlockToBe, setup } from './fixtures/utils.js'; describe('e2e_public_token_contract', () => { let aztecNode: AztecNodeService | undefined; @@ -26,19 +26,6 @@ describe('e2e_public_token_contract', () => { return { contract, txReceipt }; }; - const expectLogsFromLastBlockToBe = async (logMessages: string[]) => { - // docs:start:logs - - const l2BlockNum = await aztecRpcServer.getBlockNumber(); - const unencryptedLogs = await aztecRpcServer.getUnencryptedLogs(l2BlockNum, 1); - - // docs:end:logs - const unrolledLogs = L2BlockL2Logs.unrollLogs(unencryptedLogs); - const asciiLogs = unrolledLogs.map(log => log.toString('ascii')); - - expect(asciiLogs).toStrictEqual(logMessages); - }; - beforeEach(async () => { let accounts: CompleteAddress[]; ({ aztecNode, aztecRpcServer, accounts, wallet, logger } = await setup()); @@ -72,7 +59,7 @@ describe('e2e_public_token_contract', () => { const balance = await contract.methods.publicBalanceOf(recipient.toField()).view({ from: recipient }); expect(balance).toBe(mintAmount); - await expectLogsFromLastBlockToBe(['Coins minted']); + await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Coins minted']); }, 45_000); // Regression for https://github.com/AztecProtocol/aztec-packages/issues/640 @@ -95,6 +82,6 @@ describe('e2e_public_token_contract', () => { const balance = await contract.methods.publicBalanceOf(recipient.toField()).view({ from: recipient }); expect(balance).toBe(mintAmount * 3n); - await expectLogsFromLastBlockToBe(['Coins minted', 'Coins minted', 'Coins minted']); + await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Coins minted', 'Coins minted', 'Coins minted']); }, 60_000); }); diff --git a/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts b/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts index 7464b9881618..6513204a5328 100644 --- a/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts +++ b/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts @@ -4,7 +4,6 @@ // docs:start:imports import { AztecRPC, - L2BlockL2Logs, PrivateKey, createAztecRpcClient, createDebugLogger, @@ -20,9 +19,7 @@ import { createAztecRpcClient as createAztecRpcClient2 } from '@aztec/aztec.js'; import { defaultFetch } from '@aztec/foundation/json-rpc/client'; import { PrivateTokenContract } from '@aztec/noir-contracts/types'; -import { expectUnencryptedLogsFromLastBlockToBe } from './fixtures/utils.js'; - -const { SANDBOX_URL } = process.env; +const { SANDBOX_URL = 'http://localhost:8080' } = process.env; describe('e2e_sandbox_example', () => { // Note: this is a hack to make the docs use http://localhost:8080 and CI to use the SANDBOX_URL @@ -121,25 +118,6 @@ describe('e2e_sandbox_example', () => { // ensure that private token contract is registered in the rpc expect(await aztecRpc.getContracts()).toEqual(expect.arrayContaining([contract.address])); - // docs:start:Logs - - ////////////// RETRIEVE THE UNENCRYPTED LOGS EMITTED DURING DEPLOYMENT ////////////// - - // We can view the unencrypted logs emitted by the contract... - const viewUnencryptedLogs = async () => { - const lastBlock = await aztecRpc.getBlockNumber(); - logger(`Retrieving unencrypted logs for block ${lastBlock}`); - const logs = await aztecRpc.getUnencryptedLogs(lastBlock, 1); - const unrolledLogs = L2BlockL2Logs.unrollLogs(logs); - const asciiLogs = unrolledLogs.map(log => log.toString('ascii')); - logger(`Emitted logs: `, asciiLogs); - }; - await viewUnencryptedLogs(); - - // docs:end:Logs - - await expectUnencryptedLogsFromLastBlockToBe(aztecRpc, ['Balance set in constructor']); - // docs:start:Balance ////////////// QUERYING THE TOKEN BALANCE FOR EACH ACCOUNT ////////////// @@ -169,9 +147,6 @@ describe('e2e_sandbox_example', () => { logger(`Transferring ${transferQuantity} tokens from Alice to Bob...`); await tokenContractAlice.methods.transfer(transferQuantity, alice, bob).send().wait(); - // See if any logs were emitted - await viewUnencryptedLogs(); - // Check the new balances aliceBalance = await tokenContractAlice.methods.getBalance(alice).view(); logger(`Alice's balance ${aliceBalance}`); @@ -183,8 +158,6 @@ describe('e2e_sandbox_example', () => { expect(aliceBalance).toBe(initialSupply - transferQuantity); expect(bobBalance).toBe(transferQuantity); - await expectUnencryptedLogsFromLastBlockToBe(aztecRpc, ['Coins transferred']); - // docs:start:Mint ////////////// MINT SOME MORE TOKENS TO BOB'S ACCOUNT ////////////// @@ -193,9 +166,6 @@ describe('e2e_sandbox_example', () => { logger(`Minting ${mintQuantity} tokens to Bob...`); await tokenContractBob.methods.mint(mintQuantity, bob).send().wait(); - // See if any logs were emitted - await viewUnencryptedLogs(); - // Check the new balances aliceBalance = await tokenContractAlice.methods.getBalance(alice).view(); logger(`Alice's balance ${aliceBalance}`); @@ -206,7 +176,5 @@ describe('e2e_sandbox_example', () => { expect(aliceBalance).toBe(initialSupply - transferQuantity); expect(bobBalance).toBe(transferQuantity + mintQuantity); - - await expectUnencryptedLogsFromLastBlockToBe(aztecRpc, ['Coins minted']); }, 60_000); }); diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index 27f04ae7ff6b..63b13b3c2a6d 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -430,8 +430,12 @@ export const expectsNumOfEncryptedLogsInTheLastBlockToBe = async ( * @param logMessages - The set of expected log messages. */ export const expectUnencryptedLogsFromLastBlockToBe = async (rpc: AztecRPC, logMessages: string[]) => { + // docs:start:get_logs + // Get the latest block number to retrieve logs from const l2BlockNum = await rpc.getBlockNumber(); + // Get the unencrypted logs from the last block const unencryptedLogs = await rpc.getUnencryptedLogs(l2BlockNum, 1); + // docs:end:get_logs const unrolledLogs = L2BlockL2Logs.unrollLogs(unencryptedLogs); const asciiLogs = unrolledLogs.map(log => log.toString('ascii')); diff --git a/yarn-project/noir-contracts/src/contracts/easy_private_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/easy_private_token_contract/src/main.nr index 0feb908d29bf..b0e48aa156a2 100644 --- a/yarn-project/noir-contracts/src/contracts/easy_private_token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/easy_private_token_contract/src/main.nr @@ -14,7 +14,6 @@ contract EasyPrivateToken { abi, abi::PrivateContextInputs, context::PrivateContext, - log::emit_unencrypted_log, note::{ note_header::NoteHeader, utils as note_utils, @@ -39,8 +38,6 @@ contract EasyPrivateToken { balances.at(owner).add(&mut context, initial_supply, owner); - emit_unencrypted_log(&mut context, "Balance set in constructor"); - // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. context.finish() } @@ -60,8 +57,6 @@ contract EasyPrivateToken { balances.at(owner).add(&mut context, amount, owner); - emit_unencrypted_log(&mut context, "Coins minted"); - // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.. context.finish() } @@ -83,8 +78,6 @@ contract EasyPrivateToken { balances.at(sender).sub(&mut context, amount, sender); balances.at(recipient).add(&mut context, amount, recipient); - - emit_unencrypted_log(&mut context, "Coins transferred"); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.. context.finish() diff --git a/yarn-project/noir-contracts/src/contracts/example_public_state_increment_BROKE/src/main.nr b/yarn-project/noir-contracts/src/contracts/example_public_state_increment_BROKE/src/main.nr index 0ec68fbb492f..719f664004ec 100644 --- a/yarn-project/noir-contracts/src/contracts/example_public_state_increment_BROKE/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/example_public_state_increment_BROKE/src/main.nr @@ -8,7 +8,6 @@ contract ExamplePublicStateIncrement { PrivateContext, PublicContext, }; - use dep::aztec::oracle::logs::emit_unencrypted_log; use dep::aztec::types::point::Point; use crate::storage::Storage; use dep::aztec::state_vars::{ diff --git a/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr index 24a725cffc32..d93fabe44241 100644 --- a/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/lending_contract/src/main.nr @@ -21,7 +21,6 @@ contract Lending { PrivateContext, PublicContext }; - use dep::aztec::oracle::{logs::emit_unencrypted_log}; use dep::aztec::public_call_stack_item::PublicCallStackItem; use crate::storage::{Storage, Asset}; use crate::safe_math::SafeU120; diff --git a/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/main.nr index b9dbbd69f9a1..32459643ebe0 100644 --- a/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/private_token_airdrop_contract/src/main.nr @@ -38,7 +38,6 @@ contract PrivateTokenAirdrop { let owner_balance = storage.balances.at(owner); if (initial_supply != 0) { send_note(&mut context, owner_balance, initial_supply, owner); - emit_unencrypted_log(&mut context, "Balance set in constructor"); } // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. @@ -60,7 +59,6 @@ contract PrivateTokenAirdrop { // Insert new note to a set of user notes and emit the newly created encrypted note preimage via oracle call. let owner_balance = storage.balances.at(owner); send_note(&mut context, owner_balance, amount, owner); - emit_unencrypted_log(&mut context, "Coins minted"); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.. context.finish() @@ -86,8 +84,6 @@ contract PrivateTokenAirdrop { // Creates new note for the recipient. let recipient_balance = storage.balances.at(recipient); send_note(&mut context, recipient_balance, amount, recipient); - - emit_unencrypted_log(&mut context, "Coins transferred"); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.. context.finish() diff --git a/yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr index 4e0529766758..81be50e4925d 100644 --- a/yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr @@ -16,12 +16,6 @@ contract PrivateToken { utils as note_utils, }; - // docs:start:unencrypted_import - - use dep::aztec::log::emit_unencrypted_log; - - // docs:end:unencrypted_import - // docs:start:storage-import use crate::storage::Storage; // docs:end:storage-import @@ -43,7 +37,6 @@ contract PrivateToken { let owner_balance = storage.balances.at(owner); if (initial_supply != 0) { send_note(&mut context, owner_balance, initial_supply, owner); - emit_unencrypted_log(&mut context, "Balance set in constructor"); } // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel. @@ -68,12 +61,6 @@ contract PrivateToken { let owner_balance = storage.balances.at(owner); send_note(&mut context, owner_balance, amount, owner); - // docs:start:unencrypted - - emit_unencrypted_log(&mut context, "Coins minted"); - - // docs:end:unencrypted - // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.. context.finish() } @@ -100,8 +87,6 @@ contract PrivateToken { // Creates new note for the recipient. let recipient_balance = storage.balances.at(recipient); send_note(&mut context, recipient_balance, amount, recipient); - - emit_unencrypted_log(&mut context, "Coins transferred"); // Return private circuit public inputs. All private functions need to return this as it is part of the input of the private kernel.. context.finish() diff --git a/yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr index 6ddc646f9516..9441e9951b8e 100644 --- a/yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr @@ -8,7 +8,11 @@ contract PublicToken { PrivateContext, PublicContext }; + + // docs:start:unencrypted_import use dep::aztec::oracle::logs::emit_unencrypted_log; + // docs:end:unencrypted_import + use crate::storage::Storage; // Constructs the contract. @@ -30,8 +34,10 @@ contract PublicToken { let storage = Storage::init(); let recipient_balance = storage.balances.at(recipient); let new_amount = recipient_balance.read() + amount; + // docs:start:unencrypted_log // TODO: Remove return value. let _hash = emit_unencrypted_log("Coins minted"); + // docs:end:unencrypted_log recipient_balance.write(new_amount); context.return_values.push(new_amount);