juanfranblanco / vscode-solidity

Visual Studio Code language support extension for Solidity smart contracts in Ethereum https://marketplace.visualstudio.com/items?itemName=JuanBlanco.solidity
MIT License
892 stars 190 forks source link

Solidity error highlighting, very slow or in improper locations #401

Open 0xMedici opened 1 year ago

0xMedici commented 1 year ago

Hello!

The error highlighting in solidity has been pretty out of wack recently. It highlights correct code as errors and glosses over incorrect code without reporting anything. I reverted to an older version of the extension (from ~5 months ago) to try that out and it also has a hard time catching any existing errors on a document.

Thank you for all you've done so far by providing this extension! Any help here would be much appreciated.

FHieser commented 1 year ago

Same thing for me. On a Ubuntu system. In addition intellisense autocompletion also doesnt work for me. When I press ctrl+space-bar for autocompletion one of my CPUs goes straight to 100% workload but it doesnt load any possible suggestions. I noticed it because my laptop sounds like a helicopter every time I use vscode at the moment xD.

It seems to me that there is something with the auto recognition that slows the whole system so much it doesnt update properly. @juanfranblanco Thank you very much for making this extension and keep up the great work :D

0xfoudy commented 1 year ago

Are you working with Foundry? I am experiencing similar issues with Foundry, specially when i open a .t.sol and a .sol.

FHieser commented 1 year ago

Are you working with Foundry? I am experiencing similar issues with Foundry, specially when i open a .t.sol and a .sol.

Yes correct

juanfranblanco commented 1 year ago

Can you provide me some example project? To speed up things. Edit: But I guess is foundry / integration related.

FHieser commented 1 year ago

Sadly no The project I'm currently working on is in an internal development stage, so I wont be able to share it, but I can give some general info:

FHieser commented 1 year ago

Can you provide me some example project? To speed up things. Edit: But I guess is foundry / integration related.

Would this integration come from the vscode-solidity side or from the foundry side? I could write up an issue on their project if its the second

juanfranblanco commented 1 year ago

@FHieser I don't know, I think it might be on the Foundry side, but I would like to test it regardless, Ill try to take a full day for this in a couple of days, with a fresh ubuntu machine etc.

0xfoudy commented 1 year ago

Sadly no The project I'm currently working on is in an internal development stage, so I wont be able to share it, but I can give some general info:

  • it seems to be only happening in foundry Testfiles (.t.sol)
  • The file I'm currently working on has around 700 Lines of code
  • Implementing forge test and console
  • The implementation of forge test does not happen directly in the given testfile, but via inheritance (we have a few contracts with similar structures, that inherit from a single contract so creating a common base file made sense)

I have the same issue even with the default forge init code. Opening any .t.sol causes it (however even the .sol are affected by the slowness afterwards). I have installed v0.0.141 and it seems to be working better (still pretty slow, needed 2 or 3 seconds to auto complete but at least it does the job!)

juanfranblanco commented 1 year ago

@f-hannoun how many files / dependencies you have? Edit: Roughly ..

0xfoudy commented 1 year ago

@f-hannoun how many files / dependencies you have? Edit: Roughly ..

I only have imported "forge-std/Test.sol"; and the contract i'm testing itself (very basic counter that is generated when I Initialize a Foundry project)

juanfranblanco commented 1 year ago

Ok thanks!

FHieser commented 1 year ago

