Repository navigation
fix(tarpit): keep the Python peer slot deterministic across processes - #350
Conversation
The generated Python tarpit folded str.__hash__ of function names into the shared-slot peer, and Python randomizes that hash per process. Two runs of the same hardened module therefore exposed different decoy state, a cheap consistency tell. sum(map(ord, ...)) keeps the name touch for xref density while staying reproducible; a test runs the module under two PYTHONHASHSEED values.
…solation accepts it
|
Thanks @DeryFerd — good catch on |
generatePythonTarpitbuilds a shared slot and foldshash(name)of two generated functions into itspeerfield. Python randomisesstr.__hash__per process throughPYTHONHASHSEED, so the same hardened module produces a differentpeeron every run whileepochstays stable.Runtime behaviour does not change because
peeris never read back. The decoy state is documented as seed driven, though, and a value that drifts between runs is a cheap consistency signal for anyone comparing two executions of the same artifact.What changed
sum(map(ord, name))instead ofhash(name). It still reads the function name, so the cross reference that the original line created is preserved, but the value no longer depends on the process hash seed (src/shields/tarpit/tarpit-generator.ts).tests/tarpit-python-peer-determinism.test.tsgenerates the module once, executes it underPYTHONHASHSEED=1andPYTHONHASHSEED=2, and asserts the slot value is identical. The test is skipped when no Python 3.8 or newer interpreter is available, matching the other Python tests.Tradeoffs
The deterministic value is not the same number the old code produced at runtime, but nothing consumed the old value. Keeping the name expression costs a tiny amount of generated code and keeps the xref density that the line was added for. A constant would have removed the reference and changed the decoy shape.
Verification
npx vitest run tests/tarpit-python-peer-determinism.test.ts tests/tarpit-suite.test.ts tests/opaque-predicates.test.ts tests/exhaustion-suite.test.tspasses, 16 tests.npm run typecheckandnpm run buildare clean.