Skip to content

fix: Replace polynomial rolling hash with SHA-256 for prefix caching - #4158

Merged
lmcafee-nvidia merged 3 commits into
NVIDIA:mainfrom
lmcafee-nvidia:prefix-caching-secure-hash
Apr 25, 2026
Merged

fix: Replace polynomial rolling hash with SHA-256 for prefix caching#4158
lmcafee-nvidia merged 3 commits into
NVIDIA:mainfrom
lmcafee-nvidia:prefix-caching-secure-hash

Conversation

@lmcafee-nvidia

Copy link
Copy Markdown
Contributor

Summary

  • Replace the polynomial rolling hash in compute_block_hashes_batched() with SHA-256 to eliminate an algebraic collision vulnerability (token[j] += 31, token[j+1] -= 1 produced zero-delta in the old hash)
  • Add collision-resistance regression tests covering the exact exploit vector, all intra-block positions, parent-chain propagation, and generalized linear combinations

Test plan

  • test_hash_collision_resistance — verifies the old V2 algebraic attack no longer produces collisions
  • test_hash_computation — existing test updated to remove HASH_PRIME reference
  • Full prefix caching test suite passes: /opt/venv/bin/python -m torch.distributed.run --nproc-per-node 1 -m pytest tests/unit_tests/inference/contexts/test_dynamic_prefix_caching.py -v

🤖 Generated with Claude Code

The polynomial rolling hash had exploitable algebraic structure where
token[j] += HASH_BASE, token[j+1] -= 1 produces a zero-delta, enabling
cache poisoning in multi-tenant serving. SHA-256 eliminates this class
of attacks with cryptographic collision resistance.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@copy-pr-bot

copy-pr-bot Bot commented Apr 6, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@chtruong814
chtruong814 marked this pull request as ready for review April 16, 2026 21:43
@chtruong814
chtruong814 requested review from a team as code owners April 16, 2026 21:43
@svcnvidia-nemo-ci
svcnvidia-nemo-ci requested a review from a team April 16, 2026 21:44
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Apr 16, 2026
@lmcafee-nvidia lmcafee-nvidia self-assigned this Apr 24, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added Approved All necessary approvals have been made and removed Final Review PR is in the "final review" stage labels Apr 24, 2026
@lmcafee-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 46c4e6d

@svcnvidia-nemo-ci svcnvidia-nemo-ci added this to the Core 0.16 milestone Apr 24, 2026
@lmcafee-nvidia
lmcafee-nvidia added this pull request to the merge queue Apr 24, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/24912702741

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/24914628506

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/24916866638

Merged via the queue into NVIDIA:main with commit e9abb6c Apr 25, 2026
67 of 68 checks passed
@lmcafee-nvidia
lmcafee-nvidia deleted the prefix-caching-secure-hash branch April 25, 2026 00:41
@chtruong814 chtruong814 added the core_r0.17.0 Auto-cherrypick to release branch. Apply before merge; cherrypick happens after merge. label May 4, 2026
ko3n1g added a commit that referenced this pull request May 5, 2026
…ing (#4158) (#4612)

Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Co-authored-by: Lawrence McAfee <85179052+lmcafee-nvidia@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: oliver könig <okoenig@nvidia.com>
yangbofun pushed a commit to xlm-research/Megatron-LM that referenced this pull request May 22, 2026
…VIDIA#4158)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
yhgalaxy pushed a commit to yhgalaxy/Megatron-LM that referenced this pull request Jun 17, 2026
…VIDIA#4158)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: yhgalaxy <yhgalaxy@outlook.com>
jon-barker pushed a commit to jon-barker/Megatron-LM that referenced this pull request Jul 10, 2026
…VIDIA#4158)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Jon Barker <jbarker@aws-cmh-slurm-1-vscode-02.cm.cluster>
terminator123 pushed a commit to 021ai/Megatron-LM that referenced this pull request Aug 3, 2026
…VIDIA#4158)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved All necessary approvals have been made complexity: low core_r0.17.0 Auto-cherrypick to release branch. Apply before merge; cherrypick happens after merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants