cairo-contracts icon indicating copy to clipboard operation
cairo-contracts copied to clipboard

Need `--account-contract` flag when importing `IAccount`

Open pscott opened this issue 2 years ago • 12 comments

IAccount exopses the __execute__ function which gets the cairo-compiler to yell and error like this:

Only account contracts may have a function named "__execute__". Use --account-contract flag.

        Failed

Unfortunately this means I can't write a contract that includes IAccount without adding the --account-contract flag (which is plain wrong because I'm NOT writing an account contract but simply interacting with one!).

Not sure OZ can do anything about it, I think we need to address this to the StarkWare team but just putting it out there :)

pscott avatar May 20 '22 12:05 pscott

Agree with this. I don't think this flag makes much sense cc/@bbrandtom. If the idea is to protect users from mis-deploying (not sure if that's a good idea either), then the filter should be on deployment not compilation.

Do consider @JulissaDantes' suggestion of using a language directive.

martriay avatar May 20 '22 22:05 martriay

I was unable to reproduce the issue.

What do you mean by IAccount exopses the __execute__? IAccount only defines an interface, it does not define any @external entry point.

ilyalesokhin-starkware avatar May 25 '22 11:05 ilyalesokhin-starkware

@ilyalesokhin-starkware thanks for having a look at this!

Here's a minimal working (failing) example. I'm trying to compile it with 0.8.2.1 and it's giving me the error I mentioned in the OP.

https://gist.github.com/pscott/aa99849a1e1b53f2eaed3f71de642e8e

pscott avatar May 25 '22 11:05 pscott

The example compiles on my machine.

Are you sure you didn't change one of the imported files to include an __execute__ entrypoint?

ilyalesokhin-starkware avatar May 25 '22 11:05 ilyalesokhin-starkware

Interesting... I'm using 0.1.0 of openzeppelin-cairo-contracts dependency. Are you running this version too? (installed via pip3 install openzeppelin-cairo-contracts)

I have not added any __execute__ entrypoint.

Maybe someone else can reproduce?

pscott avatar May 25 '22 11:05 pscott

Also it should be noted that I'm using the starknet hardhat plugin and running npx hardhat starknet-compile in order to compile.

pscott avatar May 25 '22 11:05 pscott

This is related to the #291 and it's already fixed in the main branch of openzeppelin-cairo-contracts.

openzeppelin-cairo-contracts v0.1.0 is broken.

ilyalesokhin-starkware avatar May 26 '22 07:05 ilyalesokhin-starkware

All right so I guess problem solved! So I guess you testing with a local clone of the OZ repo?

@martriay @andrew-fleming do you think OZ could issue a 0.1.1 while waiting for 0.2.0? Would be really nice to be able to use Accounts right now :D

pscott avatar May 26 '22 09:05 pscott

Your guess is correct, my first attempt to reproduce the issue failed as I fetched the most recent master from the OZ repo.

ilyalesokhin-starkware avatar May 26 '22 09:05 ilyalesokhin-starkware

All right so I guess problem solved! So I guess you testing with a local clone of the OZ repo?

@martriay @andrew-fleming do you think OZ could issue a 0.1.1 while waiting for 0.2.0? Would be really nice to be able to use Accounts right now :D

No, we're really close to 0.2.0 and it would be a ton of work to cherrypick non-breaking changes to release 0.1.1.

I still think the flag is problematic and I vote for removing it, see https://github.com/OpenZeppelin/nile/pull/112 for example.

martriay avatar May 26 '22 16:05 martriay

@martriay why do you think the flag is problematic? Why an 'account' directive will be better?

bbrandtom avatar May 30 '22 06:05 bbrandtom

@martriay why do you think the flag is problematic? Why an 'account' directive will be better?

Because you can't just compile all the contracts on a project, and there's no easy nor reliable way to identify them. It's also unclear to me the added value.

A directive I would assume serves the same purpose you intend to give it, without interfering with compilation/tooling and if anything, providing a way for tooling to circumvent the issue.

martriay avatar Jun 15 '22 03:06 martriay

Closing this since it will not be relevant anymore after the ongoing Cairo 1.0 migration. If you think this is a mistake, feel free to open a new issue.

martriay avatar Feb 16 '23 21:02 martriay