I created an issue for this on the foundryside too (https://github.com/foundry-rs/book/issues/858) maybe you guys can connect over it :)

0xMedici commented 1 year ago

Can you provide me some example project? To speed up things. Edit: But I guess is foundry / integration related.

I'm unable to provide the project example due because its internal project as well. However, I am using hardhat (not foundry) so I don't think the problem is isolated to foundry related dependencies.

juanfranblanco commented 1 year ago

Hi, I have built a new Ubuntu image, installed a new version of the solidity plugin, foundry and everything seems fine. I wonder if it is due to an update on vscode itself. soldity-auto-complete solidity-forge-formatter

I am using @PaulRBerg project as the test

DangyWing commented 1 year ago

@juanfranblanco I made an example project you can test with https://github.com/DangyWing/vscode-solidity-test

juanfranblanco commented 1 year ago

Thanks !!

juanfranblanco commented 1 year ago

@DangyWing Apologies for the delay.. having problems with my machine and vm. solidity-autocomplete-Issue-Animal2 I think something is funny as I don't have any issues.

This is a clean machine only vscode and vscode-solidity installed.

juanfranblanco commented 1 year ago

Ok, actually reading the instructions i see the issue with solmate. Looking at it now.

juanfranblanco commented 1 year ago

The issue is that peggy is slow on this statement

   function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");

        // Unchecked because the only math done is incrementing
        // the owner's nonce which cannot realistically overflow.
        unchecked {

            address recoveredAddress = ecrecover(
                keccak256(
                    abi.encodePacked(
                        "\x19\x01",
                        DOMAIN_SEPARATOR(),
                        keccak256(
                            abi.encode(
                                keccak256(
                                    "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
                                ),
                                owner,
                                spender,
                                value,
                                nonces[owner]++,
                                deadline
                            )
                        )
                    )
                ),
                v,
                r,
                s
            );

        }

    }
DangyWing commented 1 year ago

@juanfranblanco I dug a little deeper and found that the slowness may be because of the nested keccak256() and abi.encode() calls. Assuming you have installed solmate, go to lib/solmate/src/tokens/ERC20.sol and replace the permit() function you shared above with the following code block and intellisense seems snappy again. Although the following code did pass the solmate tests, please do not use in production or even testing for that matter

    function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
        public
        virtual
    {
        require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");

        // Unchecked because the only math done is incrementing
        // the owner's nonce which cannot realistically overflow.
        unchecked {
            address recoveredAddress =
                ecrecover(encodeDomainSeparatorWithPermitData(owner, spender, value, deadline), v, r, s);

            require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");

            allowance[recoveredAddress][spender] = value;
        }

        emit Approval(owner, spender, value);
    }

    function hashPermitString() public pure returns (bytes32) {
        return keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
    }

    function encodePermitData(address owner, address spender, uint256 value, uint256 deadline)
        public
        returns (bytes32)
    {
        return keccak256(abi.encode(hashPermitString(), owner, spender, value, nonces[owner]++, deadline));
    }

    function encodeDomainSeparatorWithPermitData(address owner, address spender, uint256 value, uint256 deadline)
        public
        returns (bytes32)
    {
        return keccak256(
            abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), encodePermitData(owner, spender, value, deadline))
        );
    }
juanfranblanco commented 1 year ago

@DangyWing yes I it is due to that, thank you, i think i managed to get it more performant, checking the parser now.

juanfranblanco commented 1 year ago

Updated parser https://github.com/juanfranblanco/solparse/commit/55fba7ef4ff0e78a69e0ecd8c9c0bb4ef10d2297

juanfranblanco commented 1 year ago

@DangyWing @0xMedici @f-hannoun @FHieser Please check the latest and let me know how it goes, updated tthe parser etc.. so far so good on my end with that contract.

FHieser commented 1 year ago

Looks good :+1:

varun-doshi commented 1 year ago

Any standard solution found for this? I have a foundry setup with Open Zeppelin contracts installed. On writing test and script files(.t.sol and .s.sol respectively), the intellisense is very late(almost 6-7 seconds). Intellisense runs perfectly on .sol files

0xfoudy commented 1 year ago

Any standard solution found for this? I have a foundry setup with Open Zeppelin contracts installed. On writing test and script files(.t.sol and .s.sol respectively), the intellisense is very late(almost 6-7 seconds). Intellisense runs perfectly on .sol files

Make sure you have the latest version of the extension? Problem seems to be solved since April