completed replay attack demonstrator example #216
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
chainIdprotection blocks this. It signs transactions, parses signed hex, and checks whether replay is possible based onchainId. It includes a Web UI and CLI for running demos.Motivation: Helps developers and auditors understand replay risks, why
chainIdmust be included in signed transactions, and how legacy transactions withoutchainIdcan 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.
How Has This Been Tested?
npm test(Jest). Coverage includes:createTransaction– correct params and default valuesserializeTransaction– parsing signed tx hex intoethers.TransactioncanReplayTransaction– chainId protection (no replay on different network; replay allowed on same network)getTransactionDetails– extracting from, to, value, chainId from signed hexNETWORKS– BSC mainnet/testnet (and any other networks) configurationnpm run build(TypeScript compiles without errors).npm run start:ui(ornpm run dev:ui) → openhttp://localhost:3000→ use “Demonstrate” with from/to/value, original/target network, optionally private key → verify “Can Replay” result and reason.POST /api/demonstrateandPOST /api/transaction-detailswith sample payloads;GET /api/networksfor available networks.npm start <from> <to> <value> <original-network> [target-network] [private-key](or viaFROM_ADDRESS,TO_ADDRESS, etc. in.env) and confirm replay analysis output.Reproduce:
npm install, copyenv.templateto.envand fill as needed.npm run buildthennpm test.npm run start:ui→ open UI, run a demo.bsc-mainnet/bsc-testnet.Checklist: