Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eth/rpc/backend/gas_used_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *BackendSuite) TestGasUsedFunTokens() {
Nonce: nonce,
To: &precompile.PrecompileAddr_FunToken,
Data: packedArgsPass,
Gas: 1_500_000,
Gas: 3_500_000,
GasPrice: big.NewInt(1),
},
false,
Expand Down
2 changes: 1 addition & 1 deletion eth/rpc/backend/tx_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (s *BackendSuite) TestLogs() {
Nonce: s.getCurrentNonce(s.fundedAccEthAddr),
To: &precompile.PrecompileAddr_FunToken,
Data: packedArgsPass,
Gas: 1_500_000,
Gas: 2_500_000,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Standardize gas limit to 1,500,000 for consistency

The gas limit of 2,500,000 is inconsistent with similar operations in the codebase. Other token operations in the test files consistently use 1,500,000 gas, including:

  • eth/rpc/backend/gas_used_test.go
  • eth/rpc/backend/backend_suite_test.go

Consider reducing the gas limit to 1,500,000 to maintain consistency across the test suite.

🔗 Analysis chain

Maintain consistent gas limits across similar operations.

The gas limit of 2,500,000 for sending ERC20 tokens to coin seems inconsistent with similar operations in other tests. Consider standardizing gas limits across similar operations to ensure consistent testing and better detection of gas usage regressions.

Let's verify gas usage patterns for similar operations:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar ERC20 token operations and their gas limits
rg -A 5 "PrecompileAddr_FunToken.*Gas:" .

Length of output: 43


Script:

#!/bin/bash
# Search for gas limit patterns in test files
rg -A 2 "Gas:\s+\d" --type go --glob "*_test.go"

# Search specifically in the eth/rpc/backend directory for context
rg -A 5 "Gas:" eth/rpc/backend/

Length of output: 10817

GasPrice: big.NewInt(1),
},
false,
Expand Down
17 changes: 10 additions & 7 deletions evm-e2e/contracts/TestERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20} from '@openzeppelin/contracts/token/ERC20/ERC20.sol';

