Verified contractPartialMIT
DareComments
Address0x0b495e1e2c40ef2ae8f45b7857f1d98fd4469915
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,272,730
- Creation transaction
- 0xefe223b7ac…37d6b75a18
src/DareComments.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
/// @title DareComments
/// @notice Comments under tasks and proofs, written to the chain as events. Standalone: no core contract reads it and
/// it reads no core contract, so a comment may name any `targetId` (the site shows only the ones that exist).
/// It holds no money (no `payable`, no `receive`, no token call), has no owner, no role, no upgrade.
/// Key of a thread: `(vault, kind, targetId)`, kind 1 = task, 2 = proof (a dispute lives on its proof).
/// Comment ids are global, from 1. A reply names its parent's id, which must be in the same thread.
/// Hiding is not here: the site's HiddenList takes `(address(this), 3, id)` like any other item.
/// Reading without an archive node: `lastBlock(vault, kind, targetId)` is the block of a thread's newest
/// comment and each event names `prevBlock`, the block of the thread's comment before it (0 for the first),
/// so a reader asks getLogs for single blocks along that chain instead of scanning from the deployment.
contract DareComments {
uint8 public constant KIND_TASK = 1;
uint8 public constant KIND_PROOF = 2;
uint256 public constant MAX_TEXT = 500;
/// @notice Ids handed out so far; the next comment gets `count + 1`.
uint256 public count;
/// @dev id => keccak256(vault, kind, targetId) of its thread; only for checking a reply's parent.
mapping(uint256 => bytes32) private _thread;
/// @dev keccak256(vault, kind, targetId) => block of the thread's newest comment, 0 = none yet.
mapping(bytes32 => uint256) private _last;
event Comment(
uint256 indexed id,
address indexed vault,
uint256 indexed targetId,
uint8 kind,
uint256 parentId,
address author,
string text,
uint256 prevBlock
);
error BadKind();
error BadText();
error BadParent();
/// @notice Posts `text` (UTF-8, 1..500 bytes) under item `targetId` of `vault`; `parentId` 0 = top level,
/// else the id of a comment of the same `(vault, kind, targetId)`. Returns the new comment's id.
function post(address vault, uint8 kind, uint256 targetId, uint256 parentId, string calldata text)
external
returns (uint256 id)
{
if (kind != KIND_TASK && kind != KIND_PROOF) revert BadKind();
uint256 len = bytes(text).length;
if (len == 0 || len > MAX_TEXT) revert BadText();
bytes32 t = keccak256(abi.encode(vault, kind, targetId));
if (parentId != 0 && _thread[parentId] != t) revert BadParent();
id = ++count;
_thread[id] = t;
uint256 prev = _last[t];
_last[t] = block.number;
emit Comment(id, vault, targetId, kind, parentId, msg.sender, text, prev);
}
/// @notice Block of the newest comment of thread `(vault, kind, targetId)`, 0 when it has none.
function lastBlock(address vault, uint8 kind, uint256 targetId) external view returns (uint256) {
return _last[keccak256(abi.encode(vault, kind, targetId))];
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"bytecodeHash": "none"
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"/tmp/imd-attest-nQhWki/repo/lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"/tmp/imd-attest-nQhWki/repo/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"/tmp/imd-attest-nQhWki/repo/lib/v4-core/:openzeppelin-contracts/=lib/v4-core/lib/openzeppelin-contracts/",
"/tmp/imd-attest-nQhWki/repo/lib/v4-core/:solmate/=lib/v4-core/lib/solmate/",
"/tmp/imd-attest-nQhWki/repo/lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"/tmp/imd-attest-nQhWki/repo/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"/tmp/imd-attest-nQhWki/repo/lib/v4-core/lib/solmate/:ds-test/=lib/v4-core/lib/solmate/lib/ds-test/src/",
":@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
":@openzeppelin/=lib/v4-core/lib/openzeppelin-contracts/",
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
":hardhat/=lib/v4-core/node_modules/hardhat/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":solmate/=lib/v4-core/lib/solmate/",
":v4-core/=lib/v4-core/",
"lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"lib/v4-core/:openzeppelin-contracts/=lib/v4-core/lib/openzeppelin-contracts/",
"lib/v4-core/:solmate/=lib/v4-core/lib/solmate/",
"lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"lib/v4-core/lib/solmate/:ds-test/=lib/v4-core/lib/solmate/lib/ds-test/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.