Anonymous123xx / RLRep

A project to automatically generate program repair recommendation in the field of smart contracts for given code snippets with their contexts. The source code and dataset are opened.
11 stars 5 forks source link

Training and evaluation error #2

Closed Mokita-J closed 7 months ago

Mokita-J commented 7 months ago

Hey!

I followed the usage instructions provided in the README but I can't seem to run main.py like suggested. This is the error:

pwd/RLRep$ python main.py multistep_RLRep dataset_vul/newALLBUGS
ANTLR runtime and generated code versions disagree: 4.9.3!=4.7.2
ANTLR runtime and generated code versions disagree: 4.9.3!=4.7.2
line 1:0 mismatched input 'if' expecting {'function', 'constructor', 'fallback', 'receive'}
line 1:9 mismatched input '<=' expecting {',', ')'}
line 1:21 mismatched input '[' expecting {';', '{', 'returns'}
Traceback (most recent call last):
  File "main.py", line 59, in <module>
    for step, batch in enumerate(get_batch(code_dir, ast_dir, config, in_w2i, pretrain=True)):
  File "pwd/RLRep/utils2.py", line 55, in get_batch
    for code_sequence, ast_sequence, contract in code_ast2index(in_w2i, config, path_code, path_ast):
  File "pwd/RLRep/utils2.py", line 22, in code_ast2index
    for tup in get_one(path_code, path_ast):
  File "pwd/sc_study/RLRep/utils2.py", line 37, in get_one
    output = tree.toCodeSequence()
AttributeError: 'FunctionDefinitionContext' object has no attribute 'toCodeSequence'

Could you provide some insights on this matter? Thx!

Anonymous123xx commented 7 months ago

A modification step is necessary before executing the main.py

  1. You need to enter the antlr4 package and find the RuleContext.py and Trees.py (Some IDEs such as PyCharm can implement this process).

  2. Add the method code below in the RuleContext class in RuleContext.py.

    def toCodeSequence(self, ruleNames:list=None, recog:Parser=None):
    return Trees.toCodeSequence(self, ruleNames=ruleNames, recog=recog)
  3. Add the method code below in the Trees class in Trees.py.

    @classmethod
    def toCodeSequence(cls, t:Tree, ruleNames:list=None, recog:Parser=None):
        if recog is not None:
            ruleNames = recog.ruleNames
        s = escapeWhitespace(cls.getNodeText(t, ruleNames), False)
        if t.getChildCount()==0:
            return s
        with StringIO() as buf:
            buf.write(s)
            buf.write(' ')
            for i in range(0, t.getChildCount()):
                if i > 0:
                    buf.write(' ')
                buf.write(cls.toCodeSequence(t.getChild(i), ruleNames))
    
            return buf.getvalue()
Mokita-J commented 7 months ago

Thanks for the info! I got through the first training epochs.

But I can't still complete the training. This is the error I get:

Traceback (most recent call last):
  File "main.py", line 72, in <module>
    loss = model(batch[:-1], True, batch[-1])
  File "/RLRep/.venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/RLRep/multistep_RLRep.py", line 388, in forward
    return self.train_on_batch(inputs, contracts)
  File "/RLRep/multistep_RLRep.py", line 410, in train_on_batch
    res = choose_action(contracts[i], preds[i], True)
  File "/RLRep/utils2.py", line 708, in choose_action
    rew = fitness_function2(contract_path, repair_path)
  File "/RLRep/utils2.py", line 101, in fitness_function2
    contract_sims = get_similarity(original_contract, first=False)
  File "/RLRep/similarity_compute.py", line 66, in get_similarity
    context1_npy = np.load(context1_npy_path)
  File "/RLRep/.venv/lib/python3.8/site-packages/numpy/lib/npyio.py", line 417, in load
    fid = stack.enter_context(open(os_fspath(file), "rb"))
FileNotFoundError: [Errno 2] No such file or directory: 'FastText/bugEmbedding/0context1.npy'

It seems I am missing some files to calculate the similarity. Any suggestions to surpass this error?

Thx for the help!

Anonymous123xx commented 7 months ago

Download the corresponding files from Zenodo. Please refer to Readme file.

Mokita-J commented 7 months ago

Great! Thanks for the prompt reply But there are still some missing files like: solidity-extractor/function.js this file is needed according to this line.

This is the error I encounter during training:

Node.js v20.12.0
node:internal/modules/cjs/loader:1146
  throw err;
  ^

Error: Cannot find module '/home/mokita/sc_study/RLRep/solidity-extractor/function.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
    at Module._load (node:internal/modules/cjs/loader:984:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Thanks for all the help so far! RLRep is a really cool tool, can't wait to test it out :)

Anonymous123xx commented 7 months ago

The corresponding files are updated.