Verified contractExactMIT
DuelEnrollSystem
Address0x0573f2d2cd4cdb1a1003795a9dcd728b7e7cf1ef
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.24
- Same code
Only this contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 3,000 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,481,290
- Creation transaction
- 0x72cf737594…1291d99bc0
89 files
The source code is large: one file is shown at a time. Choose a file in the list.
- src/namespaces/root/DuelEnrollSystem.solmain6.04 KB
- node_modules/@latticexyz/schema-type/src/solidity/SchemaType.sol3.72 KB
- node_modules/@latticexyz/store/src/Bytes.sol35.98 KB
- node_modules/@latticexyz/store/src/EncodedLengths.sol9.33 KB
- node_modules/@latticexyz/store/src/FieldLayout.sol8.62 KB
- node_modules/@latticexyz/store/src/Hook.sol3.97 KB
- node_modules/@latticexyz/store/src/IERC165.sol576 B
- node_modules/@latticexyz/store/src/IEncodedLengthsErrors.sol737 B
- node_modules/@latticexyz/store/src/IFieldLayoutErrors.sol2.26 KB
- node_modules/@latticexyz/store/src/ISchemaErrors.sol834 B
- node_modules/@latticexyz/store/src/ISliceErrors.sol894 B
- node_modules/@latticexyz/store/src/IStore.sol321 B
- node_modules/@latticexyz/store/src/IStoreErrors.sol4.12 KB
- node_modules/@latticexyz/store/src/IStoreEvents.sol2.91 KB
- node_modules/@latticexyz/store/src/IStoreHook.sol6.12 KB
- node_modules/@latticexyz/store/src/IStoreKernel.sol988 B
- node_modules/@latticexyz/store/src/IStoreRead.sol3.95 KB
- node_modules/@latticexyz/store/src/IStoreRegistration.sol1.12 KB
- node_modules/@latticexyz/store/src/IStoreWrite.sol2.36 KB
- node_modules/@latticexyz/store/src/Memory.sol2.06 KB
- node_modules/@latticexyz/store/src/ResourceId.sol2.21 KB
- node_modules/@latticexyz/store/src/Schema.sol7.69 KB
- node_modules/@latticexyz/store/src/Slice.sol4.49 KB
- node_modules/@latticexyz/store/src/Storage.sol9.76 KB
- node_modules/@latticexyz/store/src/StoreCore.sol54.25 KB
- node_modules/@latticexyz/store/src/StoreSwitch.sol22.54 KB
- node_modules/@latticexyz/store/src/codegen/index.sol320 B
- node_modules/@latticexyz/store/src/codegen/tables/Hooks.sol15.66 KB
- node_modules/@latticexyz/store/src/codegen/tables/ResourceIds.sol7.18 KB
- node_modules/@latticexyz/store/src/codegen/tables/StoreHooks.sol15.06 KB
- node_modules/@latticexyz/store/src/codegen/tables/Tables.sol26.58 KB
- node_modules/@latticexyz/store/src/constants.sol1.73 KB
- node_modules/@latticexyz/store/src/rightMask.sol838 B
- node_modules/@latticexyz/store/src/storeHookTypes.sol1.78 KB
- node_modules/@latticexyz/store/src/storeResourceTypes.sol515 B
- node_modules/@latticexyz/store/src/tightcoder/DecodeSlice.sol46.44 KB
- node_modules/@latticexyz/store/src/tightcoder/EncodeArray.sol46.1 KB
- node_modules/@latticexyz/store/src/tightcoder/TightCoder.sol3.81 KB
- node_modules/@latticexyz/store/src/version.sol348 B
- node_modules/@latticexyz/world/src/IERC165.sol813 B
- node_modules/@latticexyz/world/src/IWorldContextConsumer.sol1.54 KB
- node_modules/@latticexyz/world/src/System.sol570 B
- node_modules/@latticexyz/world/src/WorldContext.sol9.21 KB
- node_modules/@latticexyz/world/src/revertWithBytes.sol566 B
- node_modules/solady/src/utils/DynamicArrayLib.sol37.21 KB
- node_modules/solady/src/utils/ECDSA.sol20.2 KB
- node_modules/solady/src/utils/LibBytes.sol38.18 KB
- node_modules/solady/src/utils/LibPRNG.sol22.51 KB
- node_modules/solady/src/utils/LibString.sol44.25 KB
- node_modules/solady/src/utils/SafeCastLib.sol23.8 KB
- node_modules/solady/src/utils/SafeTransferLib.sol32.86 KB
- src/codegen/common.sol527 B
- src/namespaces/app/codegen/tables/Account.sol12.37 KB
- src/namespaces/app/codegen/tables/AccountStatus.sol14.02 KB
- src/namespaces/app/codegen/tables/ActiveTaruchi.sol6.3 KB
- src/namespaces/app/codegen/tables/AuthRoles.sol6.89 KB
- src/namespaces/app/codegen/tables/BattleResult.sol13.82 KB
- src/namespaces/app/codegen/tables/Commit.sol6.85 KB
- src/namespaces/app/codegen/tables/Config.sol6.52 KB
- src/namespaces/app/codegen/tables/Data.sol7.97 KB
- src/namespaces/app/codegen/tables/Duel.sol15.56 KB
- src/namespaces/app/codegen/tables/DuelMetadata.sol6.38 KB
- src/namespaces/app/codegen/tables/TaruchiCore.sol11.99 KB
- src/namespaces/app/codegen/tables/TaruchiName.sol6.62 KB
- src/namespaces/app/codegen/tables/TaruchiStatus.sol18.6 KB
- src/namespaces/app/codegen/tables/TaruchiTourney.sol6.34 KB
- src/namespaces/app/codegen/tables/Tourney.sol13.66 KB
- src/namespaces/app/codegen/tables/TourneyMetadata.sol6.39 KB
- src/namespaces/app/codegen/tables/TourneyResult.sol8.18 KB
- src/namespaces/app/codegen/tables/TraitNames.sol6.62 KB
- src/namespaces/app/codegen/tables/TraitsRegistry.sol14.86 KB
- src/namespaces/app/libraries/BattleEngine.sol50.63 KB
- src/namespaces/app/libraries/LibDuel.sol13.73 KB
- src/namespaces/app/libraries/LibOnyx.sol29.47 KB
- src/namespaces/app/libraries/LibTourney.sol21.22 KB
- src/namespaces/app/libraries/LibWeth.sol10.93 KB
- src/namespaces/app/libraries/Taruchi.sol18.48 KB
- src/namespaces/app/libraries/Traits.sol14.6 KB
- src/namespaces/app/libraries/utils/LibAffinity.sol3.97 KB
- src/namespaces/app/libraries/utils/LibAuthRoles.sol1.06 KB
- src/namespaces/app/libraries/utils/LibBlockHeader.sol6.45 KB
- src/namespaces/app/libraries/utils/LibCommit.sol6.72 KB
- src/namespaces/app/libraries/utils/LibData.sol2.49 KB
- src/namespaces/app/libraries/utils/LibPack.sol7.13 KB
- src/namespaces/app/libraries/utils/LibProgression.sol2.32 KB
- src/namespaces/app/libraries/utils/LibRandom.sol6.96 KB
- src/namespaces/app/libraries/utils/LibSpec.sol7.33 KB
- src/namespaces/app/libraries/utils/LibStats.sol3.34 KB
- src/namespaces/app/libraries/utils/LibXP.sol6.92 KB
src/namespaces/root/DuelEnrollSystem.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;
import { System } from "@latticexyz/world/src/System.sol";
import { Bracket } from "common/common.sol";
import { LibAuthRoles, Role } from "libraries/utils/LibAuthRoles.sol";
import { LibCommit } from "libraries/utils/LibCommit.sol";
import { LibDuel } from "libraries/LibDuel.sol";
import { LibWeth } from "libraries/LibWeth.sol";
import { Taruchi } from "libraries/Taruchi.sol";
/// @notice Duel enrollment with EIP-712 signature verification.
/// @dev RELAYER-gated: only addresses with `Role.RELAYER` (the trusted matchmaker)
/// can submit. Player intents are still authorized via 2 EIP-712 `DuelAuth` sigs
/// — the gate restricts WHO can submit the bundle, not who can sign it.
/// Mirrors TourneyEnrollSystem's RELAYER gate so duels and festivals share the
/// same trust topology: keryx is the single matchmaker path on-chain, no third
/// party can replay harvested sigs at an inconvenient block. `forceDuelResolve`
/// stays REVEALER-gated as the after-256-block escape valve for stuck duels.
/// Runs in root namespace so WETH gas collection uses World as approval target.
/// CEI: duel row (battleEnroll both taruchis) is written BEFORE either fee transfer —
/// a reentrant caller hits verifyState(IDLE) and reverts without needing a guard.
/// Each signer reimburses half the enroll gas in WETH at their own signed `maxGasPrice` cap;
/// WETH lands at `_msgSender()` (the relayer who submitted the tx).
contract DuelEnrollSystem is System {
error SelfDuel();
/// @dev Bundles enrollment numerics into a single memory pointer so helpers don't blow stack.
struct EnrollArgs {
uint64 players;
uint64 specs;
uint256 deadlines;
uint256 maxGasPrices;
Bracket bracket;
}
struct DuelSigners {
address signerA;
address signerB;
}
/// @param players Packed: playerAIndex (low 32), playerBIndex (high 32)
/// @param bracket Non-festival bracket for the duel
/// @param specs Packed: specA (low 32), specB (high 32)
/// @param deadlines Packed: deadlineA (low 128), deadlineB (high 128)
/// @param maxGasPrices Packed: maxGasPriceA (low 128), maxGasPriceB (high 128) — wei units
/// @param sigA EIP-712 signature from player A
/// @param sigB EIP-712 signature from player B
/// @param secretHash keccak(secret) co-seed commitment, folded into the duelId (see LibCommit).
/// @dev secretHash is NOT part of the player-signed DuelAuth struct — the RELAYER supplies it and
/// players have no on-chain recourse over its value. The co-seed anti-grind guarantee is only
/// as strong as the relayer's CSPRNG discipline: a weak/reused/predictable secret silently
/// restores the grindable state (the zero value is the one case rejected on-chain). If the
/// signing scheme is ever revised, secretHash is a candidate for inclusion in the signed struct.
function duelEnroll(
uint64 players,
Bracket bracket,
uint64 specs,
uint256 deadlines,
uint256 maxGasPrices,
bytes calldata sigA,
bytes calldata sigB,
bytes32 secretHash
) external returns (uint256 duelId) {
LibAuthRoles.verifyRole(_msgSender(), Role.RELAYER);
if ((players & type(uint32).max) == ((players >> 32) & type(uint32).max)) revert SelfDuel();
// Reject a zero commitment up front — it binds the id to a secret no one can ever reveal,
// leaving the duel unresolvable on both the normal and force paths.
if (secretHash == bytes32(0)) revert LibCommit.ZeroCoSeedCommit();
EnrollArgs memory args = EnrollArgs(players, specs, deadlines, maxGasPrices, bracket);
DuelSigners memory signers = _verifyBothIntents(args, sigA, sigB);
// effects
duelId = _createDuel(args, secretHash);
// interactions last
_settle(signers, args, _msgSender());
}
/// @dev Recover both signers in a separate stack frame — inlining hits stack-too-deep.
function _verifyBothIntents(
EnrollArgs memory args,
bytes calldata sigA,
bytes calldata sigB
) internal view returns (DuelSigners memory signers) {
bytes32 sep = LibDuel.buildDomainSeparator(); // C2: build the EIP-712 separator once for both signers
signers.signerA = LibDuel.verifyIntent(
uint32(args.players),
uint32(args.specs),
uint128(args.deadlines),
uint128(args.maxGasPrices),
sigA,
args.bracket,
sep
);
signers.signerB = LibDuel.verifyIntent(
uint32(args.players >> 32),
uint32(args.specs >> 32),
args.deadlines >> 128,
args.maxGasPrices >> 128,
sigB,
args.bracket,
sep
);
}
/// @dev Create the duel row and return its ID. Re-reads taruchiID — warm SLOADs
/// after verifyIntent already touched taruchi rows. enrollBlock from LibDuel.create
/// is dropped here — the caller doesn't need it; matchmaker captures from receipt.
function _createDuel(EnrollArgs memory args, bytes32 secretHash) internal returns (uint256 duelId) {
uint32 playerAIndex = uint32(args.players);
uint32 playerBIndex = uint32(args.players >> 32);
uint256 taruchiA = Taruchi.getByIndex(playerAIndex);
uint256 taruchiB = Taruchi.getByIndex(playerBIndex);
(duelId, ) = LibDuel.create(
playerAIndex,
playerBIndex,
args.bracket,
uint32(args.specs),
uint32(args.specs >> 32),
taruchiA,
taruchiB,
args.maxGasPrices,
secretHash
);
}
/// @dev Tail-end interactions: WETH gas reimbursement only. Duels are free — no ONYX entry fee.
function _settle(DuelSigners memory signers, EnrollArgs memory args, address relayer) internal {
LibWeth.pullWethForGas(
signers.signerA,
LibWeth.WETH_GAS_EST_DUEL_ENROLL_PER_USER,
uint128(args.maxGasPrices),
relayer
);
LibWeth.pullWethForGas(
signers.signerB,
LibWeth.WETH_GAS_EST_DUEL_ENROLL_PER_USER,
args.maxGasPrices >> 128,
relayer
);
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 3000,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=node_modules/forge-std/src/",
"@latticexyz/=node_modules/@latticexyz/",
"@openzeppelin/=node_modules/@openzeppelin/",
"solady/=node_modules/solady/src/",
"libraries/=src/namespaces/app/libraries/",
"tables/=src/namespaces/app/codegen/tables/",
"common/=src/codegen/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.