Skip to content

Fix expire bid and event in schedule precompile #188

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

Open
wants to merge 7 commits into
base: natspecs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions EventTopics.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
| `AppGatewayCallRequested` | `(triggerId: bytes32, appGatewayId: bytes32, switchboardId: uint64, plug: bytes32, overrides: bytes, payload: bytes)` | `0x8ff0599581fd62c5733e52cea3abd7874731f4a9f86ebb929e5e4afe103f74d4` |
| `ExecutionFailed` | `(payloadId: bytes32, exceededMaxCopy: bool, returnData: bytes)` | `0x385334bc68a32c4d164625189adc7633e6074eb1b837fb4d11d768245151e4ce` |
| `ExecutionSuccess` | `(payloadId: bytes32, exceededMaxCopy: bool, returnData: bytes)` | `0x324d63a433b21a12b90e79cd2ba736b2a5238be6165e03b750fa4a7d5193d5d9` |
| `GasLimitBufferUpdated` | `(gasLimitBuffer: uint256)` | `0xd0e3eb5d0d212f0a08af2be98373721fc901ed26fbac645e08bd664fef818366` |
| `MaxCopyBytesUpdated` | `(maxCopyBytes: uint16)` | `0x294d0c11af52572317e5a0e1362cbf85b3b7c1f7b3f6c7b7e3e5c29c76da33e2` |
| `OwnershipHandoverCanceled` | `(pendingOwner: address)` | `0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92` |
| `OwnershipHandoverRequested` | `(pendingOwner: address)` | `0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d` |
| `OwnershipTransferred` | `(oldOwner: address, newOwner: address)` | `0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0` |
Expand Down Expand Up @@ -287,14 +289,14 @@

## SchedulePrecompile

| Event | Arguments | Topic |
| ------------------------------ | ---------------------------------------------------------------- | -------------------------------------------------------------------- |
| `ExpiryTimeSet` | `(expiryTime_: uint256)` | `0x07e837e13ad9a34715a6bd45f49bbf12de19f06df79cb0be12b3a7d7f2397fa9` |
| `MaxScheduleDelayInSecondsSet` | `(maxScheduleDelayInSeconds_: uint256)` | `0xfd5e4f0e96753ffb08a583390c2f151c51001d8e560625ab93b7fa7b4dac6d75` |
| `ScheduleCallbackFeesSet` | `(scheduleCallbackFees_: uint256)` | `0x82a2f41efc81ce7bfabc0affda7354dae42a3d09bd74a6196e8904b223138a52` |
| `ScheduleFeesPerSecondSet` | `(scheduleFeesPerSecond_: uint256)` | `0x7901a21229f6d2543d8676f53e21214d15f42513e7d46e0dcb510357222bdc7c` |
| `ScheduleRequested` | `(payloadId: bytes32, executeAfter: uint256, deadline: uint256)` | `0xd099d3e3d0f0e2c9c40e0066affeea125aab71d763b7ab0a279ccec3dff70b64` |
| `ScheduleResolved` | `(payloadId: bytes32)` | `0x925dc6c3ebffa07cac89d6e9675f1a5d04e045f2ed9a4fa442665935cb73e26b` |
| Event | Arguments | Topic |
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| `ExpiryTimeSet` | `(expiryTime_: uint256)` | `0x07e837e13ad9a34715a6bd45f49bbf12de19f06df79cb0be12b3a7d7f2397fa9` |
| `MaxScheduleDelayInSecondsSet` | `(maxScheduleDelayInSeconds_: uint256)` | `0xfd5e4f0e96753ffb08a583390c2f151c51001d8e560625ab93b7fa7b4dac6d75` |
| `ScheduleCallbackFeesSet` | `(scheduleCallbackFees_: uint256)` | `0x82a2f41efc81ce7bfabc0affda7354dae42a3d09bd74a6196e8904b223138a52` |
| `ScheduleFeesPerSecondSet` | `(scheduleFeesPerSecond_: uint256)` | `0x7901a21229f6d2543d8676f53e21214d15f42513e7d46e0dcb510357222bdc7c` |
| `ScheduleRequested` | `(payloadId: bytes32, executeAfter: uint256, deadline: uint256, localInvoker: address, callbackSelector: bytes4, callbackData: bytes)` | `0xbeceaccdb128631e58b881241d4fb46e53d8b2b2aa3f1ce77ba6fb80af038e30` |
| `ScheduleResolved` | `(payloadId: bytes32)` | `0x925dc6c3ebffa07cac89d6e9675f1a5d04e045f2ed9a4fa442665935cb73e26b` |

