Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.

feat: account cairo1 helpers class upgrade #1105

Closed
wants to merge 4 commits into from

Conversation

enitrat
Copy link
Collaborator

@enitrat enitrat commented Apr 16, 2024

Time spent on this PR: 0.5d

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

First step for #1095

What is the new behavior?

  • Adds a storage var to accounts to store the Cairo1Helpers class. Update upgradeability mechanism to pull the latest version when required.

This change is Reviewable

@enitrat enitrat force-pushed the feat/account-cairo1helpers-class branch from 7b664cc to 80a0c47 Compare April 16, 2024 15:16
@@ -136,8 +140,27 @@ func __execute__{
let latest_class = AccountContract.get_latest_class();
Copy link
Member

Choose a reason for hiding this comment

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

update the get_latest_class to get_latest_classes and return latest account class and latest helper class.

Comment on lines 159 to 161
let pedersen_ptr = cast([ap - 1], HashBuiltin*);
let range_check_ptr = [ap - 2];
let syscall_ptr = cast([ap - 3], felt*);
Copy link
Member

Choose a reason for hiding this comment

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

write in the order of the branches, ie ap-3, ap-2, ap-1

@@ -38,50 +72,57 @@ async def test_should_upgrade_outdated_account_on_transfer(
new_account,
other,
class_hashes,
cleanup,
Copy link
Member

Choose a reason for hiding this comment

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

use @pytest.mark.usefixture("cleanup") instead of requesting it as an (unused) argument.
you can also define the fixture with @pytest.fixture(autouse=True) if you want it to be used for all the tests

)


async def assert_transfer_success(erc20_token, new_account, other):
Copy link
Member

Choose a reason for hiding this comment

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

maybe use the Counter.inc() instead as this is not really minimal to illustrate the fact that the original tx is well processed even though we actually upgrade the classe

@enitrat
Copy link
Collaborator Author

enitrat commented Apr 17, 2024

#1107

@enitrat enitrat closed this Apr 17, 2024
let (kakarot_address) = Ownable_owner.read();
let (this_cairo1helpers_class) = Account_cairo1_helpers_class_hash.read();

if (latest_cairo1helpers_class != this_cairo1helpers_class) {
Copy link
Member

Choose a reason for hiding this comment

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

what if we change the helper but not the account class? I think that they need to be in separate branches, and that overall the function can be simplified like

let (account_class, helpers_class) = AccountContract.get_latest_classes();
let (this_helpers_class) = Account_helpers_class_hash.read();

if (helpers_class != this_cairo1helpers_class) {
    // Note this could be done in any cases but would cost a useless write
    Account_cairo1_helpers_class_hash.write(latest_cairo1helpers_class);
}

// Do the call with the latest account class, possibly same class, works in all the cases
let (response_len, response) = IAccount.library_call___execute__(
    class_hash=latest_account_class,
    call_array_len=call_array_len,
    call_array=call_array,
    calldata_len=calldata_len,
    calldata=calldata,
);

we don't need to actually store the implementation if we always call kakarot to actually check what is the implementation.

@enitrat enitrat deleted the feat/account-cairo1helpers-class branch April 29, 2024 08:27
matthieuauger pushed a commit to matthieuauger/kakarot that referenced this pull request Nov 9, 2024
* add txpool_inspect

* fix comment

* fix clippy
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants