Проверенный контрактТочноеMIT
HTLCPoseidonV2
Адрес0x4e364cc86edbf307cc6f336f3a72e1a24d284d70
- Баланс
0 ETH
- Транзакций
1
- Компилятор
solc 0.8.24
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.24+commit.e11b9ed9
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Версия EVM
- cancun
- Лицензия
- MIT
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 459 748
- Транзакция создания
- 0xe00aac4697…c0a0218748
2 файла
- contracts/HTLCPoseidonV2.solглавный9,76 КБ
- contracts/Poseidon2b.sol55,22 КБ
contracts/HTLCPoseidonV2.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Poseidon2b} from "./Poseidon2b.sol";
/**
* @title HTLCPoseidonV2
* @notice Hash-time-locked contract for native ETH whose lock is a Parano1d ADDRESS: claim
* succeeds when Poseidon2b.addr(secret) == lockAddr. Ethereum half of a NOID <-> ETH
* atomic swap in which the ETH leg is locked on A = Addr(s), the same 32 bytes that are
* the claim authority of the Parano1d lock, so no zero-knowledge equivalence proof is
* needed (docs/poseidon-leg.md). Production version of the HTLCPoseidon prototype.
*
* DIFFERENCES FROM HTLC.sol (all deliberate; everything else is line-for-line the same)
* -----------------------------------------------------------------------------------
* 1. The hashlock is lockAddr = Addr(secret) (Poseidon2b), not SHA-256(secret).
* 2. claim() checks the timelock BEFORE it pays for the permutation, so an expired claim fails
* cheaply (HTLC.sol checks the hash first; the two windows are still disjoint and exhaustive).
* 3. claim() reverts BadCalldataLength unless the calldata is exactly 68 bytes (selector, lock
* id, 32-byte secret). HTLC.sol silently ignores trailing bytes; here the secret is exactly
* 32 bytes and nothing else is accepted.
* 4. claim() reverts InsufficientGas (before any state change and before the permutation) when
* fewer than MIN_CLAIM_GAS gas are left. See COST AND GAS below.
* 5. There is NO view that computes Addr(secret). Such a function invites an eth_call with the
* live secret on a remote node, which would leak it before the counterparty has locked.
* Compute Addr locally with the reference crate (equiv-ref) and compare with this
* contract's output only on public test vectors, in a test deployment.
*
* ENCODING (the Parano1d side MUST match exactly)
* -----------------------------------------------
* - secret = exactly 32 raw bytes (a bytes32); s_lo = u128 LE of bytes 0..16, s_hi = u128 LE
* of bytes 16..32 (see Poseidon2b.sol).
* - lockAddr = the 32 address bytes, i.e. the payload of the bech32m `o1...` string, with the
* first byte as the most significant byte of the bytes32.
* - lockAddr == Addr(s), the address Parano1d prints for the raw secret s. RAW VARIANT ONLY:
* the stock wallet's address is Addr(Derive(m, 0)) and would need three more permutations
* (about 1.7 M gas per claim); not supported here.
*
* TIMELOCK RULES, LOCK ID, HAZARDS: identical to HTLC.sol.
* claim() only while block.timestamp < timelock; refund() only when block.timestamp >= timelock.
* lockId = keccak256(abi.encodePacked(sender, receiver, amount, lockAddr, timelock)).
* Funds are paid with a low-level call to the fixed receiver (an EOA in the swap tool). A
* receiver that rejects ETH makes claim() revert with the secret in its calldata; the funds stay
* until refund(). The preimage is public once used (calldata, storage, event); it pays the fixed
* receiver, so a mempool watcher gains nothing by copying it.
*
* COST AND GAS
* ------------
* One Poseidon2b permutation runs inside claim(): about 0.43 M gas, 0.50 M to 0.55 M for the whole
* transaction (measured numbers in docs/poseidon-leg.md). Send claim() with an explicit gas limit
* of at least RECOMMENDED_CLAIM_GAS_LIMIT and simulate it on your own node first. A claim that
* runs out of gas, or reverts with InsufficientGas, still published the secret in its calldata:
* the lock stays claimable, so re-send with enough gas and a sufficient fee. The InsufficientGas
* check does not prevent that disclosure; it only turns "out of gas somewhere in the middle" into
* one early, named failure and guarantees that a call that passes the check can finish an
* honest payout to an EOA.
*/
contract HTLCPoseidonV2 {
struct Lock {
address sender;
address receiver;
uint256 amount;
bytes32 lockAddr;
uint256 timelock;
bool claimed;
bool refunded;
bytes32 preimage; // zero until claimed
}
/// Gas that must be left when claim() reaches the permutation (checked after the cheap
/// validations). The work after the check needs at most about 510,000 (permutation, both storage
/// writes, the event, and the payout to a receiver account that does not exist yet, measured on
/// Cancun gas rules, test/HTLCPoseidonV2.test.js); the rest is margin for a gas repricing.
/// Re-measure after any fork that changes storage or account-creation costs.
uint256 public constant MIN_CLAIM_GAS = 540_000;
/// What a caller should put in the transaction's gas limit: MIN_CLAIM_GAS plus the intrinsic cost,
/// the calldata, the cold reads of the lock and the reentrancy flag (about 34,000), plus a margin.
uint256 public constant RECOMMENDED_CLAIM_GAS_LIMIT = 650_000;
mapping(bytes32 => Lock) private _locks;
event Locked(
bytes32 indexed lockId,
address indexed sender,
address indexed receiver,
uint256 amount,
bytes32 lockAddr,
uint256 timelock
);
event Claimed(bytes32 indexed lockId, bytes32 preimage);
event Refunded(bytes32 indexed lockId);
error ZeroAmount();
error ZeroReceiver();
error TimelockNotInFuture();
error LockAlreadyExists();
error LockNotFound();
error InvalidPreimage();
error TimelockExpired();
error TimelockNotExpired();
error AlreadyClaimed();
error AlreadyRefunded();
error NotSender();
error TransferFailed();
error Reentrancy();
error BadCalldataLength();
error InsufficientGas();
uint256 private _status = 1; // 1 = not entered, 2 = entered
modifier nonReentrant() {
if (_status == 2) revert Reentrancy();
_status = 2;
_;
_status = 1;
}
/// @notice Compute the id a lock with these parameters will have.
function computeLockId(
address sender,
address receiver,
uint256 amount,
bytes32 lockAddr,
uint256 timelock
) public pure returns (bytes32) {
return keccak256(abi.encodePacked(sender, receiver, amount, lockAddr, timelock));
}
/**
* @notice Lock msg.value for `receiver` under `lockAddr` until `timelock`.
* @param lockAddr Parano1d address Addr(s) of the 32-byte secret (see contract docs).
* @param timelock Absolute Unix timestamp; must be strictly in the future.
* @param receiver Fixed payee on claim.
* @return lockId Identifier of the new lock.
*/
function newLock(
bytes32 lockAddr,
uint256 timelock,
address payable receiver
) external payable nonReentrant returns (bytes32 lockId) {
if (msg.value == 0) revert ZeroAmount();
if (receiver == address(0)) revert ZeroReceiver();
if (timelock <= block.timestamp) revert TimelockNotInFuture();
lockId = computeLockId(msg.sender, receiver, msg.value, lockAddr, timelock);
if (_locks[lockId].sender != address(0)) revert LockAlreadyExists();
_locks[lockId] = Lock({
sender: msg.sender,
receiver: receiver,
amount: msg.value,
lockAddr: lockAddr,
timelock: timelock,
claimed: false,
refunded: false,
preimage: bytes32(0)
});
emit Locked(lockId, msg.sender, receiver, msg.value, lockAddr, timelock);
}
/**
* @notice Reveal the secret and pay the receiver. Callable by anyone; funds always go to the
* lock's fixed receiver. Costs one Poseidon2b permutation of gas: send it with a gas
* limit of at least RECOMMENDED_CLAIM_GAS_LIMIT.
*/
function claim(bytes32 lockId, bytes32 preimage) external nonReentrant {
// selector (4) + lockId (32) + preimage (32): the secret is exactly 32 bytes, no tail
if (msg.data.length != 68) revert BadCalldataLength();
Lock storage l = _locks[lockId];
if (l.sender == address(0)) revert LockNotFound();
if (l.claimed) revert AlreadyClaimed();
if (l.refunded) revert AlreadyRefunded();
if (block.timestamp >= l.timelock) revert TimelockExpired();
if (gasleft() < MIN_CLAIM_GAS) revert InsufficientGas();
if (Poseidon2b.addr(preimage) != l.lockAddr) revert InvalidPreimage();
// effects
l.claimed = true;
l.preimage = preimage;
uint256 amount = l.amount;
address receiver = l.receiver;
emit Claimed(lockId, preimage);
// interaction
(bool ok, ) = payable(receiver).call{value: amount}("");
if (!ok) revert TransferFailed();
}
/// @notice Return the funds to the sender after the timelock, if unclaimed.
function refund(bytes32 lockId) external nonReentrant {
Lock storage l = _locks[lockId];
if (l.sender == address(0)) revert LockNotFound();
if (msg.sender != l.sender) revert NotSender();
if (l.claimed) revert AlreadyClaimed();
if (l.refunded) revert AlreadyRefunded();
if (block.timestamp < l.timelock) revert TimelockNotExpired();
// effects
l.refunded = true;
uint256 amount = l.amount;
emit Refunded(lockId);
// interaction
(bool ok, ) = payable(l.sender).call{value: amount}("");
if (!ok) revert TransferFailed();
}
/// @notice Full lock record. Reverts if the lock does not exist.
function getLock(bytes32 lockId) external view returns (Lock memory) {
Lock memory l = _locks[lockId];
if (l.sender == address(0)) revert LockNotFound();
return l;
}
}
contracts/Poseidon2b.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* @title Poseidon2b
* @notice Parano1d's address function Addr(s) on the EVM: one Poseidon2b permutation over
* GF(2^128) (t = 4, x^7 S-box, 8 full + 58 partial rounds) with the ADDRFIX_ IV,
* output lanes 0 and 1.
*
* THIS FILE IS GENERATED by eth/scripts/poseidon/gen.js from the zero-dependency Rust
* spec in equiv/portable/src/{lib.rs,constants.rs,basis_tables.rs}: the round constants,
* MDS factors, IV, tag, pad and basis tables below were converted mechanically, not typed.
* Do not edit by hand: regenerate with "npm run poseidon:gen" (in eth/); the test suite and
* "npm run poseidon:check" fail unless a fresh generation is byte-identical to this file.
*
* The permutation runs in the flat (GCM polynomial) basis exactly like the
* Rust: the input lanes are converted tower -> flat, all 66 rounds run flat, the two
* output lanes are converted flat -> tower.
*
* Field: GF(2)[x] / (x^128 + x^7 + x^2 + x + 1), bit i = coefficient of x^i.
* gmul carry-less multiply done with masked integer MULs: each operand is split into
* five parts by bit position mod 5; an integer product of two parts holds, at the
* positions of one residue class, column sums of at most 26 terms, which fit in
* the 4 bits between two positions of the class, so bit p of the product is the
* GF(2) product bit. 5 x 5 = 25 MULs, five masks, then one reduction.
* gsqr squaring is GF(2)-linear: spread bit i to 2i, then reduce.
* sbox x^7 = (x * x^2) * x^4, as in the Rust.
* Linear layers (constants in tower basis -> flat): MDS_FULL = [[5,7,1,3],[4,6,1,1],
* [1,3,5,7],[1,1,4,6]] is evaluated with 4 multiplications using 5 = 1+4, 7 = 1+2+4,
* 3 = 1+2, 6 = 2+4 and distributivity (T1 = flat(2), T2 = flat(4)); MDS_PARTIAL =
* diag(0x20,0x2000,0x200,0x800) + ones, so out_i = (d_i + 1) * in_i + sum(in).
*
* Byte order (docs/parano1d-capabilities.md section 10): s_lo = u128 LE of s[0..16],
* s_hi = u128 LE of s[16..32]; the address is lane0 LE || lane1 LE. In a bytes32 the
* first byte is the most significant one, hence the byte swaps.
*
* Security note: with this lock the EVM leg's security is Addr's preimage resistance
* (Poseidon2b with unusually small round constants, open question Q8 in the design).
*/
library Poseidon2b {
/// @dev "ADDRFIX_" as a big-endian u64, as in the vendor domain tag.
uint64 internal constant ADDRFIX_LABEL = 0x414444524649585F;
/// @dev capacity IV [L << 64, L] already converted to the flat basis:
/// IV_HI_FLAT = TOWER_TO_FLAT(ADDRFIX_LABEL << 64), IV_LO_FLAT = TOWER_TO_FLAT(ADDRFIX_LABEL).
uint256 internal constant IV_HI_FLAT = 0xbfd9ad5c89d2f843a9b0600c045d8f01;
uint256 internal constant IV_LO_FLAT = 0x49f014177eae5f1e4df2a9c1a264fca2;
/// @notice Addr(s) for a raw 32-byte secret (the RAW swap variant).
function addr(bytes32 s) internal pure returns (bytes32 a) {
(uint256 lo, uint256 hi) = _limbs(uint256(s));
(uint256 l0, uint256 l1, , ) = _permute(_towerToFlat(lo), _towerToFlat(hi), IV_HI_FLAT, IV_LO_FLAT);
a = bytes32(_unlimbs(_flatToTower(l0), _flatToTower(l1)));
}
/// @notice Derive(m, index): spend secret `index` of the stock-wallet master secret `m`
/// (3 permutations: absorb m; absorb index || "noid-deri"; absorb the pad block).
function derive(bytes32 m, uint32 index) internal pure returns (bytes32 d) {
(uint256 l0, uint256 l1) = _deriveFlat(uint256(m), index);
d = bytes32(_unlimbs(_flatToTower(l0), _flatToTower(l1)));
}
/// @notice Addr(Derive(m, 0)): the STOCK variant authority, 4 permutations, no
/// intermediate basis conversion.
function addrStock(bytes32 m) internal pure returns (bytes32 a) {
(uint256 l0, uint256 l1) = _deriveFlat(uint256(m), 0);
(l0, l1, , ) = _permute(l0, l1, IV_HI_FLAT, IV_LO_FLAT);
a = bytes32(_unlimbs(_flatToTower(l0), _flatToTower(l1)));
}
/// @notice The bare permutation on a tower-basis state (vendor permute_mut), for tests.
function permute(uint256[4] memory st) internal pure returns (uint256[4] memory out) {
(uint256 a, uint256 b, uint256 c, uint256 d) =
_permute(_towerToFlat(st[0]), _towerToFlat(st[1]), _towerToFlat(st[2]), _towerToFlat(st[3]));
out[0] = _flatToTower(a);
out[1] = _flatToTower(b);
out[2] = _flatToTower(c);
out[3] = _flatToTower(d);
}
// ------------------------------------------------------------------ sponge helpers
/// @dev Flat-basis lanes 0 and 1 after the third permutation of Derive(m, index).
function _deriveFlat(uint256 m, uint32 index) private pure returns (uint256 l0, uint256 l1) {
(uint256 lo, uint256 hi) = _limbs(m);
uint256 l2;
uint256 l3;
(l0, l1, l2, l3) = _permute(_towerToFlat(lo), _towerToFlat(hi), 0, 0);
// absorb index (lane 0) and "noid-deri" (lane 1); XOR commutes with the linear basis map
(l0, l1, l2, l3) = _permute(l0 ^ _towerToFlat(uint256(index)), l1 ^ 0x0026da0bf7e5784314d8e7602a362847, l2, l3);
// pad block: byte 0 = 0x80 (lane 0, bit 7), byte 31 = 0x01 (lane 1, bit 120)
(l0, l1, , ) = _permute(l0 ^ 0x549810e11a88dea5252b49277b1b82b4, l1 ^ 0x2d4278deab8e9cdeb21b66e82f85dea7, l2, l3);
}
/// @dev (u128 LE of bytes 0..16, u128 LE of bytes 16..32) of a bytes32 word.
function _limbs(uint256 w) private pure returns (uint256 lo, uint256 hi) {
lo = _bswap128(w >> 128);
hi = _bswap128(w & 0xffffffffffffffffffffffffffffffff);
}
/// @dev Inverse of _limbs.
function _unlimbs(uint256 lo, uint256 hi) private pure returns (uint256 w) {
w = (_bswap128(lo) << 128) | _bswap128(hi);
}
/// @dev Reverse the 16 bytes of a value < 2^128.
function _bswap128(uint256 v) private pure returns (uint256 r) {
assembly {
v := or(shr(8, and(v, 0xff00ff00ff00ff00ff00ff00ff00ff00)), shl(8, and(v, 0x00ff00ff00ff00ff00ff00ff00ff00ff)))
v := or(shr(16, and(v, 0xffff0000ffff0000ffff0000ffff0000)), shl(16, and(v, 0x0000ffff0000ffff0000ffff0000ffff)))
v := or(shr(32, and(v, 0xffffffff00000000ffffffff00000000)), shl(32, and(v, 0x00000000ffffffff00000000ffffffff)))
r := or(shr(64, v), and(shl(64, v), 0xffffffffffffffffffffffffffffffff))
}
}
// ------------------------------------------------------------------ basis change
/// @dev Tower -> flat: XOR of TOWER_TO_FLAT[i] over the set bits i of v (vendor apply_matrix).
function _towerToFlat(uint256 inp) internal pure returns (uint256 out) {
assembly {
function t2f(v) -> r {
// equiv/portable/src/basis_tables.rs TOWER_TO_FLAT
r := mul(and(v, 1), 0x00000000000000000000000000000001)
r := xor(r, mul(and(shr(1, v), 1), 0x3d5bd35c94646a247573da4a5f7710ed))
r := xor(r, mul(and(shr(2, v), 1), 0xa72ec17764d7ced55e2f716f4ede412f))
r := xor(r, mul(and(shr(3, v), 1), 0x553e92e8bc0ae9a795ed1f57f3632d4d))
r := xor(r, mul(and(shr(4, v), 1), 0xc7bd33d0a58cf5b4740d6c968b842acb))
r := xor(r, mul(and(shr(5, v), 1), 0x486fb01f93aa169afd8ee716e990cf14))
r := xor(r, mul(and(shr(6, v), 1), 0xbee4e4dc44629cf627b537f28935c282))
r := xor(r, mul(and(shr(7, v), 1), 0x549810e11a88dea5252b49277b1b82b4))
r := xor(r, mul(and(shr(8, v), 1), 0x6198d3a7b756c056bd3d5a025c8d370a))
r := xor(r, mul(and(shr(9, v), 1), 0xb2ef6c31981e31582924ed9040490830))
r := xor(r, mul(and(shr(10, v), 1), 0x09ee93d00b6b040353ebf5c8e0d4401d))
r := xor(r, mul(and(shr(11, v), 1), 0xff829109128b0bd884cb11891ab51a3c))
r := xor(r, mul(and(shr(12, v), 1), 0x25ce422cd636209fd58e3eee6bcdb7d7))
r := xor(r, mul(and(shr(13, v), 1), 0x86b6a57216f083193e1b361e8a1a5bbf))
r := xor(r, mul(and(shr(14, v), 1), 0x38e5c77d01ea3f466707ab5ea8ff4171))
r := xor(r, mul(and(shr(15, v), 1), 0x2de7ef9721e4b0550d4fe61188fb1bd3))
r := xor(r, mul(and(shr(16, v), 1), 0x5c4feb37d9ad179b297b823812957b8c))
r := xor(r, mul(and(shr(17, v), 1), 0x8e36a06b2ac838db09f04ada993caa84))
r := xor(r, mul(and(shr(18, v), 1), 0xc6082bd8edaaae4873fb728376565fff))
r := xor(r, mul(and(shr(19, v), 1), 0x9b92a729351ab577a2b0de27d713817a))
r := xor(r, mul(and(shr(20, v), 1), 0xb7106c3879c5c033015afe43a7bbb48f))
r := xor(r, mul(and(shr(21, v), 1), 0xe638c5d1336cc967dd424e375f37904f))
r := xor(r, mul(and(shr(22, v), 1), 0xef30fbf0630e9d04f9efc7d242801381))
r := xor(r, mul(and(shr(23, v), 1), 0x0548ecca55b43556101c39dffff23087))
r := xor(r, mul(and(shr(24, v), 1), 0xa3dc4d913d605620dae083b969cba697))
r := xor(r, mul(and(shr(25, v), 1), 0x60c413bae203bcfee863fce3d62d7a46))
r := xor(r, mul(and(shr(26, v), 1), 0xe3f02a180f232bd7f9e6c41f2ad92bb1))
r := xor(r, mul(and(shr(27, v), 1), 0x4983d83fd28ea811148387423931f5c8))
r := xor(r, mul(and(shr(28, v), 1), 0x449a77f55b99ac57dcb2131788da3392))
r := xor(r, mul(and(shr(29, v), 1), 0x611ba189d789d45401af9d0333b3f9e7))
r := xor(r, mul(and(shr(30, v), 1), 0xb67819253374dc0ae0ec21b8ad160234))
r := xor(r, mul(and(shr(31, v), 1), 0xf23ff08f2566732b188cdc592a0eb8f7))
r := xor(r, mul(and(shr(32, v), 1), 0x0c9ac57d3e240265a401dc6270f59c10))
r := xor(r, mul(and(shr(33, v), 1), 0x3493b22a21cc4c396552505d8c638d9b))
r := xor(r, mul(and(shr(34, v), 1), 0x757fa4336d785da4447251e433ed42fb))
r := xor(r, mul(and(shr(35, v), 1), 0x6d2979d4d4a745250ea377dabd44cfb2))
r := xor(r, mul(and(shr(36, v), 1), 0x55583ad2a44322ab8ca02871898d1f81))
r := xor(r, mul(and(shr(37, v), 1), 0x86373be6909783ffc8bb21b3dda24f12))
r := xor(r, mul(and(shr(38, v), 1), 0x0c3f3f28407ec57a4a53af471e53285c))
r := xor(r, mul(and(shr(39, v), 1), 0x972c409ddb7f2db55ee11ac6a242e45c))
r := xor(r, mul(and(shr(40, v), 1), 0x96f938744906740774c33c247ccf85d8))
r := xor(r, mul(and(shr(41, v), 1), 0x4cae10232a3558fa26fbc92fab97488b))
r := xor(r, mul(and(shr(42, v), 1), 0x8bb0008776ffc7e44db0cc1a2df288b9))
r := xor(r, mul(and(shr(43, v), 1), 0x1d0703e4ee2237c7ab53e5b75d921bd7))
r := xor(r, mul(and(shr(44, v), 1), 0xff012dbc34f0271cce6d0c1b0d125e3a))
r := xor(r, mul(and(shr(45, v), 1), 0x9aea02703d99a98cb9e1b3a368dce85b))
r := xor(r, mul(and(shr(46, v), 1), 0xb39755229db1f4de29498e7a13e7cdc2))
r := xor(r, mul(and(shr(47, v), 1), 0xc31176b1b646603fc50a528e49742a0e))
r := xor(r, mul(and(shr(48, v), 1), 0xead0dc2950f39b1eb2c2edb9407de10d))
r := xor(r, mul(and(shr(49, v), 1), 0xea3f3fe33d1d2b7d3cf38b78900dab86))
r := xor(r, mul(and(shr(50, v), 1), 0x051bd919a56eb92348316675811dc923))
r := xor(r, mul(and(shr(51, v), 1), 0xba5ae9f94b493aa478e08aa4f415cb18))
r := xor(r, mul(and(shr(52, v), 1), 0x141e17265a74f46bb369c916cbaf8a25))
r := xor(r, mul(and(shr(53, v), 1), 0x6c99c4af650a8451a195d75a7769413b))
r := xor(r, mul(and(shr(54, v), 1), 0x342484168e3692419b8ea7e8fdcc8f8d))
r := xor(r, mul(and(shr(55, v), 1), 0xaa7a29ea7ae49742f8aa7027b065617d))
r := xor(r, mul(and(shr(56, v), 1), 0xd345f319cf8d0c5711c92a1a19cf232c))
r := xor(r, mul(and(shr(57, v), 1), 0xbf7956da104bb930529470fbcfa3f60e))
r := xor(r, mul(and(shr(58, v), 1), 0xaf3c8a62ae50f00d8dd54ec40c51d402))
r := xor(r, mul(and(shr(59, v), 1), 0x9f40c849b5f5405f91589271eefd831e))
r := xor(r, mul(and(shr(60, v), 1), 0x82131c9fe93d42fe3eac43b40fe78613))
r := xor(r, mul(and(shr(61, v), 1), 0xee5d797779ee1b27b76d3ed1cee66add))
r := xor(r, mul(and(shr(62, v), 1), 0xb7438c8a8d29a42710da3eeb0dcaa4f4))
r := xor(r, mul(and(shr(63, v), 1), 0x0884f37a7a1f9068c7b8dbfb652cfb52))
r := xor(r, mul(and(shr(64, v), 1), 0x9b027a35e430ddaa521ef0fd91f39162))
r := xor(r, mul(and(shr(65, v), 1), 0xb619b3c28e9fd05efbcd5ead6935a75c))
r := xor(r, mul(and(shr(66, v), 1), 0x0cad054f32f966043874b2e8163127c7))
r := xor(r, mul(and(shr(67, v), 1), 0x8ec4fff59680eaae0077f3dd83fbd947))
r := xor(r, mul(and(shr(68, v), 1), 0x50d8597763331f8dcea34c16608a96a7))
r := xor(r, mul(and(shr(69, v), 1), 0x6d03608d9f2a6e86dd0d62d96a32751d))
r := xor(r, mul(and(shr(70, v), 1), 0x49110668fefb446975dea1bb5742ad75))
r := xor(r, mul(and(shr(71, v), 1), 0xde3c54e5dc0bf89137cf5d286ba5868a))
r := xor(r, mul(and(shr(72, v), 1), 0x61121e79a40f65000fb426800e5b4f0b))
r := xor(r, mul(and(shr(73, v), 1), 0x0996944c65744223a5ef06f1eda08fd6))
r := xor(r, mul(and(shr(74, v), 1), 0xda3cbe76b9f383e1cde547094cf05431))
r := xor(r, mul(and(shr(75, v), 1), 0xa3a2b75fb155f13733c11156ff19d609))
r := xor(r, mul(and(shr(76, v), 1), 0xfb4449056e5c6fb2d9a33f42f0a893ad))
r := xor(r, mul(and(shr(77, v), 1), 0x0128f41399db28643d0743873dc1264a))
r := xor(r, mul(and(shr(78, v), 1), 0xff09c9c044dd9342be235156d0bf9197))
r := xor(r, mul(and(shr(79, v), 1), 0xcbb652c3d0896219d921f2c49b28d8e7))
r := xor(r, mul(and(shr(80, v), 1), 0x61102a46cc01cdf697b666aa7d3d8d45))
r := xor(r, mul(and(shr(81, v), 1), 0x717c5e9d4a0731b69d1e33a8f128eedd))
r := xor(r, mul(and(shr(82, v), 1), 0xd3498c6de1db846fb5b84c3d08a26402))
r := xor(r, mul(and(shr(83, v), 1), 0x1d074123e95f221742bb042dd2decd90))
r := xor(r, mul(and(shr(84, v), 1), 0x49dd214c370bbb55e8a3a82b147053be))
r := xor(r, mul(and(shr(85, v), 1), 0x18af31dbbab9458eb16b27c0fd1c309f))
r := xor(r, mul(and(shr(86, v), 1), 0x61e2d820490e7be32289961803263c34))
r := xor(r, mul(and(shr(87, v), 1), 0x107fa373d60153306bcebc6f2ea6aac5))
r := xor(r, mul(and(shr(88, v), 1), 0x3df814508cd896e7813397e8a778f8cd))
r := xor(r, mul(and(shr(89, v), 1), 0x4021c8146d9e0d33e353d0c73604d58e))
r := xor(r, mul(and(shr(90, v), 1), 0xee2c21eb408160983c5ccee03d280f85))
r := xor(r, mul(and(shr(91, v), 1), 0xe77f3ff735b6b82a28ab2ed8e3fc8320))
r := xor(r, mul(and(shr(92, v), 1), 0x8eee1c68d1cbc4b55eefff30ae3f6028))
r := xor(r, mul(and(shr(93, v), 1), 0xfabf471e3d132661b55c0f419db06696))
r := xor(r, mul(and(shr(94, v), 1), 0x69a006d6b32d6e23d48dde5999c10f7d))
r := xor(r, mul(and(shr(95, v), 1), 0x389f96875b52a0cdaf55c6a03819c6f1))
r := xor(r, mul(and(shr(96, v), 1), 0xd349d8dacbf6f4a04625d7953d3190bd))
r := xor(r, mul(and(shr(97, v), 1), 0xbe8502448366699e39f5117acfd01714))
r := xor(r, mul(and(shr(98, v), 1), 0xa3839a34242c75f7ffc21bd9c630459b))
r := xor(r, mul(and(shr(99, v), 1), 0xb3c2ef7bbf449f8af05d8a9a760e9407))
r := xor(r, mul(and(shr(100, v), 1), 0x694d27a4f1ba1074a7c2e5445f874b2d))
r := xor(r, mul(and(shr(101, v), 1), 0x0855c18884723bdcb6dff2cf4849ec19))
r := xor(r, mul(and(shr(102, v), 1), 0x58d911a330ce147d06afb9ccb802b7db))
r := xor(r, mul(and(shr(103, v), 1), 0xde87764a4427a4aff5db695eda550c2a))
r := xor(r, mul(and(shr(104, v), 1), 0xbfa47075ed035846f2016301eb7e4009))
r := xor(r, mul(and(shr(105, v), 1), 0xd7335e553652ccbc3f0ff542099a9636))
r := xor(r, mul(and(shr(106, v), 1), 0x00ede815347e14cec1440aa1c612391b))
r := xor(r, mul(and(shr(107, v), 1), 0x96e7e4d4efb40213aa73764edddd4ff6))
r := xor(r, mul(and(shr(108, v), 1), 0x399c2dd474a47a3f36d286b7e1d3b32b))
r := xor(r, mul(and(shr(109, v), 1), 0xcaaeb9876b882f04dc62c5f814d4f79c))
r := xor(r, mul(and(shr(110, v), 1), 0x5c7127c96b5c4300fe9954f7999e2f5a))
r := xor(r, mul(and(shr(111, v), 1), 0xfe1178bc295c981e59278e0135930986))
r := xor(r, mul(and(shr(112, v), 1), 0xe3a9112535f5f53b6a9acc3e49877fd2))
r := xor(r, mul(and(shr(113, v), 1), 0x3d6051a6cf2bb75e59ff8f7991cf6bad))
r := xor(r, mul(and(shr(114, v), 1), 0x30d97c016d51144b717181ec5f826ba3))
r := xor(r, mul(and(shr(115, v), 1), 0xe3b2c049622bdaa3e7e81e99b46920ee))
r := xor(r, mul(and(shr(116, v), 1), 0x547744dda2f0145457aacf948f0aca14))
r := xor(r, mul(and(shr(117, v), 1), 0x822e4b280fbbaf701b00d1cf2675dacf))
r := xor(r, mul(and(shr(118, v), 1), 0x013dae85beaa0a8bb735a39898b93504))
r := xor(r, mul(and(shr(119, v), 1), 0xaeed75387d73a822299a17f008c4cd8c))
r := xor(r, mul(and(shr(120, v), 1), 0x2d4278deab8e9cdeb21b66e82f85dea7))
r := xor(r, mul(and(shr(121, v), 1), 0x05745efd4f8b0dc873484e5f3c83ed61))
r := xor(r, mul(and(shr(122, v), 1), 0x456a83da121c2fc61b55c9bd216a36cd))
r := xor(r, mul(and(shr(123, v), 1), 0x6ccd4a5d0819113889547d0e69bac59b))
r := xor(r, mul(and(shr(124, v), 1), 0xbec7bd6ab8e7169c06c93f34451b5abe))
r := xor(r, mul(and(shr(125, v), 1), 0xb9e80fcc7ca8fe72faafc4143960829a))
r := xor(r, mul(and(shr(126, v), 1), 0xbbfefb3dd63f00f3f8407e5f20d87c6a))
r := xor(r, mul(and(shr(127, v), 1), 0x91b376701a386e5aee6fdbd0738b4c99))
}
out := t2f(inp)
}
}
/// @dev Flat -> tower.
function _flatToTower(uint256 inp) internal pure returns (uint256 out) {
assembly {
function f2t(v) -> r {
// equiv/portable/src/basis_tables.rs FLAT_TO_TOWER
r := mul(and(v, 1), 0x00000000000000000000000000000001)
r := xor(r, mul(and(shr(1, v), 1), 0xe9453afbbb5efa683426e20fcdbc3b96))
r := xor(r, mul(and(shr(2, v), 1), 0x1c17484568577f0b04c63c03208aeb8a))
r := xor(r, mul(and(shr(3, v), 1), 0x04adf5cfe6486e00ca9f6f0b3f58b122))
r := xor(r, mul(and(shr(4, v), 1), 0x4bad34793b579f5c90920a4453c26f86))
r := xor(r, mul(and(shr(5, v), 1), 0xfc24da72abcee7f5f01fbedeb26a8df9))
r := xor(r, mul(and(shr(6, v), 1), 0x1091dcf0350c7dc7c2e119ec5af1fc07))
r := xor(r, mul(and(shr(7, v), 1), 0x472c8b0c136435be967e8ef8074dced9))
r := xor(r, mul(and(shr(8, v), 1), 0xee63773a41b8bbd26fcb07ebd4630981))
r := xor(r, mul(and(shr(9, v), 1), 0x02fc50cfe61e714bbe42ae0de5fd0d8d))
r := xor(r, mul(and(shr(10, v), 1), 0x168a685e2f21945aa9736c6bb7c2895c))
r := xor(r, mul(and(shr(11, v), 1), 0x0dbec3dae32169816645d4935276b15d))
r := xor(r, mul(and(shr(12, v), 1), 0x1bcdfffc8342ca4dc8bfedc18a3078d9))
r := xor(r, mul(and(shr(13, v), 1), 0x1e81239207e6ef6e793f115bf0d1ddc0))
r := xor(r, mul(and(shr(14, v), 1), 0xbe1603d9dcb9eef74e5b36e05726ffaf))
r := xor(r, mul(and(shr(15, v), 1), 0xe1b26ab22e51d6585535ccbca9496a06))
r := xor(r, mul(and(shr(16, v), 1), 0x09f9e05a29dd55fa844808cc9a48d50c))
r := xor(r, mul(and(shr(17, v), 1), 0x021aaba3a74e307cc2ded8391e34e8e9))
r := xor(r, mul(and(shr(18, v), 1), 0x04966d3e1afc209d7f157b26e887a38a))
r := xor(r, mul(and(shr(19, v), 1), 0xaf7446de9259fba17a5602c30e34c669))
r := xor(r, mul(and(shr(20, v), 1), 0x0f25b0fd6d577f77f9d1882fb0bc5ba0))
r := xor(r, mul(and(shr(21, v), 1), 0x1d459f2a48cefb1c3cd4e7a6ec5dfa4b))
r := xor(r, mul(and(shr(22, v), 1), 0x5177981cdf5b750cc65ad9ea7ca055a4))
r := xor(r, mul(and(shr(23, v), 1), 0x51f9fbcea7da4578c92da6c12526013e))
r := xor(r, mul(and(shr(24, v), 1), 0x5e5568bae10fd0bea4055c77b9a844c3))
r := xor(r, mul(and(shr(25, v), 1), 0xe421662a1e1eec508af632be1f0e02a4))
r := xor(r, mul(and(shr(26, v), 1), 0x4fb8a006db40f3160af93b49a86074d9))
r := xor(r, mul(and(shr(27, v), 1), 0x45ae448d6e7f1d9eb69a344d34af8f84))
r := xor(r, mul(and(shr(28, v), 1), 0xb9c51ce3b12188ad65e7759b1f401559))
r := xor(r, mul(and(shr(29, v), 1), 0xabbb0931ab3235c58087e2dbc96ad33f))
r := xor(r, mul(and(shr(30, v), 1), 0x5c9cf000628598d60736ed8ccf038e67))
r := xor(r, mul(and(shr(31, v), 1), 0xb600769f47150f0b5cfaad9450463bed))
r := xor(r, mul(and(shr(32, v), 1), 0x41ff7793986a07fac4a9907ae8a743c2))
r := xor(r, mul(and(shr(33, v), 1), 0x09285f4c18937b3185fabe5973520296))
r := xor(r, mul(and(shr(34, v), 1), 0x04df8dc9851d9e1c3e7a14efcbfb2f95))
r := xor(r, mul(and(shr(35, v), 1), 0xf84536296d274eacfca1c8ec05ff86f2))
r := xor(r, mul(and(shr(36, v), 1), 0x10a307e4b186622325d30a95cecef780))
r := xor(r, mul(and(shr(37, v), 1), 0xb707ef2d98cf44184ddac671e2eb5fe3))
r := xor(r, mul(and(shr(38, v), 1), 0xa36bd753c6ba59d052163d58f1bed352))
r := xor(r, mul(and(shr(39, v), 1), 0xbb51e68d389f63b3fe34ed01757689b0))
r := xor(r, mul(and(shr(40, v), 1), 0x553399b0b5fc844caf168701fe5943e2))
r := xor(r, mul(and(shr(41, v), 1), 0x149dde950e34d85250b4a4567313dbce))
r := xor(r, mul(and(shr(42, v), 1), 0x4a3936263f0c100aa4c65c24c9f26072))
r := xor(r, mul(and(shr(43, v), 1), 0x4104e328f53e6a7de372c31b4ad5ad83))
r := xor(r, mul(and(shr(44, v), 1), 0xb1183d7d5bd62290a0a89715d0f4c888))
r := xor(r, mul(and(shr(45, v), 1), 0x4d660de92cacf0dd908421c7e6d1808d))
r := xor(r, mul(and(shr(46, v), 1), 0xb1d657600dafa9208939ab4849c39960))
r := xor(r, mul(and(shr(47, v), 1), 0x03a20e7aba728cd09b64d73cf2f674f4))
r := xor(r, mul(and(shr(48, v), 1), 0xe43e9984cf41aa0882197d2781f8b96f))
r := xor(r, mul(and(shr(49, v), 1), 0xbad1c62b0bff422854213e279a1c233d))
r := xor(r, mul(and(shr(50, v), 1), 0x4d0e6bd946302e439aac65df948a1cfe))
r := xor(r, mul(and(shr(51, v), 1), 0xffd379747924682586a493942c8bd1df))
r := xor(r, mul(and(shr(52, v), 1), 0xfe5f1194837be346fdb10eba477ab638))
r := xor(r, mul(and(shr(53, v), 1), 0x5295b8af5c0ddbed902930dfa570304d))
r := xor(r, mul(and(shr(54, v), 1), 0xba080add877d62a18cd4628ef7af6b4c))
r := xor(r, mul(and(shr(55, v), 1), 0x1e25371b9377b58089920b6a510400d3))
r := xor(r, mul(and(shr(56, v), 1), 0xac7c0e8e02a2200be87117633cbdd070))
r := xor(r, mul(and(shr(57, v), 1), 0xf366765716b499d4b7321e9df5959b66))
r := xor(r, mul(and(shr(58, v), 1), 0xb339b133a83acbbe7e547facbe195298))
r := xor(r, mul(and(shr(59, v), 1), 0x1475d3694c484e493e02607bf9356c65))
r := xor(r, mul(and(shr(60, v), 1), 0xe0cef1d5986e8d2d605e21f64226e065))
r := xor(r, mul(and(shr(61, v), 1), 0xa558f89882728f0ad97427c3f9a5f8e4))
r := xor(r, mul(and(shr(62, v), 1), 0xf912accaae2365e62b05093b2bf33d56))
r := xor(r, mul(and(shr(63, v), 1), 0xe131db01ea71d934b2eb168465351fa8))
r := xor(r, mul(and(shr(64, v), 1), 0xaa8f05ca85112b1e8297c34477ceeb64))
r := xor(r, mul(and(shr(65, v), 1), 0x0dc63231f0469178d0d4de381700cb51))
r := xor(r, mul(and(shr(66, v), 1), 0x41d4d8767a16e1d2bf0a593c25f52b86))
r := xor(r, mul(and(shr(67, v), 1), 0xad26c0aee1dd7aedd2b22cef38dd64e7))
r := xor(r, mul(and(shr(68, v), 1), 0x10491ee2eca4e054f64c3d01df6061f8))
r := xor(r, mul(and(shr(69, v), 1), 0xfaaf99c9d558bdd129634f9bc0b49d13))
r := xor(r, mul(and(shr(70, v), 1), 0x067a7a8aa629a19a5713b939774af76e))
r := xor(r, mul(and(shr(71, v), 1), 0x1c447ad4acaa6cf468c10599af589e85))
r := xor(r, mul(and(shr(72, v), 1), 0x1bbe72b8a35a9c3f87a1f1858fe5aa7a))
r := xor(r, mul(and(shr(73, v), 1), 0x08d64d109f41fd0101dc11cce5fa73a6))
r := xor(r, mul(and(shr(74, v), 1), 0xf827b63c8f571568d3cf4c1ee4ecd03e))
r := xor(r, mul(and(shr(75, v), 1), 0x5bb2d722803b61c1b08d89d05152ee9b))
r := xor(r, mul(and(shr(76, v), 1), 0xf3cb7ef7f453aef94c19b7fce8aa0805))
r := xor(r, mul(and(shr(77, v), 1), 0x450d1ab8d3157a5bb23d60c579d34dc9))
r := xor(r, mul(and(shr(78, v), 1), 0xa86d9af6cb03acbd901235280394a449))
r := xor(r, mul(and(shr(79, v), 1), 0xe97768fce8cdf250bfa8bb1d0878b3e4))
r := xor(r, mul(and(shr(80, v), 1), 0xa1951a61df54b357cfcf4ae3ebc3ccfd))
r := xor(r, mul(and(shr(81, v), 1), 0xb76dfde0d95a8d217f54a72f0eddffaf))
r := xor(r, mul(and(shr(82, v), 1), 0x0babb93003d8bec9bb5efd043338801f))
r := xor(r, mul(and(shr(83, v), 1), 0x00db4962025555aab1dabf8c6eda931d))
r := xor(r, mul(and(shr(84, v), 1), 0xefd282331287775f9cb76d437afa2af4))
r := xor(r, mul(and(shr(85, v), 1), 0x005a68ffc8bb123839157cede80abb56))
r := xor(r, mul(and(shr(86, v), 1), 0xaa8cf4dfecd7c6e8756dd13b5c8f5aca))
r := xor(r, mul(and(shr(87, v), 1), 0x021af06bb686259ccb7fd58ec495d475))
r := xor(r, mul(and(shr(88, v), 1), 0xecdf1c0a39e0e69edd223ac63f94d3cd))
r := xor(r, mul(and(shr(89, v), 1), 0x464b5cd033da15250a59b81eb662376d))
r := xor(r, mul(and(shr(90, v), 1), 0xfaa1c4106cecddd1e1ef0970d9739a93))
r := xor(r, mul(and(shr(91, v), 1), 0xb8ca7cb682820f3876fa81b790ed93c1))
r := xor(r, mul(and(shr(92, v), 1), 0xecba8b8b7f03d6c49ad4f151c9260931))
r := xor(r, mul(and(shr(93, v), 1), 0x1d60dcb980bbf80cf229556b3903eaef))
r := xor(r, mul(and(shr(94, v), 1), 0x05525a3168b2928eb6704455f531f9ce))
r := xor(r, mul(and(shr(95, v), 1), 0xe799e7eb44a895f570225704932e2b1a))
r := xor(r, mul(and(shr(96, v), 1), 0x4d407b2df1588fdb990fba30221753a7))
r := xor(r, mul(and(shr(97, v), 1), 0x5a9bb03388d916788319c89624300d82))
r := xor(r, mul(and(shr(98, v), 1), 0xa9d77c570bd47c6c66e124345a17db90))
r := xor(r, mul(and(shr(99, v), 1), 0x0a9ec560bb73e81d57e752162bbe4f3c))
r := xor(r, mul(and(shr(100, v), 1), 0xfa265c428c9da6f28e2fc970136e0b28))
r := xor(r, mul(and(shr(101, v), 1), 0xa5743cf56a237597ce580031f065e75e))
r := xor(r, mul(and(shr(102, v), 1), 0x137972c4434747054820151b571875b0))
r := xor(r, mul(and(shr(103, v), 1), 0x5c8cdc9126773bb5d414b37e60366586))
r := xor(r, mul(and(shr(104, v), 1), 0x129391be83f7a47bb70290df3750e40f))
r := xor(r, mul(and(shr(105, v), 1), 0xaeda7d495fc263f9b03de9fc7e321746))
r := xor(r, mul(and(shr(106, v), 1), 0xb4e1e37de895f7eebdb5b5394b075ef8))
r := xor(r, mul(and(shr(107, v), 1), 0xe2b5f04d33cf20822382a35dcc7edc4e))
r := xor(r, mul(and(shr(108, v), 1), 0xa9bcd291a1cf815f152fecdcbcccc914))
r := xor(r, mul(and(shr(109, v), 1), 0x5aa7ba1307657374613559d3f5f81fa7))
r := xor(r, mul(and(shr(110, v), 1), 0x4f5e74a697aee5d693c4698eebae59b5))
r := xor(r, mul(and(shr(111, v), 1), 0x155632caedb80d6b686706af56fc4b90))
r := xor(r, mul(and(shr(112, v), 1), 0xa68b8340c09a94a676d7d9a0790e3456))
r := xor(r, mul(and(shr(113, v), 1), 0xa12400cbbd51083dc4fca4a59fefba1d))
r := xor(r, mul(and(shr(114, v), 1), 0x436bbf27feb7ddeff06b53646f98b6b9))
r := xor(r, mul(and(shr(115, v), 1), 0xf9c43925d9ee85198e028ccfa403b668))
r := xor(r, mul(and(shr(116, v), 1), 0xe832f276830d436561fdd088096c633b))
r := xor(r, mul(and(shr(117, v), 1), 0x1bb6e92daca9c758540c1f17d6a3c2f9))
r := xor(r, mul(and(shr(118, v), 1), 0x0bb665e8a1f6f65dcb9c4864cb7ebf64))
r := xor(r, mul(and(shr(119, v), 1), 0xa58c2b939b7520a6fb1195e3a64b9e09))
r := xor(r, mul(and(shr(120, v), 1), 0x5d30484d6e9d13e9534ba48d6aa27e29))
r := xor(r, mul(and(shr(121, v), 1), 0x8948e62e9301d8fc28508f145c89bcb0))
r := xor(r, mul(and(shr(122, v), 1), 0xe70f02d3ff944a7f3fc77b1ef5e28fe3))
r := xor(r, mul(and(shr(123, v), 1), 0xb0a4e40faf35483b62a6ac2a434b53f5))
r := xor(r, mul(and(shr(124, v), 1), 0x07ff946d827c42ea27368426556c796f))
r := xor(r, mul(and(shr(125, v), 1), 0x1e487747cb1f2330293d260d4ef9e331))
r := xor(r, mul(and(shr(126, v), 1), 0x5c037a6cfa8c994eeda5fb46a4b26d21))
r := xor(r, mul(and(shr(127, v), 1), 0x26f2a0c6d87933fbc981c086e67c361d))
}
out := f2t(inp)
}
}
// ------------------------------------------------------------------ field arithmetic (tests)
/// @dev GF(2^128) multiplication in the flat basis (exposed for the test harness).
function gmulFlat(uint256 px, uint256 py) internal pure returns (uint256 out) {
assembly {
// carry-less multiply of two 128-bit polynomials via masked integer MULs, then reduce
function gmul(ga, gb) -> r {
let a0 := and(ga, 0x8421084210842108421084210842108421084210842108421084210842108421)
let a1 := and(ga, 0x0842108421084210842108421084210842108421084210842108421084210842)
let a2 := and(ga, 0x1084210842108421084210842108421084210842108421084210842108421084)
let a3 := and(ga, 0x2108421084210842108421084210842108421084210842108421084210842108)
let a4 := and(ga, 0x4210842108421084210842108421084210842108421084210842108421084210)
let b0 := and(gb, 0x8421084210842108421084210842108421084210842108421084210842108421)
let b1 := and(gb, 0x0842108421084210842108421084210842108421084210842108421084210842)
let b2 := and(gb, 0x1084210842108421084210842108421084210842108421084210842108421084)
let b3 := and(gb, 0x2108421084210842108421084210842108421084210842108421084210842108)
let b4 := and(gb, 0x4210842108421084210842108421084210842108421084210842108421084210)
r := and(xor(xor(mul(a0, b0), mul(a1, b4)), xor(xor(mul(a2, b3), mul(a3, b2)), mul(a4, b1))), 0x8421084210842108421084210842108421084210842108421084210842108421)
r := or(r, and(xor(xor(mul(a0, b1), mul(a1, b0)), xor(xor(mul(a2, b4), mul(a3, b3)), mul(a4, b2))), 0x0842108421084210842108421084210842108421084210842108421084210842))
r := or(r, and(xor(xor(mul(a0, b2), mul(a1, b1)), xor(xor(mul(a2, b0), mul(a3, b4)), mul(a4, b3))), 0x1084210842108421084210842108421084210842108421084210842108421084))
r := or(r, and(xor(xor(mul(a0, b3), mul(a1, b2)), xor(xor(mul(a2, b1), mul(a3, b0)), mul(a4, b4))), 0x2108421084210842108421084210842108421084210842108421084210842108))
r := or(r, and(xor(xor(mul(a0, b4), mul(a1, b3)), xor(xor(mul(a2, b2), mul(a3, b1)), mul(a4, b0))), 0x4210842108421084210842108421084210842108421084210842108421084210))
// reduce mod x^128 + x^7 + x^2 + x + 1 (deg r <= 254): two folds of the high half
let h := shr(128, r)
r := xor(and(r, 0xffffffffffffffffffffffffffffffff), xor(xor(h, shl(1, h)), xor(shl(2, h), shl(7, h))))
h := shr(128, r)
r := xor(and(r, 0xffffffffffffffffffffffffffffffff), xor(xor(h, shl(1, h)), xor(shl(2, h), shl(7, h))))
}
// squaring: spread bit i to bit 2i (128 -> 256 bits), then reduce
function gsqr(ga) -> r {
let x := ga
x := and(or(x, shl(64, x)), 0x0000000000000000ffffffffffffffff0000000000000000ffffffffffffffff)
x := and(or(x, shl(32, x)), 0x00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff)
x := and(or(x, shl(16, x)), 0x0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff)
x := and(or(x, shl(8, x)), 0x00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff)
x := and(or(x, shl(4, x)), 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f)
x := and(or(x, shl(2, x)), 0x3333333333333333333333333333333333333333333333333333333333333333)
x := and(or(x, shl(1, x)), 0x5555555555555555555555555555555555555555555555555555555555555555)
let h := shr(128, x)
r := xor(and(x, 0xffffffffffffffffffffffffffffffff), xor(xor(h, shl(1, h)), xor(shl(2, h), shl(7, h))))
h := shr(128, r)
r := xor(and(r, 0xffffffffffffffffffffffffffffffff), xor(xor(h, shl(1, h)), xor(shl(2, h), shl(7, h))))
}
out := gmul(px, py)
}
}
/// @dev GF(2^128) squaring in the flat basis (exposed for the test harness).
function gsqrFlat(uint256 px) internal pure returns (uint256 out) {
assembly {
// carry-less multiply of two 128-bit polynomials via masked integer MULs, then reduce
function gmul(ga, gb) -> r {
let a0 := and(ga, 0x8421084210842108421084210842108421084210842108421084210842108421)
let a1 := and(ga, 0x0842108421084210842108421084210842108421084210842108421084210842)
let a2 := and(ga, 0x1084210842108421084210842108421084210842108421084210842108421084)
let a3 := and(ga, 0x2108421084210842108421084210842108421084210842108421084210842108)
let a4 := and(ga, 0x4210842108421084210842108421084210842108421084210842108421084210)
let b0 := and(gb, 0x8421084210842108421084210842108421084210842108421084210842108421)
let b1 := and(gb, 0x0842108421084210842108421084210842108421084210842108421084210842)
let b2 := and(gb, 0x1084210842108421084210842108421084210842108421084210842108421084)
let b3 := and(gb, 0x2108421084210842108421084210842108421084210842108421084210842108)
let b4 := and(gb, 0x4210842108421084210842108421084210842108421084210842108421084210)
r := and(xor(xor(mul(a0, b0), mul(a1, b4)), xor(xor(mul(a2, b3), mul(a3, b2)), mul(a4, b1))), 0x8421084210842108421084210842108421084210842108421084210842108421)
r := or(r, and(xor(xor(mul(a0, b1), mul(a1, b0)), xor(xor(mul(a2, b4), mul(a3, b3)), mul(a4, b2))), 0x0842108421084210842108421084210842108421084210842108421084210842))
r := or(r, and(xor(xor(mul(a0, b2), mul(a1, b1)), xor(xor(mul(a2, b0), mul(a3, b4)), mul(a4, b3))), 0x1084210842108421084210842108421084210842108421084210842108421084))
r := or(r, and(xor(xor(mul(a0, b3), mul(a1, b2)), xor(xor(mul(a2, b1), mul(a3, b0)), mul(a4, b4))), 0x2108421084210842108421084210842108421084210842108421084210842108))
r := or(r, and(xor(xor(mul(a0, b4), mul(a1, b3)), xor(xor(mul(a2, b2), mul(a3, b1)), mul(a4, b0))), 0x4210842108421084210842108421084210842108421084210842108421084210))
// reduce mod x^128 + x^7 + x^2 + x + 1 (deg r <= 254): two folds of the high half
let h := shr(128, r)
r := xor(and(r, 0xffffffffffffffffffffffffffffffff), xor(xor(h, shl(1, h)), xor(shl(2, h), shl(7, h))))
h := shr(128, r)
r := xor(and(r, 0xffffffffffffffffffffffffffffffff), xor(xor(h, shl(1, h)), xor(shl(2, h), shl(7, h))))
}
// squaring: spread bit i to bit 2i (128 -> 256 bits), then reduce
function gsqr(ga) -> r {
let x := ga
x := and(or(x, shl(64, x)), 0x0000000000000000ffffffffffffffff0000000000000000ffffffffffffffff)
x := and(or(x, shl(32, x)), 0x00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff)
x := and(or(x, shl(16, x)), 0x0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff)
x := and(or(x, shl(8, x)), 0x00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff)
x := and(or(x, shl(4, x)), 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f)
x := and(or(x, shl(2, x)), 0x3333333333333333333333333333333333333333333333333333333333333333)
x := and(or(x, shl(1, x)), 0x5555555555555555555555555555555555555555555555555555555555555555)
let h := shr(128, x)
r := xor(and(x, 0xffffffffffffffffffffffffffffffff), xor(xor(h, shl(1, h)), xor(shl(2, h), shl(7, h))))
h := shr(128, r)
r := xor(and(r, 0xffffffffffffffffffffffffffffffff), xor(xor(h, shl(1, h)), xor(shl(2, h), shl(7, h))))
}
out := gsqr(px)
}
}
// ------------------------------------------------------------------ the permutation
/// @dev Poseidon2b on a flat-basis state (vendor permute_flat_u128 / portable permute_flat).
function _permute(uint256 s0, uint256 s1, uint256 s2, uint256 s3)
internal
pure
returns (uint256, uint256, uint256, uint256)
{
assembly {
// carry-less multiply of two 128-bit polynomials via masked integer MULs, then reduce
function gmul(ga, gb) -> r {
let a0 := and(ga, 0x8421084210842108421084210842108421084210842108421084210842108421)
let a1 := and(ga, 0x0842108421084210842108421084210842108421084210842108421084210842)
let a2 := and(ga, 0x1084210842108421084210842108421084210842108421084210842108421084)
let a3 := and(ga, 0x2108421084210842108421084210842108421084210842108421084210842108)
let a4 := and(ga, 0x4210842108421084210842108421084210842108421084210842108421084210)
let b0 := and(gb, 0x8421084210842108421084210842108421084210842108421084210842108421)
let b1 := and(gb, 0x0842108421084210842108421084210842108421084210842108421084210842)
let b2 := and(gb, 0x1084210842108421084210842108421084210842108421084210842108421084)
let b3 := and(gb, 0x2108421084210842108421084210842108421084210842108421084210842108)
let b4 := and(gb, 0x4210842108421084210842108421084210842108421084210842108421084210)
r := and(xor(xor(mul(a0, b0), mul(a1, b4)), xor(xor(mul(a2, b3), mul(a3, b2)), mul(a4, b1))), 0x8421084210842108421084210842108421084210842108421084210842108421)
r := or(r, and(xor(xor(mul(a0, b1), mul(a1, b0)), xor(xor(mul(a2, b4), mul(a3, b3)), mul(a4, b2))), 0x0842108421084210842108421084210842108421084210842108421084210842))
r := or(r, and(xor(xor(mul(a0, b2), mul(a1, b1)), xor(xor(mul(a2, b0), mul(a3, b4)), mul(a4, b3))), 0x1084210842108421084210842108421084210842108421084210842108421084))
r := or(r, and(xor(xor(mul(a0, b3), mul(a1, b2)), xor(xor(mul(a2, b1), mul(a3, b0)), mul(a4, b4))), 0x2108421084210842108421084210842108421084210842108421084210842108))
r := or(r, and(xor(xor(mul(a0, b4), mul(a1, b3)), xor(xor(mul(a2, b2), mul(a3, b1)), mul(a4, b0))), 0x4210842108421084210842108421084210842108421084210842108421084210))
// reduce mod x^128 + x^7 + x^2 + x + 1 (deg r <= 254): two folds of the high half
let h := shr(128, r)
r := xor(and(r, 0xffffffffffffffffffffffffffffffff), xor(xor(h, shl(1, h)), xor(shl(2, h), shl(7, h))))
h := shr(128, r)
r := xor(and(r, 0xffffffffffffffffffffffffffffffff), xor(xor(h, shl(1, h)), xor(shl(2, h), shl(7, h))))
}
// squaring: spread bit i to bit 2i (128 -> 256 bits), then reduce
function gsqr(ga) -> r {
let x := ga
x := and(or(x, shl(64, x)), 0x0000000000000000ffffffffffffffff0000000000000000ffffffffffffffff)
x := and(or(x, shl(32, x)), 0x00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff)
x := and(or(x, shl(16, x)), 0x0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff)
x := and(or(x, shl(8, x)), 0x00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff)
x := and(or(x, shl(4, x)), 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f)
x := and(or(x, shl(2, x)), 0x3333333333333333333333333333333333333333333333333333333333333333)
x := and(or(x, shl(1, x)), 0x5555555555555555555555555555555555555555555555555555555555555555)
let h := shr(128, x)
r := xor(and(x, 0xffffffffffffffffffffffffffffffff), xor(xor(h, shl(1, h)), xor(shl(2, h), shl(7, h))))
h := shr(128, r)
r := xor(and(r, 0xffffffffffffffffffffffffffffffff), xor(xor(h, shl(1, h)), xor(shl(2, h), shl(7, h))))
}
function sbox(x) -> r {
let x2 := gsqr(x)
r := gmul(gmul(x, x2), gsqr(x2))
}
// MDS_FULL with T1 = flat(2), T2 = flat(4), s = a+b+c+d:
// out0 = s + T2(a+b) + T1(b+d) out1 = T2(a+b) + T1 b + c + d
// out2 = s + T1(b+d) + T2(c+d) out3 = a + b + T2(c+d) + T1 d
function mdsFull(ia, ib, ic, id) -> na, nb, nc, nd {
let u := gmul(xor(ia, ib), 0xa72ec17764d7ced55e2f716f4ede412f)
let v := gmul(xor(ic, id), 0xa72ec17764d7ced55e2f716f4ede412f)
let p := gmul(ib, 0x3d5bd35c94646a247573da4a5f7710ed)
let q := gmul(id, 0x3d5bd35c94646a247573da4a5f7710ed)
let s := xor(xor(ia, ib), xor(ic, id))
na := xor(xor(s, u), xor(p, q))
nb := xor(xor(u, p), xor(ic, id))
nc := xor(xor(s, p), xor(q, v))
nd := xor(xor(ia, ib), xor(v, q))
}
// MDS_PARTIAL = diag(0x20, 0x2000, 0x200, 0x800) + ones: out_i = (d_i + 1) in_i + s
function mdsPartial(ia, ib, ic, id) -> na, nb, nc, nd {
let s := xor(xor(ia, ib), xor(ic, id))
na := xor(s, gmul(ia, 0x486fb01f93aa169afd8ee716e990cf15))
nb := xor(s, gmul(ib, 0x86b6a57216f083193e1b361e8a1a5bbe))
nc := xor(s, gmul(ic, 0xb2ef6c31981e31582924ed9040490831))
nd := xor(s, gmul(id, 0xff829109128b0bd884cb11891ab51a3d))
}
let a := s0
let b := s1
let c := s2
let d := s3
a, b, c, d := mdsFull(a, b, c, d) // initial linear layer
// full round 0
a := sbox(xor(a, 0x00000000000000000000000000000000))
b := sbox(xor(b, 0x3d5bd35c94646a247573da4a5f7710ec))
c := sbox(xor(c, 0x9a75122bf0b3a4f12b5cab2511a951c2))
d := sbox(xor(d, 0x9a75122bf0b3a4f12b5cab2511a951c3))
a, b, c, d := mdsFull(a, b, c, d)
// full round 1
a := sbox(xor(a, 0x00000000000000000000000000000001))
b := sbox(xor(b, 0x3d5bd35c94646a247573da4a5f7710ec))
c := sbox(xor(c, 0x00000000000000000000000000000000))
d := sbox(xor(d, 0x00000000000000000000000000000001))
a, b, c, d := mdsFull(a, b, c, d)
// full round 2
a := sbox(xor(a, 0x00000000000000000000000000000000))
b := sbox(xor(b, 0x00000000000000000000000000000000))
c := sbox(xor(c, 0xa72ec17764d7ced55e2f716f4ede412e))
d := sbox(xor(d, 0x00000000000000000000000000000001))
a, b, c, d := mdsFull(a, b, c, d)
// full round 3
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ec))
b := sbox(xor(b, 0x9a75122bf0b3a4f12b5cab2511a951c2))
c := sbox(xor(c, 0x3d5bd35c94646a247573da4a5f7710ec))
d := sbox(xor(d, 0xa72ec17764d7ced55e2f716f4ede412e))
a, b, c, d := mdsFull(a, b, c, d)
// partial round 4
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c3))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 5
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c3))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 6
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c2))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 7
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c2))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 8
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 9
a := sbox(xor(a, 0x00000000000000000000000000000001))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 10
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c3))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 11
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 12
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 13
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ec))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 14
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ec))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 15
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 16
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c2))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 17
a := sbox(xor(a, 0xa72ec17764d7ced55e2f716f4ede412e))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 18
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c3))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 19
a := sbox(xor(a, 0xa72ec17764d7ced55e2f716f4ede412e))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 20
a := sbox(xor(a, 0x00000000000000000000000000000000))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 21
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 22
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 23
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ec))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 24
a := sbox(xor(a, 0x00000000000000000000000000000001))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 25
a := sbox(xor(a, 0xa72ec17764d7ced55e2f716f4ede412e))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 26
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 27
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c2))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 28
a := sbox(xor(a, 0x00000000000000000000000000000001))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 29
a := sbox(xor(a, 0xa72ec17764d7ced55e2f716f4ede412f))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 30
a := sbox(xor(a, 0x00000000000000000000000000000001))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 31
a := sbox(xor(a, 0x00000000000000000000000000000000))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 32
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ec))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 33
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c3))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 34
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 35
a := sbox(xor(a, 0x00000000000000000000000000000000))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 36
a := sbox(xor(a, 0x00000000000000000000000000000001))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 37
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 38
a := sbox(xor(a, 0xa72ec17764d7ced55e2f716f4ede412f))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 39
a := sbox(xor(a, 0x00000000000000000000000000000001))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 40
a := sbox(xor(a, 0x00000000000000000000000000000000))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 41
a := sbox(xor(a, 0x00000000000000000000000000000000))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 42
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 43
a := sbox(xor(a, 0xa72ec17764d7ced55e2f716f4ede412e))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 44
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c3))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 45
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 46
a := sbox(xor(a, 0x00000000000000000000000000000000))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 47
a := sbox(xor(a, 0xa72ec17764d7ced55e2f716f4ede412f))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 48
a := sbox(xor(a, 0x00000000000000000000000000000001))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 49
a := sbox(xor(a, 0xa72ec17764d7ced55e2f716f4ede412e))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 50
a := sbox(xor(a, 0xa72ec17764d7ced55e2f716f4ede412e))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 51
a := sbox(xor(a, 0x00000000000000000000000000000001))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 52
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 53
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c3))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 54
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ec))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 55
a := sbox(xor(a, 0x00000000000000000000000000000001))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 56
a := sbox(xor(a, 0x00000000000000000000000000000000))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 57
a := sbox(xor(a, 0x00000000000000000000000000000001))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 58
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ec))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 59
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c3))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 60
a := sbox(xor(a, 0x00000000000000000000000000000001))
a, b, c, d := mdsPartial(a, b, c, d)
// partial round 61
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c2))
a, b, c, d := mdsPartial(a, b, c, d)
// full round 62
a := sbox(xor(a, 0x00000000000000000000000000000001))
b := sbox(xor(b, 0x3d5bd35c94646a247573da4a5f7710ec))
c := sbox(xor(c, 0x00000000000000000000000000000001))
d := sbox(xor(d, 0x00000000000000000000000000000001))
a, b, c, d := mdsFull(a, b, c, d)
// full round 63
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c2))
b := sbox(xor(b, 0xa72ec17764d7ced55e2f716f4ede412e))
c := sbox(xor(c, 0xa72ec17764d7ced55e2f716f4ede412f))
d := sbox(xor(d, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsFull(a, b, c, d)
// full round 64
a := sbox(xor(a, 0x9a75122bf0b3a4f12b5cab2511a951c2))
b := sbox(xor(b, 0x00000000000000000000000000000000))
c := sbox(xor(c, 0x00000000000000000000000000000001))
d := sbox(xor(d, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsFull(a, b, c, d)
// full round 65
a := sbox(xor(a, 0x3d5bd35c94646a247573da4a5f7710ed))
b := sbox(xor(b, 0x3d5bd35c94646a247573da4a5f7710ed))
c := sbox(xor(c, 0xa72ec17764d7ced55e2f716f4ede412e))
d := sbox(xor(d, 0x3d5bd35c94646a247573da4a5f7710ed))
a, b, c, d := mdsFull(a, b, c, d)
s0 := a
s1 := b
s2 := c
s3 := d
}
return (s0, s1, s2, s3);
}
}
Настройки компилятораПоказать
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": []
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.