vscode-solidity icon indicating copy to clipboard operation
vscode-solidity copied to clipboard

Solidity error highlighting, very slow or in improper locations

Open 0xMedici opened this issue 1 year ago • 26 comments

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.

0xMedici avatar Mar 22 '23 15:03 0xMedici

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

FHieser avatar Mar 27 '23 13:03 FHieser

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

0xfoudy avatar Mar 28 '23 08:03 0xfoudy

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

Yes correct

FHieser avatar Mar 28 '23 13:03 FHieser

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

juanfranblanco avatar Mar 28 '23 15:03 juanfranblanco

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)

FHieser avatar Mar 29 '23 09:03 FHieser

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

FHieser avatar Mar 29 '23 09:03 FHieser

@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.

juanfranblanco avatar Mar 29 '23 09:03 juanfranblanco

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!)

0xfoudy avatar Mar 29 '23 09:03 0xfoudy

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

juanfranblanco avatar Mar 29 '23 09:03 juanfranblanco

@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)

0xfoudy avatar Mar 29 '23 09:03 0xfoudy

Ok thanks!

juanfranblanco avatar Mar 29 '23 09:03 juanfranblanco

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 :)

FHieser avatar Mar 29 '23 09:03 FHieser

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.

0xMedici avatar Mar 29 '23 12:03 0xMedici

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

juanfranblanco avatar Apr 04 '23 14:04 juanfranblanco

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

DangyWing avatar Apr 04 '23 16:04 DangyWing

Thanks !!

juanfranblanco avatar Apr 04 '23 17:04 juanfranblanco

@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 avatar Apr 07 '23 13:04 juanfranblanco

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

juanfranblanco avatar Apr 07 '23 13:04 juanfranblanco

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
            );
            
        }

    }

juanfranblanco avatar Apr 07 '23 14:04 juanfranblanco

@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))
        );
    }

DangyWing avatar Apr 10 '23 14:04 DangyWing

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

juanfranblanco avatar Apr 10 '23 15:04 juanfranblanco

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

juanfranblanco avatar Apr 12 '23 16:04 juanfranblanco

@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.

juanfranblanco avatar Apr 12 '23 16:04 juanfranblanco

Looks good :+1:

FHieser avatar Apr 13 '23 08:04 FHieser

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

varun-doshi avatar Sep 06 '23 08:09 varun-doshi

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

0xfoudy avatar Sep 21 '23 05:09 0xfoudy