## WritePrecompile

Expand Down
4 changes: 2 additions & 2 deletions FunctionSignatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
| `consumeFrom` | `0x40dd78be` |
| `creationCodeWithArgs` | `0xc126dcc4` |
| `deployForwarder__` | `0xd4e3b034` |
| `endAuction` | `0x1212e653` |
| `endAuction` | `0x7426f0f6` |
| `evmxSlug` | `0x8bae77c2` |
| `expireBid` | `0x1dd5022c` |
| `expireBid` | `0x33b5b234` |
| `feesManager__` | `0x70568b58` |
| `forwarderAddresses` | `0x5390fdcb` |
| `getOnChainAddress` | `0xb6abffd7` |
Expand Down
25 changes: 14 additions & 11 deletions contracts/evmx/AuctionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ contract AuctionManager is AuctionManagerStorage, Initializable, AppGatewayBase,
}

/// @notice Ends an auction
/// @param requestCount_ The ID of the auction
function endAuction(uint40 requestCount_) external override onlyPromises {
/// @param data The encoded request count
function endAuction(bytes memory data, bytes memory) external onlyPromises {
uint40 requestCount_ = abi.decode(data, (uint40));
if (requestCount_ == 0) revert InvalidBid();
if (
auctionStatus[requestCount_] == AuctionStatus.CLOSED ||
auctionStatus[requestCount_] == AuctionStatus.NOT_STARTED
Expand Down Expand Up @@ -207,26 +209,27 @@ contract AuctionManager is AuctionManagerStorage, Initializable, AppGatewayBase,
/// @notice Expires a bid and restarts an auction in case a request is not fully executed.
/// @dev Auction can be restarted only for `maxReAuctionCount` times.
/// @dev It also unblocks the fees from last transmitter to be assigned to the new winner.
/// @param requestCount_ The request id
function expireBid(uint40 requestCount_) external override onlyPromises {
if (reAuctionCount[requestCount_] >= maxReAuctionCount) revert MaxReAuctionCountReached();
RequestParams memory requestParams = watcher__().getRequestParams(requestCount_);
/// @param data The encoded request count
function expireBid(bytes memory data, bytes memory) external override onlyPromises {
uint40 requestCount = abi.decode(data, (uint40));
if (reAuctionCount[requestCount] >= maxReAuctionCount) revert MaxReAuctionCountReached();
RequestParams memory requestParams = watcher__().getRequestParams(requestCount);

// if executed or cancelled, bid is not expired
if (
requestParams.requestTrackingParams.payloadsRemaining == 0 ||
requestParams.requestTrackingParams.isRequestCancelled
) return;

delete winningBids[requestCount_];
auctionStatus[requestCount_] = AuctionStatus.RESTARTED;
reAuctionCount[requestCount_]++;
delete winningBids[requestCount];
auctionStatus[requestCount] = AuctionStatus.RESTARTED;
reAuctionCount[requestCount]++;

watcher__().requestHandler__().assignTransmitter(
requestCount_,
requestCount,
Bid({fee: 0, transmitter: address(0), extraData: ""})
);
emit AuctionRestarted(requestCount_);
emit AuctionRestarted(requestCount);
}

function _createRequest(
Expand Down
9 changes: 5 additions & 4 deletions contracts/evmx/interfaces/IAuctionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ interface IAuctionManager {
) external;

/// @notice Ends an auction
/// @param requestCount_ The request count
function endAuction(uint40 requestCount_) external;
/// @param data The encoded request count
function endAuction(bytes memory data, bytes memory) external;

/// @notice Expires a bid and restarts an auction in case a request is not fully executed.
/// @dev Auction can be restarted only for `maxReAuctionCount` times.
/// @dev It also unblocks the fees from last transmitter to be assigned to the new winner.
/// @param requestCount_ The request id
function expireBid(uint40 requestCount_) external;
/// @param data The encoded request count
/// @param returnData The return data from the bid
function expireBid(bytes memory data, bytes memory returnData) external;

/// @notice Checks if an auction is closed
/// @param requestCount_ The request count
Expand Down
6 changes: 6 additions & 0 deletions contracts/evmx/interfaces/IPromise.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ interface IPromise {
/// @dev The callback will be executed on this address
function localInvoker() external view returns (address);

/// @notice The callback selector of the promise
function callbackSelector() external view returns (bytes4);

/// @notice The callback data of the promise
function callbackData() external view returns (bytes memory);

/// @notice The request count of the promise
function requestCount() external view returns (uint40);

Expand Down
22 changes: 20 additions & 2 deletions contracts/evmx/watcher/precompiles/SchedulePrecompile.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pragma solidity ^0.8.21;

import "../../interfaces/IPrecompile.sol";
import "../../interfaces/IPromise.sol";

import "../../../utils/common/Structs.sol";
import {InvalidScheduleDelay, ResolvingScheduleTooEarly} from "../../../utils/common/Errors.sol";
import "../../../utils/RescueFundsLib.sol";
Expand Down Expand Up @@ -32,7 +34,14 @@ contract SchedulePrecompile is IPrecompile, WatcherBase {
/// @notice Emitted when the expiry time for a schedule is set
event ExpiryTimeSet(uint256 expiryTime_);
/// @notice Emitted when a schedule is requested
event ScheduleRequested(bytes32 payloadId, uint256 executeAfter, uint256 deadline);
event ScheduleRequested(
bytes32 payloadId,
uint256 executeAfter,
uint256 deadline,
address localInvoker,
bytes4 callbackSelector,
bytes callbackData
);
/// @notice Emitted when a schedule is resolved
event ScheduleResolved(bytes32 payloadId);

Expand Down Expand Up @@ -128,8 +137,17 @@ contract SchedulePrecompile is IPrecompile, WatcherBase {
precompileData = abi.encode(delayInSeconds, executeAfter);
fees = getPrecompileFees(precompileData);

IPromise promise_ = IPromise(payloadParams.asyncPromise);

// emits event for watcher to track schedule and resolve when deadline is reached
emit ScheduleRequested(payloadParams.payloadId, executeAfter, deadline);
emit ScheduleRequested(
payloadParams.payloadId,
executeAfter,
deadline,
promise_.localInvoker(),
promise_.callbackSelector(),
promise_.callbackData()
);
}

function resolvePayload(PayloadParams calldata payloadParams_) external onlyRequestHandler {
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/SocketFeeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract SocketFeeManager is ISocketFeeManager, AccessControl {
* @notice Pays and validates fees for execution
* @dev This function is payable and will revert if the fees are insufficient
*/
function payAndCheckFees() external payable {
function payAndCheckFees(ExecuteParams memory, TransmissionParams memory) external payable {
if (msg.value < socketFees) revert InsufficientFees();
}

Expand Down
3 changes: 1 addition & 2 deletions contracts/protocol/switchboard/SwitchboardBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ abstract contract SwitchboardBase is ISwitchboard, AccessControl {
/**
* @notice Returns the transmitter for a given payload
* @dev If the transmitter signature is provided, the function will return the signer of the signature
* @param sender_ The sender of the payload
* @param payloadId_ The payload id
* @param transmitterSignature_ The transmitter signature (optional)
* @return transmitter The transmitter address
*/
function getTransmitter(
address sender_,
address,
bytes32 payloadId_,
bytes calldata transmitterSignature_
) external view returns (address transmitter) {
Expand Down
22 changes: 20 additions & 2 deletions deployments/dev_addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"AsyncDeployer": "0xF1D3ebDF91Cf4b1bc7C9A1D78413CD1Ed2d3123d",
"AsyncDeployerImpl": "0x8daf174Be9Bb708c04b708A92b88Cc89bd223498",
"AuctionManager": "0xE4243383566fcA32aA6815dE83e8EA86b2027b8b",
"AuctionManagerImpl": "0x122beAFCfc2E99D825322a78EAFD8a11fa2d9E0b",
"AuctionManagerImpl": "0x8EB4402AFAa335b05Bb37f80377F77eeC678b734",
"Configurations": "0x6a6697A2AD51DB9a41BaEE78e194335c1aD7369d",
"ConfigurationsImpl": "0x8A9256F31b0bb85863c253F8CAE800A32Cb2d595",
"DeployForwarder": "0xE986bCd19b8725ea3417C2A7728158ecABA6C8bE",
Expand All @@ -18,13 +18,31 @@
"ReadPrecompile": "0xE693bEc40e39223749AC351156E713b7256541B0",
"RequestHandler": "0xE785Fdbd049D0647e8B2Bd28C75a679dEBaD9D6f",
"RequestHandlerImpl": "0x5332d341cd7B423C2f75AF7Ca295455e5F08fAcb",
"SchedulePrecompile": "0x99af65efe676C4899F6e500DF18d4fD84dbe0A1D",
"SchedulePrecompile": "0x1099338aB85627640bB7A0D55c683921EA766C75",
"startBlock": 10904,
"Watcher": "0x96ACe2d4a36a1Fd6e3eeE1cD3FeDA36eA62E3064",
"WatcherImpl": "0xE5542FAB56B652A95aBD05a08E920687d1ef3849",
"WritePrecompile": "0x27794dd1166ED0c6A70c655C297BB79bF06bf44A",
"WritePrecompileImpl": "0xc2Ca571f4d4C2008Da4Bd750BaD3d50A5705ffF8"
},
"84532": {
"CCTPSwitchboard": "0xBD6770182fB47DD77924aDf3F200246Ab851f9c2",
"CCTPSwitchboardId": "2",
"ContractFactoryPlug": "0x6320Ff773a4E01Cb8EB849EA906F17Cf6c48Ff9c",
"FastSwitchboard": "0x2420B85D7e126d1948a4602f0c78a685655292Bd",
"FastSwitchboardId": "1",
"FeesPlug": "0x89634ecFea933aFaD5d3D6557b13cb8D466313d2",
"MessageSwitchboard": "0xd94741a4654953817faEe228739a6d10C0683839",
"MessageSwitchboardId": "3",
"Socket": "0xA90f2aB2804e8575D021882aAB74399fa282A8A3",
"SocketBatcher": "0x138C1B6e301C7d1B59920bEe2834f5B481bA39dF",
"startBlock": 29270214,
"SwitchboardIdToAddressMap": {
"1": "0x2420B85D7e126d1948a4602f0c78a685655292Bd",
"2": "0xBD6770182fB47DD77924aDf3F200246Ab851f9c2",
"3": "0xd94741a4654953817faEe228739a6d10C0683839"
}
},
"421614": {
"CCTPSwitchboard": "0xaF912b7eaD59f5d8c8179f8606A3fa93459a612C",
"CCTPSwitchboardId": "2",
Expand Down
1 change: 1 addition & 0 deletions deployments/dev_verification.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"14323": [],
"84532": [],
"421614": [],
"7625382": [
[
Expand Down
46 changes: 23 additions & 23 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ evm_version = 'paris'
via_ir = false

[labels]
0xAA77c2dE14CfFF4244a127deED6b53ce79481e14 = "AddressResolver"
0xe857a826D330Fc0429c67FaBEB8B66C26ea1DD5f = "AddressResolverImpl"
0x24c3f774c231ADFeb5e22Ad826a666A0FF9742C8 = "AsyncDeployer"
0xB7Bf09935108753491E59114dc0B713cDa6F703F = "AsyncDeployerImpl"
0xd5853f69f5dE728AEF7d1cF029cB3bF1581A4ED4 = "AuctionManager"
0x89A0D4550D5aFa809B74856624D4595188641BCe = "AuctionManagerImpl"
0x0f2801ee741A3BdeA2245d97AB54B1C4d7734534 = "Configurations"
0xD41d93042Dd1aB8c712C212A6907d4dC0718D021 = "ConfigurationsImpl"
0x54676a772aEe69E3F87178F2b5E4414dcE9A9720 = "DeployForwarder"
0x9882ce57b618175Bd9d3a4eC50ebD682B39bc467 = "DeployForwarderImpl"
0x61788F19CA1b098cE8437f8eb13B1Ad68f4FcD77 = "ERC1967Factory"
0x9339e8D915Aaf467d2fC01a4e694c8FE85621e94 = "FeesManager"
0x27b763c5410E83c02F21D97B33555729B77B2Ce1 = "FeesManagerImpl"
0xC8d803B7c1719cdF21392405879D1B56398045C4 = "FeesPool"
0x9BE3513a5d32E74935a54e5516b4daa198da5574 = "PromiseResolver"
0x784730D5e5D2F64eA63BfafeDC759317438c9186 = "ReadPrecompile"
0x22FaddfD47B9E0B545f83a2E7Cd05c12889c7a57 = "RequestHandler"
0xAA6EfF8dbd53B8d95a02c59Fe5C8A8422B08F5AA = "RequestHandlerImpl"
0x074118aB15e54A84b42Ff3de5233721434cF9f55 = "SchedulePrecompile"
0xdd25a87AeB5bCEeBAc0EB27aFfaBB6eB5a2857ca = "Watcher"
0xb143810f13fDF66F7a9B973252AEC80ec47FF0cb = "WatcherImpl"
0x66ce424303EC8499C5cdC4F6437A0434D8bd9b81 = "WritePrecompile"
0x962E1db23f6C5879A5c9D58CcB8c67CD282F1000 = "WritePrecompileImpl"
0x774f608eD8fc03B05a9da51588F8571ced4c2eb2 = "AddressResolver"
0x9c58dAABeBE7D6DfD8F70097c6f9c87FEC9b83DE = "AddressResolverImpl"
0xF1D3ebDF91Cf4b1bc7C9A1D78413CD1Ed2d3123d = "AsyncDeployer"
0x8daf174Be9Bb708c04b708A92b88Cc89bd223498 = "AsyncDeployerImpl"
0xE4243383566fcA32aA6815dE83e8EA86b2027b8b = "AuctionManager"
0x8EB4402AFAa335b05Bb37f80377F77eeC678b734 = "AuctionManagerImpl"
0x6a6697A2AD51DB9a41BaEE78e194335c1aD7369d = "Configurations"
0x8A9256F31b0bb85863c253F8CAE800A32Cb2d595 = "ConfigurationsImpl"
0xE986bCd19b8725ea3417C2A7728158ecABA6C8bE = "DeployForwarder"
0xfBe803842B50d8A2a91DA3dD88B67E92D5C0bd97 = "DeployForwarderImpl"
0x4f1Cd0CdBc7EA445b8B34Af8844fA4D4B5f48b79 = "ERC1967Factory"
0xa6D93e7B2cde3C8d318f45890dE3dB0a2E54058B = "FeesManager"
0x38A7558D2C3b4097c2098444a46D625D51E7336F = "FeesManagerImpl"
0x13A3018920c7b56B20dd34E29C298121025E6de4 = "FeesPool"
0x40834274ee715B1748e450A67cFf2B52b0388eC3 = "PromiseResolver"
0xE693bEc40e39223749AC351156E713b7256541B0 = "ReadPrecompile"
0xE785Fdbd049D0647e8B2Bd28C75a679dEBaD9D6f = "RequestHandler"
0x5332d341cd7B423C2f75AF7Ca295455e5F08fAcb = "RequestHandlerImpl"
0x1099338aB85627640bB7A0D55c683921EA766C75 = "SchedulePrecompile"
0x96ACe2d4a36a1Fd6e3eeE1cD3FeDA36eA62E3064 = "Watcher"
0xE5542FAB56B652A95aBD05a08E920687d1ef3849 = "WatcherImpl"
0x27794dd1166ED0c6A70c655C297BB79bF06bf44A = "WritePrecompile"
0xc2Ca571f4d4C2008Da4Bd750BaD3d50A5705ffF8 = "WritePrecompileImpl"
5 changes: 3 additions & 2 deletions test/apps/app-gateways/counter/CounterAppGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ contract CounterAppGateway is AppGatewayBase, Ownable {
then(this.resolveSchedule.selector, abi.encode(block.timestamp));
}

function resolveSchedule(uint256 creationTimestamp_) external onlyPromises {
emit CounterScheduleResolved(creationTimestamp_, block.timestamp);
function resolveSchedule(bytes memory data, bytes memory) external onlyPromises {
uint256 creationTimestamp = abi.decode(data, (uint256));
emit CounterScheduleResolved(creationTimestamp, block.timestamp);
}

// UTILS
Expand Down