crytic / crytic-compile

Abstraction layer for smart contract build systems
GNU Affero General Public License v3.0
149 stars 84 forks source link

Natspec: parse custom fields #295

Open montyly opened 1 year ago

montyly commented 1 year ago
% cat test.sol
contract A{

    /**
     * @custom:customfield
     * @notice This is the notice
     * @param a This is a
     * @param b This is b
     */
     function test(uint a, uint b) public{

     }

}

% cat test.py
from slither import Slither

sl = Slither("test.sol")

compilation_unit = sl.compilation_units[0]

natspec = compilation_unit.crytic_compile_compilation_unit.natspec["A"]

print(natspec.userdoc.export())
print(natspec.devdoc.export())

% python test.py
{'methods': {}, 'notice': None}
{'methods': {'test(uint256,uint256)': {'author': None, 'details': None, 'params': {'a': 'This is a', 'b': 'This is b'}, 'return': None}}, 'author': None, 'details': None, 'title': None}

Here we are missing some of the fields of the natspec, while they are provided by solc:

% solc test.sol --devdoc

{"kind":"dev","methods":{"test(uint256,uint256)":{"custom:customfield":"@notice This is the notice","params":{"a":"This is a","b":"This is b"}}},"version":1}
Troublor commented 6 months ago

Any plans to implement this feature?