Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

Commit 77da1eb

Browse files
authored
Allow access to associated storage for new accounts deployed with a staked factory (#202)
1 parent e3a0027 commit 77da1eb

File tree

4 files changed

+45
-33
lines changed

4 files changed

+45
-33
lines changed

.github/workflows/compliance.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ jobs:
3131
- name: Checkout bundler spec test
3232
uses: actions/checkout@v3
3333
with:
34-
# TODO: Revert back to eth-infinitism/bundler-spec-tests once PR #23 and #24 merged.
3534
repository: hazim-j/bundler-spec-tests
3635
ref: develop
3736
path: ./bundler-spec-tests

internal/config/values.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func GetValues() *Values {
7676
viper.SetDefault("erc4337_bundler_port", 4337)
7777
viper.SetDefault("erc4337_bundler_data_directory", "/tmp/stackup_bundler")
7878
viper.SetDefault("erc4337_bundler_supported_entry_points", "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789")
79-
viper.SetDefault("erc4337_bundler_max_verification_gas", 1500000)
79+
viper.SetDefault("erc4337_bundler_max_verification_gas", 3000000)
8080
viper.SetDefault("erc4337_bundler_max_batch_gas_limit", 25000000)
8181
viper.SetDefault("erc4337_bundler_max_ops_for_unstaked_sender", 4)
8282
viper.SetDefault("erc4337_bundler_blocks_in_the_future", 25)

pkg/entrypoint/simulation/storageslots.go

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
4461
func 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
}

pkg/entrypoint/simulation/tracevalidation.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,18 @@ func TraceSimulateValidation(
8989

9090
slotsByEntity := newStorageSlotsByEntity(stakes, res.Keccak)
9191
for title, entity := range knownEntity {
92-
if err := validateStorageSlotsForEntity(
93-
title,
94-
op,
95-
entryPoint,
96-
slotsByEntity,
97-
entity.Info.Access,
98-
entity.Address,
99-
entity.IsStaked,
100-
); err != nil {
92+
v := &storageSlotsValidator{
93+
Op: op,
94+
EntryPoint: entryPoint,
95+
SenderSlots: slotsByEntity[op.Sender],
96+
FactoryIsStaked: knownEntity["factory"].IsStaked,
97+
EntityName: title,
98+
EntityAddr: entity.Address,
99+
EntityAccess: entity.Info.Access,
100+
EntitySlots: slotsByEntity[entity.Address],
101+
EntityIsStaked: entity.IsStaked,
102+
}
103+
if err := v.Process(); err != nil {
101104
return nil, err
102105
}
103106
}

0 commit comments

Comments
 (0)