Verified contractExactMIT
ConsultEscrow
Address0xa01b54fa6970f774071d8e43754e34ee8d568ef8
- Balance
0 ETH
- Transactions
3
- Compiler
solc 0.8.24
- Same code
Only this contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,460,272
- Creation transaction
- 0x019169682f…81619a337d
src/ConsultEscrow.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/// @title ConsultEscrow — trustless pay-on-delivery for agent consultations
/// @notice A consumer locks payment for a consultation; it releases to the provider
/// only when the named attestor (the agent's signer / a verifier) signs the
/// result's WYRIWE commitment, or refunds the consumer after a deadline if no
/// valid result is delivered. No valid signed result -> no payment.
contract ConsultEscrow {
enum Status { None, Open, Released, Refunded }
struct Job {
address consumer;
address provider;
address attestor; // key whose signature over commitmentHash authorizes release
uint256 amount;
uint256 deadline;
Status status;
}
mapping(bytes32 => Job) public jobs;
event Opened(bytes32 indexed jobId, address indexed consumer, address indexed provider, address attestor, uint256 amount, uint256 deadline);
event Released(bytes32 indexed jobId, bytes32 commitmentHash, address provider, uint256 amount);
event Refunded(bytes32 indexed jobId, address consumer, uint256 amount);
/// @notice Consumer locks payment for `jobId`, naming the provider and the attestor.
function open(bytes32 jobId, address provider, address attestor, uint256 deadline) external payable {
require(jobs[jobId].status == Status.None, "job exists");
require(msg.value > 0, "no payment");
require(provider != address(0) && attestor != address(0), "zero addr");
require(deadline > block.timestamp, "deadline past");
jobs[jobId] = Job(msg.sender, provider, attestor, msg.value, deadline, Status.Open);
emit Opened(jobId, msg.sender, provider, attestor, msg.value, deadline);
}
/// @notice Release to the provider on proof the attestor signed the result commitment.
/// @param commitmentHash the WYRIWE commitment binding the query, report and agent
/// @param signature EIP-191 personal_sign of commitmentHash by the attestor
function release(bytes32 jobId, bytes32 commitmentHash, bytes calldata signature) external {
Job storage j = jobs[jobId];
require(j.status == Status.Open, "not open");
require(_recover(commitmentHash, signature) == j.attestor, "bad attestor sig");
j.status = Status.Released;
uint256 amt = j.amount;
(bool ok, ) = j.provider.call{value: amt}("");
require(ok, "pay failed");
emit Released(jobId, commitmentHash, j.provider, amt);
}
/// @notice Refund the consumer if the deadline passed without a valid release.
function refund(bytes32 jobId) external {
Job storage j = jobs[jobId];
require(j.status == Status.Open, "not open");
require(block.timestamp >= j.deadline, "before deadline");
j.status = Status.Refunded;
uint256 amt = j.amount;
(bool ok, ) = j.consumer.call{value: amt}("");
require(ok, "refund failed");
emit Refunded(jobId, j.consumer, amt);
}
function _recover(bytes32 hash, bytes calldata sig) internal pure returns (address) {
require(sig.length == 65, "bad sig len");
bytes32 r; bytes32 s; uint8 v;
assembly {
r := calldataload(sig.offset)
s := calldataload(add(sig.offset, 32))
v := byte(0, calldataload(add(sig.offset, 64)))
}
bytes32 ethHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
return ecrecover(ethHash, v, r, s);
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.