User Tools

Site Tools


dido:public:ra:1.2_views:3_taxonomic:4_data_tax:10_errors:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
dido:public:ra:1.2_views:3_taxonomic:4_data_tax:10_errors:start [2022/02/04 11:12]
nick [DIDO Specifics]
dido:public:ra:1.2_views:3_taxonomic:4_data_tax:10_errors:start [2022/03/16 15:55] (current)
char
Line 39: Line 39:
 [[dido:​public:​ra:​1.2_views:​3_taxonomic:​4_data_tax:​10_errors:​start | Return to Top]] [[dido:​public:​ra:​1.2_views:​3_taxonomic:​4_data_tax:​10_errors:​start | Return to Top]]
  
-Solidity Syntax errors are detected within [[dido:​public:​ra:​xapend:​xapend.a_glossary:​s:​syntax_highlighting]] the [[dido:​public:​ra:​xapend:​xapend.b_stds:​defact:​ethereum:​remix]] or other [[dido:​public:​ra:​xapend:​xapend.a_glossary:​i:​ide | Integrated Development Environments (IDEs) ]] such as [[dido:​public:​ra:​xapend:​xapend.b_stds:​defact:​microsoft:​visual_studio_code]] with the Solidity [[dido:​public:​ra:​xapend:​xapend.a_glossary:​p:​plug_in]]. ​+Solidity Syntax errors are detected within [[dido:​public:​ra:​xapend:​xapend.a_glossary:​s:​syntax_highlighting]] the [[dido:​public:​ra:​xapend:​xapend.b_stds:​defact:​ethereum:​remix:start]] or other [[dido:​public:​ra:​xapend:​xapend.a_glossary:​i:​ide | Integrated Development Environments (IDEs) ]] such as [[dido:​public:​ra:​xapend:​xapend.b_stds:​defact:​microsoft:​visual_studio_code]] with the Solidity [[dido:​public:​ra:​xapend:​xapend.a_glossary:​p:​plug_in]]. ​
  
 A very important aspect of **Syntax Errors** caught within the IDE is that these errors are NOT caught on the blockchain, but rather just inside the IDE. This means there is no expenditure of Gas to catch these errors. ​ A very important aspect of **Syntax Errors** caught within the IDE is that these errors are NOT caught on the blockchain, but rather just inside the IDE. This means there is no expenditure of Gas to catch these errors. ​
Line 191: Line 191:
  
 Logic Errors are the hardest to fix becuase there are no tools that can examine a Smart Contract and find the Logic Errors. There are efforts underway at Ethereum called the [[https://​github.com/​leonardoalt/​ethereum_formal_verification_overview | Ethereum Formal Verification]]. Logic Errors are the hardest to fix becuase there are no tools that can examine a Smart Contract and find the Logic Errors. There are efforts underway at Ethereum called the [[https://​github.com/​leonardoalt/​ethereum_formal_verification_overview | Ethereum Formal Verification]].
 +
 +The Solidity [[dido:​public:​ra:​xapend:​xapend.b_stds:​defact:​ethereum:​remix:​start| Remix Project]] [[dido:​public:​ra:​xapend:​xapend.a_glossary:​i:​ide]] has a [[dido:​public:​ra:​xapend:​xapend.a_glossary:​p:​plug_in]] for [[dido:​public:​ra:​xapend:​xapend.a_glossary:​s:​static_code_analysis]] called the **Remix-analyzer**. ​
 +
 +**remix-analyzer** is the library which works underneath of **Remix-IDE Solidity Static Analysis** plugin.
 +
 +remix-analyzer is an NPM package. It can be used as a library in a solution supporting [[dido:​public:​ra:​xapend:​xapend.a_glossary:​n:​nodejs]]. Find more information about this type of usage in the remix-analyzer repository
 +
  
 <table staticAnalysis>​ <table staticAnalysis>​
Line 407: Line 414:
  
 </​WRAP>​| </​WRAP>​|
-^ | | <​WRAP>​+^ | No return: Function with ‘returns’ not returning ​| <​WRAP>​ 
 +It warns for the methods which define a return type but never explicitly return a value.
  
 +Example:
 +<Code Solidity linenums:​1>​
 +function noreturn
 +  ( string memory _dna ) 
 +  public ​
 +  returns (bool) ​
 +{ dna = _dna;
 +} // End function noreturn
 +</​Code>​
 </​WRAP>​| </​WRAP>​|
-^ | | <​WRAP>​+^ | Guard conditions: Use ‘require’ and ‘assert’ appropriately ​| <​WRAP>​ 
 +Use **''​assert(x)''​** if you never ever want **''​x''​** to be **''​false''​**,​ not in any circumstance (apart from a bug in your code). Use **''​require(x)''​** if **''​x''​** can be **''​false''​**,​ due to e.g. invalid input or a failing external component.
  
 +Example:
 +<Code Solidity linenums:​1>​
 +assert(a.balance == 0);
 +</​Code>​
 </​WRAP>​| </​WRAP>​|
-^ | | <​WRAP>​+^ | Result not used: The result of an operation not used | <​WRAP>​ 
 +A binary operation yields a value that is not used in the following code. This is often caused by confusing assignment (**''​=''​**) and comparison (**''​==''​**).
  
 +Example:
 +<Code Solidity linenums:​1>​
 +c == 5;
 + // or
 +a + b;
 +</​Code>​
 +</​WRAP>​|
 +^  | String Length: Bytes length != String length | <​WRAP>​
 +Bytes and string length are not the same since strings are assumed to be UTF-8 encoded (according to the ABI definition) therefore one character is not necessarily encoded in one byte of data.
 +
 +Example:
 +<Code Solidity linenums:​1>​
 +function length
 +  ( string memory a )
 +  public ​
 +  pure 
 +  returns ( uint ) 
 +{ bytes memory x = bytes ( a );
 +    return x.length;
 +} // End function length
 +</​Code>​
 +</​WRAP>​|
 +^  | Delete from dynamic array: ‘delete’ on an array leaves a gap | <​WRAP>​
 +Using **''​delete''​** on an array leaves a gap. The length of the array remains the same. If you want to remove the empty position you need to shift items manually and update the length property.
 +
 +Example:
 +<Code Solidity linenums:​1>​
 +contract arr 
 +{ uint[] array = [ 1, 2, 3 ];
 +  function removeAtIndex() ​
 +    public ​
 +    returns ( uint[] memory ) 
 +  { delete array[1];
 +    return array;
 +  } // End function removeAtIndex
 +} // End contract arr
 +</​Code>​
 +</​WRAP>​|
 +^  | Data Truncated: Division on int/uint values truncates the result | <​WRAP>​
 +Division of integer values yields an integer value again. That means e.g. ''​10 / 100 = 0''​ instead of ''​0.1''​ since the result is an integer again. This does not hold for division of (only) literal values since those yield rational constants.
 +
 +Example:
 +<Code Solidity linenums:​1>​
 +function contribute() ​
 +  payable ​
 +  public ​
 +{ uint fee = msg.value * uint256 ( feePercentage / 100 );
 +  fee = msg.value * ( p2 / 100 );
 +} // End function contribute
 +</​Code>​
 </​WRAP>​| </​WRAP>​|
 </​table>​ </​table>​
Line 429: Line 502:
  
  
 +<color darkred><​todo @char>​Review </​todo></​color>​
  
    
dido/public/ra/1.2_views/3_taxonomic/4_data_tax/10_errors/start.1643991153.txt.gz · Last modified: 2022/02/04 11:12 by nick