Проверенный контрактТочноеMIT
DuelEnrollSystem
Адрес0x0573f2d2cd4cdb1a1003795a9dcd728b7e7cf1ef
- Баланс
0 ETH
- Транзакций
0
- Компилятор
solc 0.8.24
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.24+commit.e11b9ed9
- Язык
- solidity
- Оптимизация
- Да, 3 000 прогонов
- Версия EVM
- cancun
- Через IR
- да
- Лицензия
- MIT
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 25 481 290
- Транзакция создания
- 0x72cf737594…1291d99bc0
89 файлов
Исходный код большой: показывается один файл. Выберите файл в списке.
- src/namespaces/root/DuelEnrollSystem.solглавный6,04 КБ
- node_modules/@latticexyz/schema-type/src/solidity/SchemaType.sol3,72 КБ
- node_modules/@latticexyz/store/src/Bytes.sol35,98 КБ
- node_modules/@latticexyz/store/src/EncodedLengths.sol9,33 КБ
- node_modules/@latticexyz/store/src/FieldLayout.sol8,62 КБ
- node_modules/@latticexyz/store/src/Hook.sol3,97 КБ
- node_modules/@latticexyz/store/src/IERC165.sol576 Б
- node_modules/@latticexyz/store/src/IEncodedLengthsErrors.sol737 Б
- node_modules/@latticexyz/store/src/IFieldLayoutErrors.sol2,26 КБ
- node_modules/@latticexyz/store/src/ISchemaErrors.sol834 Б
- node_modules/@latticexyz/store/src/ISliceErrors.sol894 Б
- node_modules/@latticexyz/store/src/IStore.sol321 Б
- node_modules/@latticexyz/store/src/IStoreErrors.sol4,12 КБ
- node_modules/@latticexyz/store/src/IStoreEvents.sol2,91 КБ
- node_modules/@latticexyz/store/src/IStoreHook.sol6,12 КБ
- node_modules/@latticexyz/store/src/IStoreKernel.sol988 Б
- node_modules/@latticexyz/store/src/IStoreRead.sol3,95 КБ
- node_modules/@latticexyz/store/src/IStoreRegistration.sol1,12 КБ
- node_modules/@latticexyz/store/src/IStoreWrite.sol2,36 КБ
- node_modules/@latticexyz/store/src/Memory.sol2,06 КБ
- node_modules/@latticexyz/store/src/ResourceId.sol2,21 КБ
- node_modules/@latticexyz/store/src/Schema.sol7,69 КБ
- node_modules/@latticexyz/store/src/Slice.sol4,49 КБ
- node_modules/@latticexyz/store/src/Storage.sol9,76 КБ
- node_modules/@latticexyz/store/src/StoreCore.sol54,25 КБ
- node_modules/@latticexyz/store/src/StoreSwitch.sol22,54 КБ
- node_modules/@latticexyz/store/src/codegen/index.sol320 Б
- node_modules/@latticexyz/store/src/codegen/tables/Hooks.sol15,66 КБ
- node_modules/@latticexyz/store/src/codegen/tables/ResourceIds.sol7,18 КБ
- node_modules/@latticexyz/store/src/codegen/tables/StoreHooks.sol15,06 КБ
- node_modules/@latticexyz/store/src/codegen/tables/Tables.sol26,58 КБ
- node_modules/@latticexyz/store/src/constants.sol1,73 КБ
- node_modules/@latticexyz/store/src/rightMask.sol838 Б
- node_modules/@latticexyz/store/src/storeHookTypes.sol1,78 КБ
- node_modules/@latticexyz/store/src/storeResourceTypes.sol515 Б
- node_modules/@latticexyz/store/src/tightcoder/DecodeSlice.sol46,44 КБ
- node_modules/@latticexyz/store/src/tightcoder/EncodeArray.sol46,1 КБ
- node_modules/@latticexyz/store/src/tightcoder/TightCoder.sol3,81 КБ
- node_modules/@latticexyz/store/src/version.sol348 Б
- node_modules/@latticexyz/world/src/IERC165.sol813 Б
- node_modules/@latticexyz/world/src/IWorldContextConsumer.sol1,54 КБ
- node_modules/@latticexyz/world/src/System.sol570 Б
- node_modules/@latticexyz/world/src/WorldContext.sol9,21 КБ
- node_modules/@latticexyz/world/src/revertWithBytes.sol566 Б
- node_modules/solady/src/utils/DynamicArrayLib.sol37,21 КБ
- node_modules/solady/src/utils/ECDSA.sol20,2 КБ
- node_modules/solady/src/utils/LibBytes.sol38,18 КБ
- node_modules/solady/src/utils/LibPRNG.sol22,51 КБ
- node_modules/solady/src/utils/LibString.sol44,25 КБ
- node_modules/solady/src/utils/SafeCastLib.sol23,8 КБ
- node_modules/solady/src/utils/SafeTransferLib.sol32,86 КБ
- src/codegen/common.sol527 Б
- src/namespaces/app/codegen/tables/Account.sol12,37 КБ
- src/namespaces/app/codegen/tables/AccountStatus.sol14,02 КБ
- src/namespaces/app/codegen/tables/ActiveTaruchi.sol6,3 КБ
- src/namespaces/app/codegen/tables/AuthRoles.sol6,89 КБ
- src/namespaces/app/codegen/tables/BattleResult.sol13,82 КБ
- src/namespaces/app/codegen/tables/Commit.sol6,85 КБ
- src/namespaces/app/codegen/tables/Config.sol6,52 КБ
- src/namespaces/app/codegen/tables/Data.sol7,97 КБ
- src/namespaces/app/codegen/tables/Duel.sol15,56 КБ
- src/namespaces/app/codegen/tables/DuelMetadata.sol6,38 КБ
- src/namespaces/app/codegen/tables/TaruchiCore.sol11,99 КБ
- src/namespaces/app/codegen/tables/TaruchiName.sol6,62 КБ
- src/namespaces/app/codegen/tables/TaruchiStatus.sol18,6 КБ
- src/namespaces/app/codegen/tables/TaruchiTourney.sol6,34 КБ
- src/namespaces/app/codegen/tables/Tourney.sol13,66 КБ
- src/namespaces/app/codegen/tables/TourneyMetadata.sol6,39 КБ
- src/namespaces/app/codegen/tables/TourneyResult.sol8,18 КБ
- src/namespaces/app/codegen/tables/TraitNames.sol6,62 КБ
- src/namespaces/app/codegen/tables/TraitsRegistry.sol14,86 КБ
- src/namespaces/app/libraries/BattleEngine.sol50,63 КБ
- src/namespaces/app/libraries/LibDuel.sol13,73 КБ
- src/namespaces/app/libraries/LibOnyx.sol29,47 КБ
- src/namespaces/app/libraries/LibTourney.sol21,22 КБ
- src/namespaces/app/libraries/LibWeth.sol10,93 КБ
- src/namespaces/app/libraries/Taruchi.sol18,48 КБ
- src/namespaces/app/libraries/Traits.sol14,6 КБ
- src/namespaces/app/libraries/utils/LibAffinity.sol3,97 КБ
- src/namespaces/app/libraries/utils/LibAuthRoles.sol1,06 КБ
- src/namespaces/app/libraries/utils/LibBlockHeader.sol6,45 КБ
- src/namespaces/app/libraries/utils/LibCommit.sol6,72 КБ
- src/namespaces/app/libraries/utils/LibData.sol2,49 КБ
- src/namespaces/app/libraries/utils/LibPack.sol7,13 КБ
- src/namespaces/app/libraries/utils/LibProgression.sol2,32 КБ
- src/namespaces/app/libraries/utils/LibRandom.sol6,96 КБ
- src/namespaces/app/libraries/utils/LibSpec.sol7,33 КБ
- src/namespaces/app/libraries/utils/LibStats.sol3,34 КБ
- src/namespaces/app/libraries/utils/LibXP.sol6,92 КБ
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
);
}
}
Настройки компилятораПоказать
{
"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/"
]
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.