fix(cnight-observation): enforce MaxRegistrationsPerCardanoAddress in handle_registration (audit AE / #314)#1488
Draft
fix(cnight-observation): enforce MaxRegistrationsPerCardanoAddress in handle_registration (audit AE / #314)#1488
Conversation
…ation Signed-off-by: Mike Clay <mike.clay@shielded.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Enforce
MaxRegistrationsPerCardanoAddressinpallet-cnight-observation::handle_registrationso a single Cardano address cannot accumulate moreMappingEntryrecords than the declared cap, closing the writer-side gap flagged by audit Issue AE.🐛 Issue 📐 Engineering
Audit reference: Least Authority Node Final Audit Report (10 March 2026) — Issue AE.
Jira: PM-19974.
Motivation
pallet-cnight-observation'shandle_registration(pallets/cnight-observation/src/lib.rs:411-452) appends newMappingEntryrecords toMappings::<T>::get(cardano_reward_address)without checking the per-address cap. The cap concept is already declared in three places —Error::<T>::MaxRegistrationsExceeded(src/lib.rs:178, currently unused),MaxRegistrationsPerCardanoAddress = 100in both mock runtimes (mock/src/mock.rs:146,mock_with_capture.rs:134), and a block of commented-out cap-enforcement tests intests/tests.rs:730+— but no path reads the cap at write time. A Cardano address that submits N valid registration UTXOs without intervening deregistrations accumulates N entries unchecked. The audit categorises both severity and feasibility as Low (the spam path is rate-limited by Cardano fees), but the gap is a straightforward declaration/enforcement mismatch and a latent panic site for any future reader that convertsMappingstoBoundedVec.This PR closes the gap with a writer-invariant cap inside
handle_registration, parameterised on the palletConfigtrait so the runtime can bind the value. The cap-rejection is observable via a newEvent::MappingCappedvariant (indexer-facing) and alog::warn!line (operator-facing). The deadError::MaxRegistrationsExceededvariant is removed in the same PR.Changes
Implementation (coming next):
type MaxRegistrationsPerCardanoAddress: Get<u32>topallet_cnight_observation::Config(third associated type, alongsideMidnightSystemTransactionExecutorandWeightInfo).handle_registration(before any read ofMappingsfor write purposes). Onmappings.len() as u32 >= T::MaxRegistrationsPerCardanoAddress::get(), emitEvent::MappingCapped(new_reg),log::warn!, andreturn None. No mutation occurs on rejection.MappingCapped(MappingEntry)variant toEvent<T>. Shape-parallel toMappingAdded/MappingRemoved.Error::MaxRegistrationsExceededvariant.MaxRegistrationsPerCardanoAddressliteral fromu8 = 100tou32 = 100in both mocks; bindtype MaxRegistrationsPerCardanoAddress = MaxRegistrationsPerCardanoAddress;in eachimpl Config for Test.parameter_types! { pub const MaxRegistrationsPerCardanoAddress: u32 = 100; }and bindtype MaxRegistrationsPerCardanoAddressinruntime/src/lib.rs.MappingCappedevent), andprocess_tokensbatch continuity (cap-rejected UTXO does not poison sibling UTXOs).changes/runtime/changed/audit-cnight-observation-cap-enforcement.mdmirroring theaudit-motion-close-weight-bound.mdprecedent.MappingsremainsVec<MappingEntry>. NoBoundedVecmigration in this PR. (Path B — typedBoundedVec<_, T::MaxRegistrationsPerCardanoAddress>withOnRuntimeUpgrade— is enumerated as a follow-up in the engineering plan.)📌 Submission Checklist
🔱 Fork Strategy
🗹 TODO before merging