Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Initial cheatcode loadPublic #1353

Merged
merged 10 commits into from
Aug 3, 2023
Merged

feat: Initial cheatcode loadPublic #1353

merged 10 commits into from
Aug 3, 2023

Conversation

LHerskind
Copy link
Contributor

@LHerskind LHerskind commented Aug 1, 2023

Description

Fixes #1281.

Introduces an initial CheatCodes class that will contain the non-intrusive cheatcodes, and can later be altered as a fork of the node.

Checklist:

  • I have reviewed my diff in github, line by line.
  • Every change is related to the PR description.
  • I have linked this pull request to the issue(s) that it resolves.
  • There are no unexpected formatting changes, superfluous debug logs, or commented-out code.
  • The branch has been merged or rebased against the head of its merge target.
  • I'm happy for the PR to be merged at the reviewer's next convenience.

@LHerskind LHerskind added the A-internal-devex Area: Relates to the devex of internal teams building Aztec. label Aug 2, 2023
@LHerskind LHerskind marked this pull request as ready for review August 2, 2023 07:37
import { AztecRPC } from '@aztec/types';

const toFr = (what: Fr | bigint): Fr => {
return typeof what === 'bigint' ? new Fr(what) : what;
Copy link
Contributor

Choose a reason for hiding this comment

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

😂 "what"

Copy link
Member

Choose a reason for hiding this comment

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

may i suggest "value" hahah

@@ -95,7 +104,12 @@ describe('e2e_public_token_contract', () => {
expect(receipts.map(r => r.status)).toEqual(times(3, () => TxStatus.MINED));
expect(receipts.map(r => r.blockNumber)).toEqual(times(3, () => receipts[0].blockNumber));

await expectAztecStorageSlot(logger, aztecRpcServer, contract, balanceSlot, recipient.toField(), mintAmount * 3n);
const balance = await cc.l2.loadPublic(
Copy link
Contributor

Choose a reason for hiding this comment

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

given how often this is used, we can probably make another helper like getPublicBalanceOf(contractAddress, balanceSlot, recipient) that calls this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, what is the reason for not using a view function? If supported, seems like it would be much more clear then 🤷

Copy link
Member

@Maddiaa0 Maddiaa0 left a comment

Choose a reason for hiding this comment

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

lgtm, mostly naming nits etc

@@ -533,35 +540,6 @@ export async function calculateAztecStorageSlot(slot: bigint, key: Fr): Promise<
return storageSlot; //.value;
Copy link
Member

Choose a reason for hiding this comment

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

This function can be removed now the cheat code exists

@@ -72,7 +75,13 @@ describe('e2e_public_token_contract', () => {
const receipt = await tx.getReceipt();

expect(receipt.status).toBe(TxStatus.MINED);
await expectAztecStorageSlot(logger, aztecRpcServer, contract, balanceSlot, recipient.toField(), mintAmount);

const balance = await cc.l2.loadPublic(
Copy link
Member

Choose a reason for hiding this comment

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

I prefered the shortness of the previous diff, i agree with rahul a helper function can be used here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I redid it as this using the cheatcodes mainly to make the check that was performed more explicit.

public logger = createDebugLogger('aztec:cheat_codes:l1'),
) {}

async rpcCall(method: string, params: string) {
Copy link
Member

Choose a reason for hiding this comment

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

params would be more conviently an array that gets converted into a string in this method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ye, used a string as I just recalled there being some weirdness with how the params were passed, but might just be a weird initial setup. Will change it.

contract.address,
cc.l2.computeSlotInMap(2n, account.address.toField()),
);
storageValues['private_debt'] = await cc.l2.loadPublic(contract.address, cc.l2.computeSlotInMap(3n, accountKey));
Copy link
Member

Choose a reason for hiding this comment

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

utility funcs for stuff like this would read nicer

* @param slot - The storage slot to lookup
* @returns The value stored at the given slot
*/
public async loadPublic(who: AztecAddress, slot: Fr | bigint): Promise<Fr> {
Copy link
Member

Choose a reason for hiding this comment

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

load public is a bit ambiguous as a name, load public slot it more explicit
who could also just be address.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Were using this naming to make it closer to foundry cheatcodes.

@Maddiaa0 Maddiaa0 enabled auto-merge (squash) August 2, 2023 13:43
@Maddiaa0 Maddiaa0 disabled auto-merge August 2, 2023 13:43
@LHerskind LHerskind merged commit 75c35a7 into master Aug 3, 2023
@LHerskind LHerskind deleted the lh/1281 branch August 3, 2023 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-internal-devex Area: Relates to the devex of internal teams building Aztec.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

feat(CheatCode): loadPublic(who, slot)
3 participants