Cointime

Download App
iOS & Android

How Effective Is GPT for Auditing Smart Contracts?

Introduction

Recently, ChatGPT has gained a great deal of popularity, impressing its users with its capacity to enhance traditional text, work efficiency, and provide concise overviews. Following closely behind is CodeGPT, a GPT-based plugin that further enhances coding efficiency. With the recent release of GPT-4, can it be applied to auditing blockchain and Solidity smart contracts? Based on this question, we conducted various feasibility tests.’

Testing Environment and Methodology

The comparison models used in this test are: GPT-3.5(Web),GPT-3.5-turbo-0301,GPT-4(Web).

Prompt used in the test: Help me discover vulnerabilities in this Solidity smart contract.

Comparison of Vulnerability Code Snippet Detectio

We performed three rounds of testing. In tests 1 and 2, we utilized historical vulnerability codes commonly encountered in the past as test cases to evaluate the model’s ability to detect fundamental vulnerabilities. In Test 3, we introduced moderately challenging vulnerability codes as the primary test cases.

Test 1:

Example: “Intro to Smart Contract Audit Series: Phishing With tx.orgin”

Vulnerability Code:

Sent to GPT:

GPT-3.5(Web) Response:

GPT-3.5-turbo-0301 Response:

GPT-4(Web) Response:

As you can see from the results, all three models identified critical issues related to tx.origin.

Test 2:

Example: “Intro to Smart Contract Security Audits | Overflow”

Sent to GPT:

GPT-3.5(Web) Response:

GPT-3.5-turbo-0301 Response:

GPT-4(Web) Response:

It is worth noting that both GPT-3.5 (Web) and gpt-3.5-turbo-0301 were able to identify a critical overflow vulnerability, whereas surprisingly, GPT-4 (Web) did not provide any relevant prompt.

Test 3:

Example: “Empty-handed with a White Wolf — Analysis of the Popsicle Hack”

Sent to GPT:

GPT-3.5(Web) Response:

GPT-3.5-turbo-0301 Response:

Looking at the results,, we can see that none of the three versions detected any of the critical vulnerability points.

Summary of Code Snippet Detection

While the GPT models displayed adequate detection capabilities for simple vulnerability code snippets, it falls short when it comes to identifying more complex ones. Throughout the tests, GPT-4 (Web) showcased exceptional readability and a clear output format. However, its ability to audit code does not appear to surpass that of GPT-3.5 (Web) or GPT-3.5-turbo-0301. In some cases, due to the inherent uncertainties in the transformer output, GPT-4 (Web) managed to overlook certain critical issues.

Comparative Detection of Known Vulnerabilities in Full Contracts

To better accommodate the practical requirements of projects during contract audits, we raised the difficulty level by importing contracts with an extensive codebase. This allowed us to comprehensively test the GPT-4 model’s auditing capabilities, as opposed to GPT-3 which has a smaller contextual character limit and thus was not evaluated in this context.

For this instance, we used previous case studies as a test template to simulate real-world scenarios:

Example: “Detailed analysis of the $31 Million MonoX Protocol Hack”.

To initiate the audit, we inputted the complete contract in batches and submitted a vulnerability detection request towards the end of the dialogue.

The following prompt was utilized for this test:

“Here is a Solidity smart contract”

Insert Contract Code

“The above is the complete code,help me discover vulnerabilities in this smart contract.”

As demonstrated, despite GPT-4 having the highest single input character limit, according to the information published by OpenAI, it still encountered contextual challenges due to text overflow during the final vulnerability detection request. Consequently, the model can only identify a portion of the content, rendering it incapable of conducting a thorough contextual audit for large-scale contracts.

Batched Auditing: Unpacked Contracts through Incremental Input and Detection:

Prompt 1:

“Help me discover vulnerabilities in this Solidity smart contract.”

Batch 1 of the contract code.

Prompt 2:

“Help me discover vulnerabilities in this Solidity smart contract.”

