Skip to content

Commit

Permalink
test: msg sender is 0 when no entrypoint is called (#3024)
Browse files Browse the repository at this point in the history
Fixes #2949
  • Loading branch information
benesjan authored Oct 25, 2023
1 parent 0e6958c commit 53c6680
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions yarn-project/end-to-end/src/e2e_non_contract_account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SignerlessWallet, Wallet } from '@aztec/aztec.js';
import { CircuitsWasm, Fr } from '@aztec/circuits.js';
import { siloNullifier } from '@aztec/circuits.js/abis';
import { DebugLogger } from '@aztec/foundation/log';
import { toBigInt } from '@aztec/foundation/serialize';
import { TestContract } from '@aztec/noir-contracts/types';
import { AztecNode, PXE, TxStatus } from '@aztec/types';

Expand Down Expand Up @@ -43,4 +44,19 @@ describe('e2e_non_contract_account', () => {

expect(siloedNullifier.equals(expectedSiloedNullifier)).toBeTruthy();
}, 120_000);

it('msg.sender is 0 when a non-contract account calls a private function on a contract', async () => {
const contractWithNoContractWallet = await TestContract.at(contract.address, nonContractAccountWallet);

// Send transaction as arbitrary non-contract account
const tx = contractWithNoContractWallet.methods.emit_msg_sender().send();
const receipt = await tx.wait({ interval: 0.1 });
expect(receipt.status).toBe(TxStatus.MINED);

const logs = (await tx.getUnencryptedLogs()).logs;
expect(logs.length).toBe(1);

const msgSender = toBigInt(logs[0].log.data);
expect(msgSender).toBe(0n);
}, 120_000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ impl TestPrivateContextInterface {
}


pub fn emit_msg_sender(
self,
context: &mut PrivateContext
) -> [Field; RETURN_VALUES_LENGTH] {
let mut serialized_args = [0; 0];

context.call_private_function(self.address, 0x11fb5d45, serialized_args)
}


pub fn emit_nullifier(
self,
context: &mut PrivateContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ contract Test {
context::get_portal_address,
rand::rand
},
log::emit_unencrypted_log_from_private,
types::vec::BoundedVec,
constants_gen::EMPTY_NULLIFIED_COMMITMENT,
};
Expand Down Expand Up @@ -124,6 +125,12 @@ contract Test {
context.push_new_nullifier(nullifier, EMPTY_NULLIFIED_COMMITMENT);
}

#[aztec(private)]
fn emit_msg_sender() {
// Note: don't use emit_unencrypted_log_from_private in production code
emit_unencrypted_log_from_private(&mut context, context.msg_sender());
}

// docs:start:is-time-equal
#[aztec(public)]
fn is_time_equal(
Expand Down

0 comments on commit 53c6680

Please sign in to comment.