@@ -41,6 +41,23 @@ func newStorageSlotsByEntity(stakes EntityStakes, keccak []string) storageSlotsB
4141 return storageSlotsByEntity
4242}
4343
44+ type storageSlotsValidator struct {
45+ // Global parameters
46+ Op * userop.UserOperation
47+ EntryPoint common.Address
48+
49+ // Parameters of specific entities required for all validation
50+ SenderSlots storageSlots
51+ FactoryIsStaked bool
52+
53+ // Parameters of the entity under validation
54+ EntityName string
55+ EntityAddr common.Address
56+ EntityAccess tracer.AccessMap
57+ EntitySlots storageSlots
58+ EntityIsStaked bool
59+ }
60+
4461func isAssociatedWith (slots storageSlots , slot string ) bool {
4562 slotN , _ := big .NewInt (0 ).SetString (fmt .Sprintf ("0x%s" , slot ), 0 )
4663 for _ , k := range slots .ToSlice () {
@@ -53,26 +70,18 @@ func isAssociatedWith(slots storageSlots, slot string) bool {
5370 return false
5471}
5572
56- func validateStorageSlotsForEntity (
57- entityName string ,
58- op * userop.UserOperation ,
59- entryPoint common.Address ,
60- slotsByEntity storageSlotsByEntity ,
61- entityAccess tracer.AccessMap ,
62- entityAddr common.Address ,
63- entityIsStaked bool ,
64- ) error {
65- senderSlots , senderSlotOk := slotsByEntity [op .Sender ]
66- if ! senderSlotOk {
73+ func (v * storageSlotsValidator ) Process () error {
74+ senderSlots := v .SenderSlots
75+ if senderSlots == nil {
6776 senderSlots = mapset .NewSet [string ]()
6877 }
69- storageSlots , entitySlotOk := slotsByEntity [ entityAddr ]
70- if ! entitySlotOk {
71- storageSlots = mapset .NewSet [string ]()
78+ entitySlots := v . EntitySlots
79+ if entitySlots == nil {
80+ entitySlots = mapset .NewSet [string ]()
7281 }
7382
74- for addr , access := range entityAccess {
75- if addr == op . Sender || addr == entryPoint {
83+ for addr , access := range v . EntityAccess {
84+ if addr == v . Op . Sender || addr == v . EntryPoint {
7685 continue
7786 }
7887
@@ -84,24 +93,25 @@ func validateStorageSlotsForEntity(
8493 for key , slotCount := range accessTypes {
8594 for slot := range slotCount {
8695 if isAssociatedWith (senderSlots , slot ) {
87- if len (op .InitCode ) > 0 {
96+ if (len (v .Op .InitCode ) > 0 && ! v .FactoryIsStaked ) ||
97+ (len (v .Op .InitCode ) > 0 && v .FactoryIsStaked && v .EntityAddr != v .Op .Sender ) {
8898 mustStakeSlot = slot
8999 } else {
90100 continue
91101 }
92- } else if isAssociatedWith (storageSlots , slot ) || addr == entityAddr {
102+ } else if isAssociatedWith (entitySlots , slot ) || addr == v . EntityAddr {
93103 mustStakeSlot = slot
94104 } else {
95- return fmt .Errorf ("%s has forbidden %s to %s slot %s" , entityName , key , addr2KnownEntity (op , addr ), slot )
105+ return fmt .Errorf ("%s has forbidden %s to %s slot %s" , v . EntityName , key , addr2KnownEntity (v . Op , addr ), slot )
96106 }
97107 }
98108 }
99109
100- if mustStakeSlot != "" && ! entityIsStaked {
110+ if mustStakeSlot != "" && ! v . EntityIsStaked {
101111 return fmt .Errorf (
102112 "unstaked %s accessed %s slot %s" ,
103- entityName ,
104- addr2KnownEntity (op , addr ),
113+ v . EntityName ,
114+ addr2KnownEntity (v . Op , addr ),
105115 mustStakeSlot ,
106116 )
107117 }
0 commit comments