Batch 2 of the contract code.

Prompt 3:

“Help me discover vulnerabilities in this Solidity smart contract.”

Batch 3 of the contract code.

It is worth mentioning that GPT-4 failed to identify any critical vulnerability points.

Summary: While the current state of GPT’s capabilities may not be entirely suitable for contract analysis, the potential of AI in this domain remains impressive.

Advantages:

While GPT’s detection capabilities for complex vulnerabilities in contract code may be limited, it has shown impressive partial detection capabilities for basic and simple vulnerabilities. Additionally, once a vulnerability is identified, the model provides an explanation in an easily understandable and user-readable format. This unique feature is especially beneficial for novice contract auditors who require quick guidance and straightforward answers during their initial training phase.

Challenges:

There is a certain amount of variation in GPT’s output for each dialogue, which can be adjusted through API interface parameters. However, the output is still not constant. Although such variability is beneficial for language dialogues and greatly enhances the authenticity of the conversation, it is not ideal for code analysis work. In order to cover multiple possible vulnerability answers that AI may provide, we had to make multiple requests for the same question and compare and filter the results. This inadvertently increases the workload, ultimately undermining the fundamental objective of AI in assisting humans to improve their efficiency.

For instance, we conducted an additional test by running Test 2 of the Comparison of Vulnerability Code Snippet Detection with a slight modification of the function name before generating again.

As we can see, its output results have added some additional content compared to the previous test.

There is still significant room for improvement in its vulnerability analysis capabilities.

It is worth noting that the current (as of March 16, 2024) training models of GPT are unable to accurately analyze and identify critical vulnerability points for slightly complex vulnerabilities.

Despite the current limitations of GPT’s analysis and mining capabilities for contract vulnerabilities, its ability to analyze and generate reports on simple code blocks for common vulnerabilities still sparks excitement among users. With continued training and development of GPT and other AI models, we firmly believe that assisted auditing of large and complex contracts will achieve faster, more intelligent, and more comprehensive outcomes in the foreseeable future. As technological development exponentially improves human efficiency, a transformative shift is imminent. We eagerly anticipate the benefits of AI in enhancing blockchain security and remain vigilant in monitoring the impact of emerging AI products on this vital field. In the visible future, we will inevitably integrate with AI to some extent. May AI and blockchain be with you.

Read more: https://slowmist.medium.com/how-effective-is-gpt-for-auditing-smart-contracts-cdeddfa76dbe

Comments

All Comments

