refactor(policy): mirror Rust write_builtins design in MockPolicyRegistry#71
Merged
Conversation
746aac6 to
0db7787
Compare
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
Aligns
MockPolicyRegistrystorage behavior with the Rust precompile(
base/baseorigin/maincommit460972cc9) so the fork-test suiteno longer surfaces a counter / sentinel-slot divergence.
What changed
INITIAL_CUSTOM_COUNTER = 2floor with anexplicit
writeBuiltins()that writesALWAYS_ALLOW_IDandALWAYS_BLOCK_IDinto thepoliciesmapping (renounced admin,exists bit set) and advances
nextCountertoBUILTIN_POLICY_COUNT = 2. Idempotent; called lazily on everycreatePolicyentry to mirror Rust'sis_initialized→write_builtinsflow.
policyAdminandpendingPolicyAdmin. AfterwriteBuiltins, the normal storageread returns
address(0)for the sentinels just like for anyrenounced or uncreated policy — matching the Rust impl.
isAuthorizedandpolicyExists:B-20 tokens may query the sentinel IDs (and especially
ALWAYS_ALLOW_ID = 0, the EVM default for unset policy slots)before any
createPolicytriggers init._predictNextPolicyIdto read the canonical floor fromthe now-
publicBUILTIN_POLICY_COUNTgetter.PolicyRegistryFullLayoutTestto assert both sentinelslots are populated post-init.
writeBuiltins.t.solcovering: explicit init, lazy init onfirst create, idempotence, sentinel slot encoding,
policyAdminreading zero from storage post-init, and thepolicyExistspre-init fast path.Observable behavior
The output of the very first
createPolicyis unchanged (stillcounter == 2). The storage layout now matches the Rust impl
byte-for-byte:
policies[0]andpolicies[ALWAYS_BLOCK_ID]carrypacked(address(0))after the first create, instead of being empty.Tests
446 passed / 0 failed (440 prior + 6 new).