Skip to content
Verified contractPartialMIT

CrowdWhisper

Address0x58a6e12458b526507a03c4fa425f1907dce53751
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 1,000 runs
EVM version
cancun
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,385,196
Creation transaction
0x324b7d4d64…7ffae8d1c0

src/CrowdWhisper.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

// Website : https://crowdonerc.xyz
// X       : https://x.com/CrowdOnERC

/*
    CROWD WHISPER

    The wall with the lights off. Anyone holding a zero-knowledge proof that they control one of the wallets
    in the Veil (see CrowdVeil.sol) can leave a message here, and nobody can tell which wallet it was.

    Each wallet speaks under one stable pseudonym, its nullifier: every whisper of a wallet carries the same
    nullifier, so its messages link to each other but not to the wallet. The proof is tied to the text, so a
    proof cannot be reused to say something else. Who sends the transaction is irrelevant and is not recorded
    by this contract; send it from a wallet that says nothing about you (or through a relayer).

    Messages are not stored: they are emitted as events. Public, permanent, no owner, no moderation.
*/

interface IVeil {
    function isRoot(bytes32 root) external view returns (bool);
}

interface IVeilVerifier {
    function verify(bytes calldata proof, bytes32[] calldata publicInputs) external view returns (bool);
}

contract CrowdWhisper {
    error UnknownRoot();
    error BadLength();
    error BadProof();
    error AlreadyWhispered();

    /// @param nullifier  the speaker's pseudonym: the same for every whisper of one wallet
    /// @param index      position of this message on the wall, starting at 1
    event Whispered(bytes32 indexed nullifier, uint256 index, string text);

    IVeil public immutable veil;
    IVeilVerifier public immutable verifier;
    uint256 public constant MAX_LENGTH = 280;
    /// @notice How many messages the wall holds.
    uint256 public count;
    /// @notice keccak256(nullifier, msgHash) of every whisper so far: the same pseudonym cannot post the
    ///         same text twice (which also stops a proof from being replayed).
    mapping(bytes32 => bool) public whispered;

    constructor(IVeil veil_, IVeilVerifier verifier_) {
        veil = veil_;
        verifier = verifier_;
    }

    /// @notice Post `text` anonymously.
    /// @param proof      the proof from the zk library's prove()
    /// @param root       the Veil root the proof was made against (any root the Veil has held)
    /// @param nullifier  the pseudonym the proof commits to
    function whisper(bytes calldata proof, bytes32 root, bytes32 nullifier, string calldata text) external {
        if (!veil.isRoot(root)) revert UnknownRoot();
        uint256 len = bytes(text).length;
        if (len == 0 || len > MAX_LENGTH) revert BadLength();

        bytes32 msgHash = msgHashOf(text);
        bytes32[] memory publicInputs = new bytes32[](3);
        publicInputs[0] = root;
        publicInputs[1] = nullifier;
        publicInputs[2] = msgHash;
        // the verifier reverts on most bad proofs and returns false on the rest
        if (!verifier.verify(proof, publicInputs)) revert BadProof();

        bytes32 key = keccak256(abi.encode(nullifier, msgHash));
        if (whispered[key]) revert AlreadyWhispered();
        whispered[key] = true;

        emit Whispered(nullifier, ++count, text);
    }

    /// @notice The hash of a text as the proof sees it: keccak256 with the last byte dropped, so it fits the field.
    function msgHashOf(string calldata text) public pure returns (bytes32) {
        return bytes32(uint256(keccak256(bytes(text))) >> 8);
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 1000,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/contracts/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/contracts/",
    "@uniswap/v4-core/=lib/v4-periphery/lib/v4-core/",
    "v4-core/=lib/v4-periphery/lib/v4-core/",
    "v4-periphery/=lib/v4-periphery/",
    "forge-std/=lib/forge-std/src/",
    "solmate/=lib/v4-periphery/lib/v4-core/lib/solmate/",
    "permit2/=lib/v4-periphery/lib/permit2/",
    "lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/lib/forge-std/:ds-test/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/lib/forge-std/lib/ds-test/src/",
    "lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/lib/forge-std/:ds-test/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/lib/forge-std/lib/ds-test/src/",
    "lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "lib/v4-periphery/lib/permit2/lib/forge-std/:ds-test/=lib/v4-periphery/lib/permit2/lib/forge-std/lib/ds-test/src/",
    "lib/v4-periphery/lib/permit2/lib/forge-std/:ds-test/=lib/v4-periphery/lib/permit2/lib/forge-std/lib/ds-test/src/",
    "lib/v4-periphery/lib/permit2/lib/solmate/:ds-test/=lib/v4-periphery/lib/permit2/lib/solmate/lib/ds-test/src/",
    "lib/v4-periphery/lib/permit2/lib/solmate/:ds-test/=lib/v4-periphery/lib/permit2/lib/solmate/lib/ds-test/src/",
    "lib/v4-periphery/lib/v4-core/lib/solmate/:ds-test/=lib/v4-periphery/lib/v4-core/lib/solmate/lib/ds-test/src/",
    "lib/v4-periphery/lib/v4-core/lib/solmate/:ds-test/=lib/v4-periphery/lib/v4-core/lib/solmate/lib/ds-test/src/",
    "lib/v4-periphery/lib/permit2/:openzeppelin-contracts/=lib/v4-periphery/lib/permit2/lib/openzeppelin-contracts/",
    "lib/v4-periphery/lib/permit2/:openzeppelin-contracts/=lib/v4-periphery/lib/permit2/lib/openzeppelin-contracts/",
    "lib/v4-periphery/lib/v4-core/:openzeppelin-contracts/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
    "lib/v4-periphery/lib/v4-core/:openzeppelin-contracts/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
    "@ensdomains/=lib/v4-periphery/lib/v4-core/node_modules/@ensdomains/",
    "@openzeppelin/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
    "ds-test/=lib/v4-periphery/lib/permit2/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
    "hardhat/=lib/v4-periphery/lib/v4-core/node_modules/hardhat/",
    "openzeppelin-contracts/=lib/v4-periphery/lib/permit2/lib/openzeppelin-contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.