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 tips easier to understand/trace #1464

Closed
ChiTimesChi opened this issue Oct 19, 2023 · 1 comment
Closed

Make tips easier to understand/trace #1464

ChiTimesChi opened this issue Oct 19, 2023 · 1 comment

Comments

@ChiTimesChi
Copy link
Collaborator

The tips encoding scheme could be massively improved. I see two directions that would improve the overall system:

  • Change the location of the encoded tips. The full message tip value belongs in the message header.
    /// # Header stack layout (from highest bits to lowest)
    ///
    /// | Position | Field | Type | Bytes | Description |
    /// | ---------- | ---------------- | ------ | ----- | --------------------------------------- |
    /// | (017..016] | flag | uint8 | 1 | Flag specifying the type of message |
    /// | (016..012] | origin | uint32 | 4 | Domain where message originated |
    /// | (012..008] | nonce | uint32 | 4 | Message nonce on the origin domain |
    /// | (008..004] | destination | uint32 | 4 | Domain where message will be executed |
    /// | (004..000] | optimisticPeriod | uint32 | 4 | Optimistic period that will be enforced |

    Right now, the tips are encoded in the body of the base message, and are nowhere to be found in the manager message (that doesn't have any tips), which is hard to track.

  • Change the tips encoding schema as well. Instead of storing values scaled down by 2*32 (which causes bugs like Fix: tips scaling in Summit #1463), we could store the total tips value, as well as distribution ratios between the off-chain actors (which don't need high resolution, and could be fit into 8/16 bits each).
Copy link

greptile-apps bot commented Jun 24, 2024

To improve the tips encoding scheme, follow these steps:

  1. Move Tips to Header:

    • Update HeaderLib in Header.sol to include tips.
    struct Header {
        uint136 data;
        uint256 tips; // Add this line
    }
    • Modify encodeHeader to accept tips and encode them.
    function encodeHeader(
        MessageFlag flag_,
        uint32 origin_,
        uint32 nonce_,
        uint32 destination_,
        uint32 optimisticPeriod_,
        uint256 tips_ // Add this line
    ) internal pure returns (Header) {
        return Header.wrap(
            uint136(uint8(flag_)) << SHIFT_FLAG |
            uint136(origin_) << SHIFT_ORIGIN |
            uint136(nonce_) << SHIFT_NONCE |
            uint136(destination_) << SHIFT_DESTINATION |
            uint136(optimisticPeriod_),
            tips_ // Add this line
        );
    }
  2. Change Tips Encoding Schema:

    • Update TipsLib in Tips.sol to store total tips value and distribution ratios.
    struct Tips {
        uint256 totalValue;
        uint16 summitRatio;
        uint16 attestationRatio;
        uint16 executionRatio;
        uint16 deliveryRatio;
    }
    • Modify encodeTips to accept and encode these values.
    function encodeTips(uint256 totalValue_, uint16 summitRatio_, uint16 attestationRatio_, uint16 executionRatio_, uint16 deliveryRatio_) internal pure returns (Tips) {
        return Tips({
            totalValue: totalValue_,
            summitRatio: summitRatio_,
            attestationRatio: attestationRatio_,
            executionRatio: executionRatio_,
            deliveryRatio: deliveryRatio_
        });
    }
  3. Update Summit Contract:

    • Modify Summit.sol to handle the new tips structure.
    function _saveReceipt(
        Receipt rcpt,
        Tips tips,
        uint32 rcptNotaryIndex,
        uint32 attNotaryIndex,
        uint256 sigIndex,
        uint32 attNonce
    ) internal returns (bool) {
        // Use tips.totalValue and tips ratios for processing
    }
  4. Update Tests:

    • Modify TipsHarness.t.sol and Tips.t.sol to test the new encoding schema and header changes.
    function test_encodeTips(uint256 totalValue, uint16 summitRatio, uint16 attestationRatio, uint16 executionRatio, uint16 deliveryRatio) public {
        uint256 encodedTips = libHarness.encodeTips(totalValue, summitRatio, attestationRatio, executionRatio, deliveryRatio);
        // Add assertions to validate the new structure
    }

References

/packages/contracts-core/contracts/libs/stack/Tips.sol
/packages/contracts-core/contracts/libs/stack/Header.sol
/packages/contracts-core/contracts/Summit.sol
/packages/contracts-core/test/harnesses/libs/stack/TipsHarness.t.sol
/packages/contracts-core/test/suite/libs/stack/Tips.t.sol

Ask Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants