Skip to content

Commit

Permalink
chore: misc AVM migration prep changes (#6253)
Browse files Browse the repository at this point in the history
Remove usage of debug and header oracles in contracts which aren't yet
supported by AVM. Transpile all noir-contracts instead of only those
prefixed with `avm_` (functions are checked anyway to see if they are
tagged public-vm before transpilation).
  • Loading branch information
dbanks12 authored May 7, 2024
1 parent e4b97a8 commit fe19404
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ library Constants {
uint256 internal constant DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE =
0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631;
uint256 internal constant DEPLOYER_CONTRACT_ADDRESS =
0x0097949bb96834550868230a1b6cc242d1f662f7c52946245e4e73da1b8b2165;
0x2e9c386f07e22a1d24e677ab70407b2dd0adbc7cafb9c822bf249685d6a2e4cc;
uint256 internal constant DEFAULT_GAS_LIMIT = 1_000_000_000;
uint256 internal constant DEFAULT_TEARDOWN_GAS_LIMIT = 100_000_000;
uint256 internal constant DEFAULT_MAX_FEE_PER_GAS = 10;
Expand Down
5 changes: 1 addition & 4 deletions noir-projects/aztec-nr/aztec/src/context/interface.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use dep::protocol_types::{
abis::function_selector::FunctionSelector, address::{AztecAddress, EthAddress}, header::Header,
traits::Deserialize
};
use dep::protocol_types::{abis::function_selector::FunctionSelector, address::{AztecAddress, EthAddress}, traits::Deserialize};

use crate::context::private_context::PrivateContext;
use crate::context::public_context::PublicContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ contract GasToken {
fn pay_fee(fee_limit: Field) -> Field {
let fee_limit_u128 = U128::from_integer(fee_limit);
let fee = U128::from_integer(calculate_fee(context));
dep::aztec::oracle::debug_log::debug_log_format(
"Gas token: paying fee {0} (limit {1})",
[fee.to_field(), fee_limit]
);
// TODO(6252): implement debug logging in AVM
//dep::aztec::oracle::debug_log::debug_log_format(
// "Gas token: paying fee {0} (limit {1})",
// [fee.to_field(), fee_limit]
//);
assert(fee <= fee_limit_u128, "Fee too high");

let sender_new_balance = storage.balances.at(context.msg_sender()).read() - fee;
Expand Down
23 changes: 13 additions & 10 deletions noir-projects/noir-contracts/contracts/test_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ contract Test {
use dep::aztec::protocol_types::{
abis::private_circuit_public_inputs::PrivateCircuitPublicInputs,
constants::{MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, CANONICAL_KEY_REGISTRY_ADDRESS},
traits::{Serialize, ToField, FromField}, grumpkin_point::GrumpkinPoint, grumpkin_private_key::GrumpkinPrivateKey
traits::{Serialize, ToField, FromField}, grumpkin_point::GrumpkinPoint,
grumpkin_private_key::GrumpkinPrivateKey
};

use dep::aztec::encrypted_logs::header::EncryptedLogHeader;
Expand Down Expand Up @@ -375,10 +376,11 @@ contract Test {
assert(context.historical_header.hash() == header_hash, "Invalid header hash");
}

#[aztec(public)]
fn assert_header_public(header_hash: Field) {
assert(context.historical_header.hash() == header_hash, "Invalid header hash");
}
// TODO(4840): add AVM opcodes for getting header (members)
//#[aztec(public)]
//fn assert_header_public(header_hash: Field) {
// assert(context.historical_header.hash() == header_hash, "Invalid header hash");
//}

#[aztec(private)]
fn deploy_contract(target: AztecAddress) {
Expand Down Expand Up @@ -431,15 +433,16 @@ contract Test {
let derived_slot = derive_storage_slot_in_map(storage_slot_of_shared_mutable, address_to_get_in_registry);

// It's a bit wonky because we need to know the delay for get_current_value_in_private to work correctly
let registry_private_getter: SharedMutablePrivateGetter<Field, 5> = SharedMutablePrivateGetter::new(context, AztecAddress::from_field(CANONICAL_KEY_REGISTRY_ADDRESS), derived_slot);
let registry_private_getter: SharedMutablePrivateGetter<Field, 5> = SharedMutablePrivateGetter::new(
context,
AztecAddress::from_field(CANONICAL_KEY_REGISTRY_ADDRESS),
derived_slot
);
registry_private_getter.get_current_value_in_private()
}

#[aztec(private)]
fn test_nullifier_key_freshness(
address: AztecAddress,
public_nullifying_key: GrumpkinPoint,
) {
fn test_nullifier_key_freshness(address: AztecAddress, public_nullifying_key: GrumpkinPoint) {
assert_eq(get_npk_m(&mut context, address), public_nullifying_key);
}

Expand Down
3 changes: 2 additions & 1 deletion noir-projects/noir-contracts/scripts/transpile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
set -eu

TRANSPILER=${TRANSPILER:-../../avm-transpiler/target/release/avm-transpiler}
ls target/avm_*.json | parallel "$TRANSPILER {} {}"
ls target/*.json | parallel "$TRANSPILER {} {}"

Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ global REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = 0xe7af8166354
// CONTRACT INSTANCE CONSTANTS
// sha224sum 'struct ContractInstanceDeployed'
global DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631;
global DEPLOYER_CONTRACT_ADDRESS = 0x0097949bb96834550868230a1b6cc242d1f662f7c52946245e4e73da1b8b2165;
global DEPLOYER_CONTRACT_ADDRESS = 0x2e9c386f07e22a1d24e677ab70407b2dd0adbc7cafb9c822bf249685d6a2e4cc;

// GAS DEFAULTS
global DEFAULT_GAS_LIMIT: u32 = 1_000_000_000;
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE =
0xe7af816635466f128568edb04c9fa024f6c87fb9010fdbffa68b3d99n;
export const DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE =
0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631n;
export const DEPLOYER_CONTRACT_ADDRESS = 0x0097949bb96834550868230a1b6cc242d1f662f7c52946245e4e73da1b8b2165n;
export const DEPLOYER_CONTRACT_ADDRESS = 0x2e9c386f07e22a1d24e677ab70407b2dd0adbc7cafb9c822bf249685d6a2e4ccn;
export const DEFAULT_GAS_LIMIT = 1_000_000_000;
export const DEFAULT_TEARDOWN_GAS_LIMIT = 100_000_000;
export const DEFAULT_MAX_FEE_PER_GAS = 10;
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/simulator/src/public/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,8 @@ describe('ACIR public execution simulator', () => {
});
});

describe('Historical header in public context', () => {
// TODO(4840): add AVM opcodes for getting header (members)
describe.skip('Historical header in public context', () => {
let contractAddress: AztecAddress;
let callContext: CallContext;
let assertHeaderPublicArtifact: FunctionArtifact;
Expand Down

0 comments on commit fe19404

Please sign in to comment.