contract TestERC20 is ERC20 {
// Define the supply of TestERC20: 1,000,000
uint256 constant initialSupply = 1000000 * (10 ** 18);

// Define the supply of TestERC20: 1,000,000
uint256 constant initialSupply = 1000000 * (10**18);
// Constructor will be called on contract creation
constructor() ERC20('TestERC20', 'FOO') {
_mint(msg.sender, initialSupply);
}

// Constructor will be called on contract creation
constructor() ERC20("TestERC20", "FOO") {
_mint(msg.sender, initialSupply);
}
function mint(address to, uint256 amount) public {
_mint(to, amount);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add access control to mint function

The mint function is public without any access restrictions, which could allow anyone to create unlimited tokens. Consider adding the OpenZeppelin Ownable contract and restricting minting to the contract owner.

+import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol';

-contract TestERC20 is ERC20 {
+contract TestERC20 is ERC20, Ownable {
   // ... other code ...

-  function mint(address to, uint256 amount) public {
+  function mint(address to, uint256 amount) public onlyOwner {
     _mint(to, amount);
   }

Committable suggestion skipped: line range outside the PR's diff.

}
88 changes: 88 additions & 0 deletions x/evm/embeds/abi/DSAuth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
[
{
"constant": false,
"inputs": [
{
"name": "owner_",
"type": "address"
}
],
"name": "setOwner",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "authority_",
"type": "address"
}
],
"name": "setAuthority",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "authority",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "authority",
"type": "address"
}
],
"name": "LogSetAuthority",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "owner",
"type": "address"
}
],
"name": "LogSetOwner",
"type": "event"
}
]
26 changes: 26 additions & 0 deletions x/evm/embeds/abi/DSAuthEvents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "authority",
"type": "address"
}
],
"name": "LogSetAuthority",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "owner",
"type": "address"
}
],
"name": "LogSetOwner",
"type": "event"
}
]
29 changes: 29 additions & 0 deletions x/evm/embeds/abi/DSAuthority.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"constant": true,
"inputs": [
{
"name": "src",
"type": "address"
},
{
"name": "dst",
"type": "address"
},
{
"name": "sig",
"type": "bytes4"
}
],
"name": "canCall",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
1 change: 1 addition & 0 deletions x/evm/embeds/abi/DSMath.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
39 changes: 39 additions & 0 deletions x/evm/embeds/abi/DSNote.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[
{
"anonymous": true,
"inputs": [
{
"indexed": true,
"name": "sig",
"type": "bytes4"
},
{
"indexed": true,
"name": "guy",
"type": "address"
},
{
"indexed": true,
"name": "foo",
"type": "bytes32"
},
{
"indexed": true,
"name": "bar",
"type": "bytes32"
},
{
"indexed": false,
"name": "wad",
"type": "uint256"
},
{
"indexed": false,
"name": "fax",
"type": "bytes"
}
],
"name": "LogNote",
"type": "event"
}
]
151 changes: 151 additions & 0 deletions x/evm/embeds/abi/DSStop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
[
{
"constant": false,
"inputs": [],
"name": "stop",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "owner_",
"type": "address"
}
],
"name": "setOwner",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "stopped",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "authority_",
"type": "address"
}
],
"name": "setAuthority",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "start",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "authority",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "authority",
"type": "address"
}
],
"name": "LogSetAuthority",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "owner",
"type": "address"
}
],
"name": "LogSetOwner",
"type": "event"
},
{
"anonymous": true,
"inputs": [
{
"indexed": true,
"name": "sig",
"type": "bytes4"
},
{
"indexed": true,
"name": "guy",
"type": "address"
},
{
"indexed": true,
"name": "foo",
"type": "bytes32"
},
{
"indexed": true,
"name": "bar",
"type": "bytes32"
},
{
"indexed": false,
"name": "wad",
"type": "uint256"
},
{
"indexed": false,
"name": "fax",
"type": "bytes"
}
],
"name": "LogNote",
"type": "event"
}
Comment on lines +114 to +150
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Reduce the number of indexed parameters in LogNote event.

The LogNote event has 4 indexed parameters (sig, guy, foo, bar), which exceeds Solidity's limit of 3 indexed parameters per event. This could cause compatibility issues with some tools and increase gas costs.

Apply this diff to fix the issue:

  {
    "anonymous": true,
    "inputs": [
      {
        "indexed": true,
        "name": "sig",
        "type": "bytes4"
      },
      {
        "indexed": true,
        "name": "guy",
        "type": "address"
      },
      {
        "indexed": true,
        "name": "foo",
        "type": "bytes32"
      },
      {
-       "indexed": true,
+       "indexed": false,
        "name": "bar",
        "type": "bytes32"
      },
      {
        "indexed": false,
        "name": "wad",
        "type": "uint256"
      },
      {
        "indexed": false,
        "name": "fax",
        "type": "bytes"
      }
    ],
    "name": "LogNote",
    "type": "event"
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
"anonymous": true,
"inputs": [
{
"indexed": true,
"name": "sig",
"type": "bytes4"
},
{
"indexed": true,
"name": "guy",
"type": "address"
},
{
"indexed": true,
"name": "foo",
"type": "bytes32"
},
{
"indexed": true,
"name": "bar",
"type": "bytes32"
},
{
"indexed": false,
"name": "wad",
"type": "uint256"
},
{
"indexed": false,
"name": "fax",
"type": "bytes"
}
],
"name": "LogNote",
"type": "event"
}
{
"anonymous": true,
"inputs": [
{
"indexed": true,
"name": "sig",
"type": "bytes4"
},
{
"indexed": true,
"name": "guy",
"type": "address"
},
{
"indexed": true,
"name": "foo",
"type": "bytes32"
},
{
"indexed": false,
"name": "bar",
"type": "bytes32"
},
{
"indexed": false,
"name": "wad",
"type": "uint256"
},
{
"indexed": false,
"name": "fax",
"type": "bytes"
}
],
"name": "LogNote",
"type": "event"
}

]
Loading
Loading