Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TracerConfig Support and Implement Contract Tracer #683

Open
wants to merge 2 commits into
base: dev-upgrade
Choose a base branch
from

Conversation

JukLee0ira
Copy link

@JukLee0ira JukLee0ira commented Oct 21, 2024

Proposed changes

  1. Add TracerConfig to Existing Tracer:

    • Added a TracerConfig option, primarily for onlyTopCall, to provide more control over which calls are traced.
  2. Implement ContractTracer:

    • Introduced a new ContractTracer to locate created contracts and return their addresses.
    • Added configuration options to retrieve the corresponding contract bytecode when needed.

Example

Request

RPC="http://172.16.3.16:8547"
NUMBER="0x399e"
curl -s -X POST -H "Content-Type: application/json" ${RPC} -d '{
  "jsonrpc": "2.0",
  "id": 1002,
  "method": "debug_traceBlockByNumber",
  "params": [
    "'"${NUMBER}"'", {
        "tracer":"contractTracer","tracerConfig": {"opCode": "PREVRANDAO","WithByteCode": true}
    }
  ]
}' | jq

Response

{
  "jsonrpc": "2.0",
  "id": 1002,
  "result": [
    {
      "result": {
        "0xf63f8ba05d790b93db0005de3e65d90cd0b68bf6": "0x608060405234801561001057600080fd5b50610734806100206000396000f3fe6080604052600436106100345760003560e01c806311ec0dde146100395780638398aefe14610076578063af899735146100b3575b600080fd5b34801561004557600080fd5b50610060600480360381019061005b9190610469565b6100bd565b60405161006d91906104af565b60405180910390f35b34801561008257600080fd5b5061009d60048036038101906100989190610469565b6100d5565b6040516100aa91906104af565b60405180910390f35b6100bb6100ed565b005b60006020528060005260406000206000915090505481565b60016020528060005260406000206000915090505481565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050600081036101d25760804361014691906104f9565b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550346000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555050610404565b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054431015610254576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161024b9061058a565b60405180910390fd5b60004490506000811415806102755750600060028261027391906105d9565b145b1561037857600060026000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546102c7919061060a565b905060003373ffffffffffffffffffffffffffffffffffffffff16826040516102ef9061067d565b60006040518083038185875af1925050503d806000811461032c576040519150601f19603f3d011682016040523d82523d6000602084013e610331565b606091505b5050905080610375576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161036c906106de565b60405180910390fd5b50505b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555060008060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555050505b565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006104368261040b565b9050919050565b6104468161042b565b811461045157600080fd5b50565b6000813590506104638161043d565b92915050565b60006020828403121561047f5761047e610406565b5b600061048d84828501610454565b91505092915050565b6000819050919050565b6104a981610496565b82525050565b60006020820190506104c460008301846104a0565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061050482610496565b915061050f83610496565b9250828201905080821115610527576105266104ca565b5b92915050565b600082825260208201905092915050565b7f546f6f206561726c790000000000000000000000000000000000000000000000600082015250565b600061057460098361052d565b915061057f8261053e565b602082019050919050565b600060208201905081810360008301526105a381610567565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b60006105e482610496565b91506105ef83610496565b9250826105ff576105fe6105aa565b5b828206905092915050565b600061061582610496565b915061062083610496565b925082820261062e81610496565b91508282048414831517610645576106446104ca565b5b5092915050565b600081905092915050565b50565b600061066760008361064c565b915061067282610657565b600082019050919050565b60006106888261065a565b9150819050919050565b7f5472616e73666572206661696c65642e00000000000000000000000000000000600082015250565b60006106c860108361052d565b91506106d382610692565b602082019050919050565b600060208201905081810360008301526106f7816106bb565b905091905056fea2646970667358221220292ac5b3f6bec5a93ff3bd6571adf53fda3ef1c1845ca420f2c090a2b668786664736f6c63430008130033"
      }
    }
  ]
}

Request

RPC="http://172.16.3.16:8547"
NUMBER="0x399e"
curl -s -X POST -H "Content-Type: application/json" ${RPC} -d '{
  "jsonrpc": "2.0",
  "id": 1002,
  "method": "debug_traceBlockByNumber",
  "params": [
    "'"${NUMBER}"'", {
        "tracer":"contractTracer","tracerConfig": {"opCode": "PREVRANDAO"}
    }
  ]
}' | jq

Response

{
  "jsonrpc": "2.0",
  "id": 1002,
  "result": [
    {
      "result": {
        "0xf63f8ba05d790b93db0005de3e65d90cd0b68bf6": ""
      }
    }
  ]
}

Request

RPC="http://172.16.3.16:8547"
NUMBER="0x399e"
curl -s -X POST -H "Content-Type: application/json" ${RPC} -d '{
  "jsonrpc": "2.0",
  "id": 1002,
  "method": "debug_traceBlockByNumber",
  "params": [
    "'"${NUMBER}"'", {
        "tracer":"contractTracer","tracerConfig": {"opCode": "PRO","WithByteCode": true}
    }
  ]
}' | jq

Response

{
  "jsonrpc": "2.0",
  "id": 1002,
  "result": [
    {
      "result": {}
    }
  ]
}

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)
  • Regular KTLO or any of the maintaince work. e.g code style
  • CICD Improvement

Impacted Components

Which part of the codebase this PR will touch base on,

Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

// handle invalid opcode case
op := vm.StringToOp(t.config.OpCode)
if op == 0 && t.config.OpCode != "STOP" && t.config.OpCode != "" {
t.config.OpCode = "inv"
Copy link

Choose a reason for hiding this comment

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

I would return an error here instead. No reason to do tracing in this case.

}
// If WithByteCode is true, store the input in the address mapping as hex.
if t.config.WithByteCode {
t.Addrs[addrToHex(to)] = bytesToHex(input)
Copy link

Choose a reason for hiding this comment

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

This is not quite right. The inout here will not be the actual bytecode. Rather the contract constructor code.


func validateAndStoreOpCode(t *contractTracer, input []byte, to common.Address) {
// If the OpCode is "inv" or if the OpCode is not empty and doesn't match the input, exit early.
if t.config.OpCode == "inv" || (t.config.OpCode != "" && !findOpcodes(input, vm.StringToOp(t.config.OpCode))) {
Copy link

Choose a reason for hiding this comment

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

Also here the input is constructor code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants