Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make check() an independent smart contract #5

Open
0xjei opened this issue Oct 21, 2024 · 1 comment · May be fixed by #9
Open

Make check() an independent smart contract #5

0xjei opened this issue Oct 21, 2024 · 1 comment · May be fixed by #9
Assignees
Labels
research Insight into technologies
Milestone

Comments

@0xjei
Copy link
Member

0xjei commented Oct 21, 2024

There's a proposal for changing the _check() method to be an independent smart contract (Checker). We must understand the trade-offs mainly in reuse of gatekeepers, DX and gas consumption. This alternative is going to be executed on the ar/checker-contract branch.

@0xjei 0xjei self-assigned this Oct 21, 2024
@0xjei 0xjei added the research Insight into technologies label Oct 21, 2024
@0xjei 0xjei added this to the [MVP-1] Heart milestone Oct 21, 2024
@0xjei
Copy link
Member Author

0xjei commented Oct 25, 2024

After some discussions & feedbacks and classic trial-and-error approach, the drafty new core structure including a Checker contract will be something similar to the following.

// Base interface.
interface IChecker {
    function check(address passerby, bytes memory data) external view;
}

// Simple Checker for base use cases.
abstract contract SimpleChecker is IChecker {
    function check(address passerby, bytes memory data) external view virtual {
        _check(passerby, data);
    }
   
    function _check(address passerby, bytes memory data) internal view virtual;
}

// Advanced Checker for complex flows
// Used MAIN instead of CONTINUE for
// PRE-MAIN-POST and main check can be done >= 1 times.
abstract contract AdvancedChecker is IChecker {
    enum Phase { PRE, MAIN, POST }
    
    struct CheckStatus {
        bool preExecuted;
        bool mainExecuted;
        bool postExecuted;
    }
    
    mapping(address => CheckStatus) public checkStatus;
    uint8 public configFlags;
    
    function check(address passerby, bytes memory data) external view override {
        if (!_shouldSkipPhase(Phase.PRE)) {
            _checkPre(passerby, data);
        }
        _checkMain(passerby, data);
        if (!_shouldSkipPhase(Phase.POST)) {
            _checkPost(passerby, data);
        }
    }
    
    function _checkPre(address passerby, bytes memory data) internal view virtual {}
    function _checkMain(address passerby, bytes memory data) internal view virtual;
    function _checkPost(address passerby, bytes memory data) internal view virtual {}
}

// Factory pattern for checker creation.
contract CheckerFactory {
    function createSimpleChecker() external returns (address);
    function createAdvancedChecker(uint8 configFlags) external returns (address);
}

// Modified Excubia base.
abstract contract Excubia is IExcubia {
    IChecker public immutable checker;
    
    constructor(IChecker _checker) {
        checker = _checker;
    }
    
    function pass(address passerby, bytes calldata data) external virtual onlyGate {
        checker.check(passerby, data);
        emit GatePassed(passerby, gate);
    }
}

@0xjei 0xjei linked a pull request Nov 6, 2024 that will close this issue
20 tasks
@0xjei 0xjei linked a pull request Nov 22, 2024 that will close this issue
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
research Insight into technologies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant