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

JSONRPC: Account update subscription #615

Open
Kriys94 opened this issue Dec 20, 2024 · 0 comments
Open

JSONRPC: Account update subscription #615

Kriys94 opened this issue Dec 20, 2024 · 0 comments

Comments

@Kriys94
Copy link

Kriys94 commented Dec 20, 2024

Motivation


There is no universal solution to see activity of an address. Today, one way is to listen and look block logs activity but they are not covering all cases, some are not emitting events. in addition to subscribe to nonce, balance, code update, this method tries to watch all account activity by looking at the KECCAK256 and SSTORE level.

Websocket specification


Parameters:

  1. accountUpdate
  2. object
    2.a. nonce (optional): boolean to subscribe to nonce update
    2.b. balance (optional): boolean to subscribe to balance update
    2.c. code (optional): boolean to subscribe to code update
    2.d. storageSlots (optional): list of storage slots update (SSTORE)
    2.f. preKeccak256StorageKey (optional): list of keccak256 input used as storage key
  3. List of addresses to watch. If null, watch all changes (optional)
{
  "jsonrpc": "2.0",
  "method": "eth_subscribe",
  "params": [
    "accountUpdate",
    {
      "nonce": true, // optional
      "balance": true, // optional
      "code": true, // optional
      "storageSlots": [
        "..." // storage slots - optional
      ],
      "preKeccak256StorageKey": [
        "..." // list of addresses used in a keccak256 for an SSTORE - optional
      ],
    },
    [...] // list of smart contract/EOA addresses - optional
  ],
  "id": 1
}
>>>
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x9ce59a13059e417087c02d3236a0b1cc"
}

Notification Response:

  • subscription id
  • result
    • blockHash: 32 bytes. Hash of the block including this transaction
    • blockNumber: Block number including this transaction.
    • transactionHash: 32 bytes. The hash of the transaction.
    • OR
    • nonceUpdate
    • balanceUpdate
    • codeUpdate
    • storageUpdate object:
      • account address: list of accounts with update
        • storageKey list of storage key with update
          • preKeccak256StorageKey Input of the Keccak256 used for the storage
          • value new value of the storage key
>>>
{
  "jsonrpc":  "2.0",
  "method":  "eth_subscription",
  "params":  {
      "subscription":  "0x9ce59a13059e417087c02d3236a0b1cc",
      "result":  {
          "blockHash": "0xabc",
          "blockNumber": 1213232,
          "transactionHash": "0x38c0a3cea017d3c9213d86037beb0f5ac49e46d262925139dd536f30a12e5461",
          "storageUpdate": {
              "0xc8ba32cab1757528daf49033e3673fae77dcf05d": { // smart contract address
                "0x59fb7853eb21f604d010b94c123acbeae621f09ce15ee5d7616485b1e78a72e9" { // storage key
                  "preKeccak256StorageKeyy": ["0x000000000000000000000000974caa59e49682cda0ad2bbe82983419a2ecc4000000000000000000000000000000000000000000000000000000000000000006"] // pre-processed storage key value (if applicable) 
                  "value": "0x00000000000000c42b56a52aedf18667c8ae258a0280a8912641c80c48cd9548" // storage value
                }
              }
          }
      }
  }
}
>>>
{
  "jsonrpc":  "2.0",
  "method":  "eth_subscription",
  "params":  {
      "subscription":  "0x9ce59a13059e417087c02d3236a0b1cc",
      "result":  {
          "blockNumber": 1213232,
          "blockHash": "0xabc",
          "txHash": "0x38c0a3cea017d3c9213d86037beb0f5ac49e46d262925139dd536f30a12e5461",
          "nonceUpdate": "0x1"
      }
  }
}
>>>
{
  "jsonrpc":  "2.0",
  "method":  "eth_subscription",
  "params":  {
      "subscription":  "0x9ce59a13059e417087c02d3236a0b1cc",
      "result":  {
          "blockNumber": 1213232,
          "blockHash": "0xabc",
          "txHash": "0x38c0a3cea017d3c9213d86037beb0f5ac49e46d262925139dd536f30a12e5461",
          "balanceUpdate": "0xaa"
      }
  }
}

HTTP filter subscription specification


Parameters:

  1. object
    1.a. nonce (optional): boolean to subscribe to nonce update
    1.b. balance (optional): boolean to subscribe to balance update
    1.c. code (optional): boolean to subscribe to code update
    1.d. storageSlots (optional): list of storage slots update (SSTORE)
    1.f. preKeccak256StorageKey (optional): list of keccak256 input used as storage key
  2. List of addresses to watch. If null, watch all changes (optional)
{
  "jsonrpc": "2.0",
  "method": "eth_newStorageUpdateFilter",
  "params": [
    {
      "nonce": true, // optional
      "balance": true, // optional
      "code": true, // optional
      "storageSlots": [
        "..." // storage slots - optional
      ],
      "preKeccak256StorageKey": [
        "..." // list of addresses used in a keccak256 for an SSTORE - optional
      ],
    },
    [...] // list of smart contract/EOA addresses - optional
  ],
  "id": 1
}
>>>
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x9ce59a13059e417087c02d3236a0b1cc"
}

eth_getFilterChanges response:

{
  "jsonrpc": "2.0",
  "method": "eth_getFilterChanges",
  "params": ["0x9ce59a13059e417087c02d3236a0b1cc"],
  "id": 1
}
>>>
{
  "jsonrpc": "2.0",
  "id": 73,
  "result": [
        {
          "blockHash": "0xabc",
          "blockNumber": 1213232,
          "transactionHash": "0x38c0a3cea017d3c9213d86037beb0f5ac49e46d262925139dd536f30a12e5461",
          "storageUpdate": {
              "0xc8ba32cab1757528daf49033e3673fae77dcf05d": { // smart contract address
                "0x59fb7853eb21f604d010b94c123acbeae621f09ce15ee5d7616485b1e78a72e9" { // storage key
                  "preKeccak256StorageKeyy": ["0x000000000000000000000000974caa59e49682cda0ad2bbe82983419a2ecc4000000000000000000000000000000000000000000000000000000000000000006"] // pre-processed storage key value (if applicable) 
                  "value": "0x00000000000000c42b56a52aedf18667c8ae258a0280a8912641c80c48cd9548" // storage value
                }
              }
          }
      }
    [...]
  ]
}
@Kriys94 Kriys94 changed the title WIP - JSONRPC: Account update subscription JSONRPC: Account update subscription Jan 7, 2025
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

No branches or pull requests

1 participant