Skip to content

[Feat] ZippersΒ #14

@fubuloubu

Description

@fubuloubu

Add the ability to enable "Zippers" which implement pre-/post- transaction checks on the execution of certain callbacks (reminiscent of Safe's Guards)

Sketch: (update Purse.vy)

interface Zipper:
    def unzip(accessory: address, indata: Bytes[65535]): view
    def rezip(accessory: address, indata: Bytes[65535], outdata: Bytes[65535]): view


zippers: public(HashMap[bytes4, Zipper])


event ZipperUpdated:
    method: indexed(bytes4)
    old_zipper: indexed(Zipper)
    new_zipper: indexed(Zipper)

...

struct ZipperUpdate:
    method: bytes4
    zipper: Zipper


@external
# NOTE: Reentrancy guard ensures that `__default__` module calls can't call this
def update_zippers(updates: DynArray[ZipperUpdate, 100]):
    # NOTE: Can only work in a EIP-7702 context
    assert tx.origin == self and tx.origin == msg.sender, "Purse:!authorized"

    for update: ZipperUpdate in updates:
        old_zipper: Zipper = self.zippers[update.method]
        self.zippers[update.method] = update.zipper

        log ZipperUpdated(
            method=update.method,
            old_zipper=old_zipper,
            new_zipper=update.zipper,
        )

...

def __default__():
    ...  # Load accessory by `method`

    zipper: Zipper = self.zippers[method]
    if zipper.address != empty(address):
        staticcall zipper.unzip(accessory, msg.data)

    data: Bytes[65535] = ...  # Call accessory w/ `msg.data`

    if zipper.address != empty(address):
        staticcall zipper.rezip(accessory, msg.data, data)

    return data  # NOTE: Need to temporarily store return data

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions