Skip to content

completed replay attack demonstrator example#216

Open
buggythanos wants to merge 1 commit intobnb-chain:mainfrom
buggythanos:replay-attack-demonstrator-example
Open

completed replay attack demonstrator example#216
buggythanos wants to merge 1 commit intobnb-chain:mainfrom
buggythanos:replay-attack-demonstrator-example

Conversation

@buggythanos
Copy link

@buggythanos buggythanos commented Jan 25, 2026

Description

Adds the Replay Attack Demonstrator to the BNBChain Cookbook. The tool shows how transactions can be replayed across networks (e.g. BSC mainnet vs testnet) and how chainId protection blocks this. It signs transactions, parses signed hex, and checks whether replay is possible based on chainId. It includes a Web UI and CLI for running demos.

replay-attack-demonstrator-example

Motivation: Helps developers and auditors understand replay risks, why chainId must be included in signed transactions, and how legacy transactions without chainId can be replayed on other networks. Supports security education and due diligence for BSC/EVM usage.

Type of change

Please delete options that are not relevant.

  • Bug fix (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)
  • This change requires a documentation update

How Has This Been Tested?

  • Unit tests: npm test (Jest). Coverage includes:
    • createTransaction – correct params and default values
    • serializeTransaction – parsing signed tx hex into ethers.Transaction
    • canReplayTransaction – chainId protection (no replay on different network; replay allowed on same network)
    • getTransactionDetails – extracting from, to, value, chainId from signed hex
    • NETWORKS – BSC mainnet/testnet (and any other networks) configuration
  • Build: npm run build (TypeScript compiles without errors).
  • Manual testing:
    • Web UI: npm run start:ui (or npm run dev:ui) → open http://localhost:3000 → use “Demonstrate” with from/to/value, original/target network, optionally private key → verify “Can Replay” result and reason.
    • API: POST /api/demonstrate and POST /api/transaction-details with sample payloads; GET /api/networks for available networks.
    • CLI: npm start <from> <to> <value> <original-network> [target-network] [private-key] (or via FROM_ADDRESS, TO_ADDRESS, etc. in .env) and confirm replay analysis output.

Reproduce:

  1. Clone repo, run npm install, copy env.template to .env and fill as needed.
  2. npm run build then npm test.
  3. npm run start:ui → open UI, run a demo.
  4. Optionally run CLI with test addresses and bsc-mainnet / bsc-testnet.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@vivixu-cmd
Copy link

Congratulations! You have received a Cookbook reward. Please reply with your BSC wallet address.Thanks

@buggythanos
Copy link
Author

Congratulations! You have received a Cookbook reward. Please reply with your BSC wallet address.Thanks

Hi there, thank you!
0x4e5d4a29F7b02c8cf1310D112A42231Bde049180

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