Recommended for you

  • Trump to Hold Midterm Election Rally in Kentucky on October 17

    On October 13, the Republican National Committee announced that Trump will hold a midterm election rally in Kentucky on October 17. (Bloomberg)

  • Al Masirah TV: Yemen Oil Company in Sanaa Attacked

    Al Masirah TV, controlled by the Houthi forces, reported that the Yemen Oil Company located in Sanaa was attacked. (Jinshi)

  • Goldman Sachs CEO Solomon: We Are Very Cautious About AI Risk Underwriting and Capital Investment

    On October 13, Goldman Sachs CEO Solomon stated that we are very cautious about underwriting risks and capital investment in artificial intelligence, especially as clients' financing needs become larger and more complex.

  • U.S. Stocks Open: Philadelphia Semiconductor Index Drops Over 2%

    At the start of trading, the Philadelphia Semiconductor Index fell over 2%, with memory chip stocks broadly declining. Goldman Sachs rose about 3%, while Apple's stock price reached a new all-time high. The Dow Jones Industrial Average increased by 0.8%, the S&P 500 Index fell by 0.1%, and the Nasdaq dropped by 0.4%. Memory chip stocks saw widespread declines, with SK Hynix down about 6%, Western Digital down about 6%, SanDisk down about 4%, Micron Technology down about 6%, and Seagate Technology down about 7%. Optical communication stocks also fell, with Marvell Technology down about 6%, Corning down about 4%, Coherent down about 3%, Credo down about 4%, and Lumentum down about 3%. Goldman Sachs rose about 3%, reporting Q3 net revenue of $18.68 billion, with stock trading revenue surging by 72%. Wells Fargo fell by 0.5%, as the company's Q3 revenue fell short of expectations. JPMorgan Chase rose about 3%, with Q3 adjusted revenue of $50.9 billion also missing expectations, and fixed income trading revenue unexpectedly declined by 4%. Citigroup rose by 0.3%, having previously announced its Q3 financial results. Apple's stock price increased by about 2%, setting a new historical high.

  • Philadelphia Semiconductor Index Drops 3% in Early Trading

    On October 13, the Philadelphia Semiconductor Index fell 3% in early trading, currently reported at 11,867.80 points. Nvidia dropped 1.18%, Broadcom fell 1.64%, Micron decreased by 5.94%, Intel declined 2.95%, AMD fell 3.84%, Qualcomm dropped 0.26%, TSMC decreased by 1.39%, and ASML fell 2.61%.

  • All Three Major U.S. Stock Indices Turn Positive

    On October 13, the Dow Jones Industrial Average rose by 0.46%, the S&P 500 increased by 0.07%, and the Nasdaq Composite gained 0.01%.

  • BlackRock President and Fed Governor Waller: France's Fiscal Pressure Sounds Alarm for High-Deficit Countries

    On October 13, Jon Gray, President of BlackRock, and Christopher Waller, a Governor of the Federal Reserve, stated that the fiscal pressure faced by France serves as a warning for governments with high spending. However, due to the significantly higher growth rate of the U.S. economy, these risks are not as urgent in the United States.

  • U.S. Stocks Open with Significant Decline in Storage Sector

    On October 13, U.S. stocks opened with the Dow Jones up 0.47%, the S&P 500 down 0.14%, and the Nasdaq down 0.38%. The storage sector saw a significant decline, with Western Digital (WDC.O) and Seagate Technology (STX.O) dropping over 7%, SK Hynix (SKHY.O) and Micron Technology (MU.O) falling over 5%, and SanDisk (SNDK.O) down 4.6%.

  • Goldman Sachs and JPMorgan Refuse to Underwrite 11% Interest AI Chip Loan

    On October 13, Wall Street's two major investment banks, JPMorgan and Goldman Sachs, took the "rare step of limiting their exposure" in a $5 billion AI loan project for the newly established cloud service provider Volta Infrastructure Holdings. They only underwrote $1.3 billion in term loans and completely refrained from underwriting the $3.7 billion chip loan to mitigate potential risks. The entire loan package carries an interest rate of approximately 11%, marking one of the highest borrowing costs in the AI financing leveraged loan market. The offerings include 36,000 NVIDIA chips and a leasing right in Norway. (Zerohedge)

  • Goldman Sachs Pre-Market Rises Over 3%, Q3 Stock Trading Revenue at $6.44 Billion Exceeds Expectations

    On October 13, Goldman Sachs (GS.US) saw its pre-market shares rise over 3%. In terms of news, the performance of Goldman Sachs Group's stock trading business in the third quarter significantly exceeded expectations, although revenue from fixed income and interest rate trading was far below Wall Street forecasts. A statement released by Goldman on Tuesday indicated that stock trading revenue reached $6.44 billion for the three months ending in September. This business had set a record for global banking in the second quarter, announced in July, marking the third consecutive quarter of record-breaking revenue. Although the third quarter revenue fell short of the historical peak of $7.42 billion set in the second quarter, it still surpassed aggregated analyst expectations. Revenue from fixed income and commodities trading was $3.47 billion, well below expectations and nearly a 1% year-over-year decline. Goldman Sachs CEO David Solomon had previously warned in September that business performance would slow in the third quarter. The trading facilitation business drove Goldman Sachs' growth in the third quarter, with investment banking fee revenue reaching $3.22 billion, exceeding expectations. The bank's asset management division also achieved record-high management fee revenue.