Skip to content
Verified contractPartial

MLDSA65

Address0xb152e0b101e0a52fd045cc3d032dd25e8c742f77
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.28

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
yul
Optimization
Yes, 200 runs
EVM version
cancun
License
Not stated
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,392,234
Creation transaction
0x8e1963ff8d…7369075a82

lattice/src/MLDSA65.yul

// MLDSA65.yul is GENERATED by gen_lattice.mjs from template.yul. Do not edit MLDSA65.yul.
//
// FIPS 204 ML-DSA-65 signature verification (Algorithm 7 with the external interface, pure ML-DSA), and the key
// expansion that LatticeKeys stores as contract code. The generated Keccak
// rounds use literal addresses, and the solc optimizer hoists those literals into stack slots (stack too deep), so the
// permutation is a separate contract, KeccakF.yul, compiled with the optimizer off; this object is optimized.
//
// Memory, absolute byte addresses:
//   0       Keccak lanes (25 words)         800   double buffer        1600  theta D (5 words)   1760  round constants
//   2560    NTT zetas (256 words)
//   10752   SQZ: squeeze output, absorb tail (1024)
//   11776   ACC: six rows of w (6 x 256 words); key expansion scratch
//   60928   ZP: the five z polynomials, then CP, the challenge c (6 x 256 words at one stride)
//   110080  W1: mu (64) then w1Encode (768)
//   110976  HM: six hint masks
//   111168  EK: expanded key: tr (64) | A-hat (30 x 1024, 4 bytes a coefficient) | NTT(t1 * 2^13) (6 x 1024)
//   148128  SIG (3309)
//   151488  MSG: the bytes hashed into mu
//
// Calls (Solidity ABI):
//   verifyStored(address,address,address,bytes,bytes,bytes) returns (bool)   key parts as code, message, context, sig
//   expandPart(bytes,uint256) returns (bytes)                                 part 0, 1 or 2 of the expanded key
//   verify(bytes,bytes,bytes,bytes) returns (bool)                            public key, message, context, sig
//   verifyInternal(bytes,bytes,bytes) returns (bool)                          FIPS 204 internal interface
//   verifyMu(bytes,bytes,bytes) returns (bool)                                with mu given
//   shake(uint256,bytes) returns (bytes32,bytes32)                            test: one squeeze block, first 64 bytes
//   bench(uint256,uint256) returns (uint256)                                  test: gas of n runs of one piece (0 Keccak-f, 1 NTT6, 2 INTT6, 3 products, 4 UseHint, 5 z, 6 SampleInBall, 7 hints)
object "MLDSA65" {
    code {
        // the Keccak-f permutation is its own contract, compiled with the optimizer off (KeccakF.yul), created here
        datacopy(0, dataoffset("KeccakF"), datasize("KeccakF"))
        let k := create(0, 0, datasize("KeccakF"))
        if iszero(k) { revert(0, 0) }
        datacopy(0, dataoffset("runtime"), datasize("runtime"))
        setimmutable(0, "keccak", k)
        return(0, datasize("runtime"))
    }
    data "KeccakF" hex"610ab961000e5f39610ab95ff3fe6103205f803760016106e0526180826107005267800000000000808a610720526780000000800080006107405261808b610760526380000001610780526780000000800080816107a0526780000000000080096107c052608a6107e052608861080052638000800961082052638000000a61084052638000808b6108605267800000000000008b610880526780000000000080896108a0526780000000000080036108c0526780000000000080026108e0526780000000000000806109005261800a6109205267800000008000000a61094052678000000080008081610960526780000000000080806109805263800000016109a0526780000000800080086109c0525f5b600c8110610112576103205ff35b600190610280516101e0516101405160a0515f51181818186102a051610200516101605160c05160205118181818906102c051610220516101805160e051604051181818186102e051610240516101a05161010051606051181818189261030051610260516101c05161012051608051181818189080603f1c878060401b0382891b161782186106405282603f1c878060401b0384891b161784186106605284603f1c878060401b0386891b1617186106805280603f1c90868060401b0390871b1617186106a05280603f1c90848060401b0390851b1617186106c052610640515f51186106605160c0511860141c838060401b036106605160c05118602c1b161761068051610180511860151c848060401b03610680516101805118602b1b1617916106a0516102405118602b1c858060401b036106a051610240511860151b16176106c051610300511860321c868060401b036106c0516103005118600e1b1617938560061b6106e001518185191684181861032052818119168418610340528482191618610360528184191618610380521916186103a0526106a0516060511860241c828060401b036106a05160605118601c1b16176106c0516101205118602c1c838060401b036106c051610120511860141b1617610640516101405118603d1c848060401b0361064051610140511860031b16179161066051610200511860131c858060401b03610660516102005118602d1b1617610680516102c0511860031c868060401b03610680516102c05118603d1b1617938084191683186103c0528181191684186103e052848219161861040052818419161861042052191618610440526106605160205118603f1c828060401b036106605160205118841b16176106805160e05118603a1c838060401b036106805160e0511860061b16176106a0516101a0511860271c848060401b036106a0516101a0511860191b1617916106c051610260511860381c858060401b036106c051610260511860081b1617610640516102805118602e1c868060401b0361064051610280511860121b161793808419168318610460528181191684186104805284821916186104a05281841916186104c0521916186104e0526106c0516080511860251c828060401b036106c05160805118601b1b16176106405160a05118601c1c838060401b036106405160a0511860241b161761066051610160511860361c848060401b03610660516101605118600a1b16179161068051610220511860311c858060401b03610680516102205118600f1b16176106a0516102e0511860081c868060401b036106a0516102e0511860381b161793808419168318610500528181191684186105205284821916186105405281841916186105605219161861058052610680516040511860021c828060401b036106805160405118603e1b16176106a051610100511860091c838060401b036106a051610100511860371b16176106c0516101c0511860191c848060401b036106c0516101c0511860271b161791610640516101e0511860171c858060401b03610640516101e0511860291b1617610660516102a05118603e1c868060401b03610660516102a0511860021b1617938084191683186105a0528181191684186105c05284821916186105e052818419161861060052191618610620526105a05161050051610460516103c05161032051181818186105c05161052051610480516103e0516103405118181818906105e051610540516104a05161040051610360511818181861060051610560516104c0516104205161038051181818189261062051610580516104e051610440516103a051181818189080603f1c878060401b0382891b161782186106405282603f1c878060401b0384891b161784186106605284603f1c878060401b0386891b1617186106805280603f1c90868060401b0390871b1617186106a05280603f1c90848060401b0390851b1617186106c052610640516103205118610660516103e0511860141c838060401b03610660516103e05118602c1b1617610680516104a0511860151c848060401b03610680516104a05118602b1b1617916106a0516105605118602b1c858060401b036106a051610560511860151b16176106c051610620511860321c868060401b036106c0516106205118600e1b1617938560061b6107000151818519168418185f52818119168418602052848219161860405281841916186060521916186080526106a051610380511860241c828060401b036106a0516103805118601c1b16176106c0516104405118602c1c838060401b036106c051610440511860141b1617610640516104605118603d1c848060401b0361064051610460511860031b16179161066051610520511860131c858060401b03610660516105205118602d1b1617610680516105e0511860031c868060401b03610680516105e05118603d1b16179380841916831860a05281811916841860c052848219161860e05281841916186101005219161861012052610660516103405118603f1c828060401b03610660516103405118841b1617610680516104005118603a1c838060401b0361068051610400511860061b16176106a0516104c0511860271c848060401b036106a0516104c0511860191b1617916106c051610580511860381c858060401b036106c051610580511860081b1617610640516105a05118602e1c868060401b03610640516105a0511860121b161793808419168318610140528181191684186101605284821916186101805281841916186101a0521916186101c0526106c0516103a0511860251c828060401b036106c0516103a05118601b1b1617610640516103c05118601c1c838060401b03610640516103c0511860241b161761066051610480511860361c848060401b03610660516104805118600a1b16179161068051610540511860311c858060401b03610680516105405118600f1b16176106a051610600511860081c868060401b036106a051610600511860381b1617938084191683186101e052818119168418610200528482191618610220528184191618610240521916186102605261068051610360511860021c828060401b03610680516103605118603e1b16176106a051610420511860091c838060401b036106a051610420511860371b16176106c0516104e0511860191c848060401b036106c0516104e0511860271b16179161064051610500511860171c858060401b0361064051610500511860291b1617610660516105c05118603e1c868060401b03610660516105c0511860021b161793808419168318610280528181191684186102a05284821916186102c05281841916186102e052191618610300520161010456"
    object "runtime" {
        code {
            if callvalue() { revert(0, 0) }
            init()
            switch shr(224, calldataload(0))
            case 0x1e86a6cf {
                let ok := loadStored(calldataload(4), calldataload(36), calldataload(68))
                if ok {
                    let m := add(4, calldataload(100))
                    let c := add(4, calldataload(132))
                    let s := add(4, calldataload(164))
                    mu(add(m, 32), calldataload(m), add(c, 32), calldataload(c), 1)
                    ok := loadSig(add(s, 32), calldataload(s))
                    if ok { ok := core() }
                }
                mstore(0, ok)
                return(0, 32)
            }
            case 0xbd7c364f {
                let pk := add(4, calldataload(4))
                if iszero(eq(calldataload(pk), 1952)) { revert(0, 0) }
                let part := calldataload(36)
                if gt(part, 2) { revert(0, 0) }
                calldatacopy(151488, add(pk, 32), 1952)
                let start := 111168
                let len := 10304
                switch part
                case 0 {
                    expandTr(151488)
                    expandRows(151488, 0)
                }
                case 1 {
                    expandRows(151488, 2)
                    start := add(111168, 10304)
                    len := 10240
                }
                default {
                    expandRows(151488, 4)
                    expandT1(151488)
                    start := add(111168, 20544)
                    len := 16384
                }
                mstore(sub(start, 64), 32)
                mstore(sub(start, 32), len)
                return(sub(start, 64), add(len, 64))
            }
            case 0x067874cf {
                let pk := add(4, calldataload(4))
                let m := add(4, calldataload(36))
                let c := add(4, calldataload(68))
                let s := add(4, calldataload(100))
                let ok := fullKey(pk)
                if ok {
                    mu(add(m, 32), calldataload(m), add(c, 32), calldataload(c), 1)
                    ok := loadSig(add(s, 32), calldataload(s))
                    if ok { ok := core() }
                }
                mstore(0, ok)
                return(0, 32)
            }
            case 0x509aafbb {
                let pk := add(4, calldataload(4))
                let m := add(4, calldataload(36))
                let s := add(4, calldataload(68))
                let ok := fullKey(pk)
                if ok {
                    mu(add(m, 32), calldataload(m), 0, 0, 0)
                    ok := loadSig(add(s, 32), calldataload(s))
                    if ok { ok := core() }
                }
                mstore(0, ok)
                return(0, 32)
            }
            case 0x90bd06a7 {
                let pk := add(4, calldataload(4))
                let u := add(4, calldataload(36))
                let s := add(4, calldataload(68))
                let ok := and(fullKey(pk), eq(calldataload(u), 64))
                if ok {
                    calldatacopy(110080, add(u, 32), 64)
                    ok := loadSig(add(s, 32), calldataload(s))
                    if ok { ok := core() }
                }
                mstore(0, ok)
                return(0, 32)
            }
            case 0x5f7f27d0 {
                let rate := calldataload(4)
                let d := add(4, calldataload(36))
                calldatacopy(151488, add(d, 32), calldataload(d))
                absorb(rate, 151488, calldataload(d))
                squeeze(rate, 10752)
                return(10752, 64)
            }
            case 0xddff0319 {
                let what := calldataload(4)
                let n := calldataload(36)
                let g := gas()
                for { let i := 0 } lt(i, n) { i := add(i, 1) } {
                    switch what
                    case 0 { keccakf() }
                    case 1 { ntt6(60928) }
                    case 2 { invntt6(11776) }
                    case 3 { products() }
                    case 4 { useHints() }
                    case 5 { pop(zDecode()) }
                    case 6 { sampleInBall() }
                    default { pop(hintUnpack()) }
                }
                mstore(0, sub(g, gas()))
                return(0, 32)
            }
            default { revert(0, 0) }

            // :: layout
            
            
            
            
            
            
            
            
            
            

            function init() {
                mstore(2560, 1)
                mstore(2592, 4808194)
                mstore(2624, 3765607)
                mstore(2656, 3761513)
                mstore(2688, 5178923)
                mstore(2720, 5496691)
                mstore(2752, 5234739)
                mstore(2784, 5178987)
                mstore(2816, 7778734)
                mstore(2848, 3542485)
                mstore(2880, 2682288)
                mstore(2912, 2129892)
                mstore(2944, 3764867)
                mstore(2976, 7375178)
                mstore(3008, 557458)
                mstore(3040, 7159240)
                mstore(3072, 5010068)
                mstore(3104, 4317364)
                mstore(3136, 2663378)
                mstore(3168, 6705802)
                mstore(3200, 4855975)
                mstore(3232, 7946292)
                mstore(3264, 676590)
                mstore(3296, 7044481)
                mstore(3328, 5152541)
                mstore(3360, 1714295)
                mstore(3392, 2453983)
                mstore(3424, 1460718)
                mstore(3456, 7737789)
                mstore(3488, 4795319)
                mstore(3520, 2815639)
                mstore(3552, 2283733)
                mstore(3584, 3602218)
                mstore(3616, 3182878)
                mstore(3648, 2740543)
                mstore(3680, 4793971)
                mstore(3712, 5269599)
                mstore(3744, 2101410)
                mstore(3776, 3704823)
                mstore(3808, 1159875)
                mstore(3840, 394148)
                mstore(3872, 928749)
                mstore(3904, 1095468)
                mstore(3936, 4874037)
                mstore(3968, 2071829)
                mstore(4000, 4361428)
                mstore(4032, 3241972)
                mstore(4064, 2156050)
                mstore(4096, 3415069)
                mstore(4128, 1759347)
                mstore(4160, 7562881)
                mstore(4192, 4805951)
                mstore(4224, 3756790)
                mstore(4256, 6444618)
                mstore(4288, 6663429)
                mstore(4320, 4430364)
                mstore(4352, 5483103)
                mstore(4384, 3192354)
                mstore(4416, 556856)
                mstore(4448, 3870317)
                mstore(4480, 2917338)
                mstore(4512, 1853806)
                mstore(4544, 3345963)
                mstore(4576, 1858416)
                mstore(4608, 3073009)
                mstore(4640, 1277625)
                mstore(4672, 5744944)
                mstore(4704, 3852015)
                mstore(4736, 4183372)
                mstore(4768, 5157610)
                mstore(4800, 5258977)
                mstore(4832, 8106357)
                mstore(4864, 2508980)
                mstore(4896, 2028118)
                mstore(4928, 1937570)
                mstore(4960, 4564692)
                mstore(4992, 2811291)
                mstore(5024, 5396636)
                mstore(5056, 7270901)
                mstore(5088, 4158088)
                mstore(5120, 1528066)
                mstore(5152, 482649)
                mstore(5184, 1148858)
                mstore(5216, 5418153)
                mstore(5248, 7814814)
                mstore(5280, 169688)
                mstore(5312, 2462444)
                mstore(5344, 5046034)
                mstore(5376, 4213992)
                mstore(5408, 4892034)
                mstore(5440, 1987814)
                mstore(5472, 5183169)
                mstore(5504, 1736313)
                mstore(5536, 235407)
                mstore(5568, 5130263)
                mstore(5600, 3258457)
                mstore(5632, 5801164)
                mstore(5664, 1787943)
                mstore(5696, 5989328)
                mstore(5728, 6125690)
                mstore(5760, 3482206)
                mstore(5792, 4197502)
                mstore(5824, 7080401)
                mstore(5856, 6018354)
                mstore(5888, 7062739)
                mstore(5920, 2461387)
                mstore(5952, 3035980)
                mstore(5984, 621164)
                mstore(6016, 3901472)
                mstore(6048, 7153756)
                mstore(6080, 2925816)
                mstore(6112, 3374250)
                mstore(6144, 1356448)
                mstore(6176, 5604662)
                mstore(6208, 2683270)
                mstore(6240, 5601629)
                mstore(6272, 4912752)
                mstore(6304, 2312838)
                mstore(6336, 7727142)
                mstore(6368, 7921254)
                mstore(6400, 348812)
                mstore(6432, 8052569)
                mstore(6464, 1011223)
                mstore(6496, 6026202)
                mstore(6528, 4561790)
                mstore(6560, 6458164)
                mstore(6592, 6143691)
                mstore(6624, 1744507)
                mstore(6656, 1753)
                mstore(6688, 6444997)
                mstore(6720, 5720892)
                mstore(6752, 6924527)
                mstore(6784, 2660408)
                mstore(6816, 6600190)
                mstore(6848, 8321269)
                mstore(6880, 2772600)
                mstore(6912, 1182243)
                mstore(6944, 87208)
                mstore(6976, 636927)
                mstore(7008, 4415111)
                mstore(7040, 4423672)
                mstore(7072, 6084020)
                mstore(7104, 5095502)
                mstore(7136, 4663471)
                mstore(7168, 8352605)
                mstore(7200, 822541)
                mstore(7232, 1009365)
                mstore(7264, 5926272)
                mstore(7296, 6400920)
                mstore(7328, 1596822)
                mstore(7360, 4423473)
                mstore(7392, 4620952)
                mstore(7424, 6695264)
                mstore(7456, 4969849)
                mstore(7488, 2678278)
                mstore(7520, 4611469)
                mstore(7552, 4829411)
                mstore(7584, 635956)
                mstore(7616, 8129971)
                mstore(7648, 5925040)
                mstore(7680, 4234153)
                mstore(7712, 6607829)
                mstore(7744, 2192938)
                mstore(7776, 6653329)
                mstore(7808, 2387513)
                mstore(7840, 4768667)
                mstore(7872, 8111961)
                mstore(7904, 5199961)
                mstore(7936, 3747250)
                mstore(7968, 2296099)
                mstore(8000, 1239911)
                mstore(8032, 4541938)
                mstore(8064, 3195676)
                mstore(8096, 2642980)
                mstore(8128, 1254190)
                mstore(8160, 8368000)
                mstore(8192, 2998219)
                mstore(8224, 141835)
                mstore(8256, 8291116)
                mstore(8288, 2513018)
                mstore(8320, 7025525)
                mstore(8352, 613238)
                mstore(8384, 7070156)
                mstore(8416, 6161950)
                mstore(8448, 7921677)
                mstore(8480, 6458423)
                mstore(8512, 4040196)
                mstore(8544, 4908348)
                mstore(8576, 2039144)
                mstore(8608, 6500539)
                mstore(8640, 7561656)
                mstore(8672, 6201452)
                mstore(8704, 6757063)
                mstore(8736, 2105286)
                mstore(8768, 6006015)
                mstore(8800, 6346610)
                mstore(8832, 586241)
                mstore(8864, 7200804)
                mstore(8896, 527981)
                mstore(8928, 5637006)
                mstore(8960, 6903432)
                mstore(8992, 1994046)
                mstore(9024, 2491325)
                mstore(9056, 6987258)
                mstore(9088, 507927)
                mstore(9120, 7192532)
                mstore(9152, 7655613)
                mstore(9184, 6545891)
                mstore(9216, 5346675)
                mstore(9248, 8041997)
                mstore(9280, 2647994)
                mstore(9312, 3009748)
                mstore(9344, 5767564)
                mstore(9376, 4148469)
                mstore(9408, 749577)
                mstore(9440, 4357667)
                mstore(9472, 3980599)
                mstore(9504, 2569011)
                mstore(9536, 6764887)
                mstore(9568, 1723229)
                mstore(9600, 1665318)
                mstore(9632, 2028038)
                mstore(9664, 1163598)
                mstore(9696, 5011144)
                mstore(9728, 3994671)
                mstore(9760, 8368538)
                mstore(9792, 7009900)
                mstore(9824, 3020393)
                mstore(9856, 3363542)
                mstore(9888, 214880)
                mstore(9920, 545376)
                mstore(9952, 7609976)
                mstore(9984, 3105558)
                mstore(10016, 7277073)
                mstore(10048, 508145)
                mstore(10080, 7826699)
                mstore(10112, 860144)
                mstore(10144, 3430436)
                mstore(10176, 140244)
                mstore(10208, 6866265)
                mstore(10240, 6195333)
                mstore(10272, 3123762)
                mstore(10304, 2358373)
                mstore(10336, 6187330)
                mstore(10368, 5365997)
                mstore(10400, 6663603)
                mstore(10432, 2926054)
                mstore(10464, 7987710)
                mstore(10496, 8077412)
                mstore(10528, 3531229)
                mstore(10560, 4405932)
                mstore(10592, 4606686)
                mstore(10624, 1900052)
                mstore(10656, 7598542)
                mstore(10688, 1054478)
                mstore(10720, 7648983)
            }

            // :: Keccak-f[1600], lanes at 0..800 (one 64-bit lane a word), double-buffered through 800..1600
            // Keccak-f[1600] on the 25 lanes at 0..800 (one 64-bit lane a word), in the KeccakF contract
            function keccakf() {
                if iszero(staticcall(gas(), loadimmutable("keccak"), 0, 800, 0, 800)) { revert(0, 0) }
            }

            function rev64(x) -> v {
                v := or(shl(8, and(x, 0x00FF00FF00FF00FF)), and(shr(8, x), 0x00FF00FF00FF00FF))
                v := or(shl(16, and(v, 0x0000FFFF0000FFFF)), and(shr(16, v), 0x0000FFFF0000FFFF))
                v := and(or(shl(32, v), shr(32, v)), 0xFFFFFFFFFFFFFFFF)
            }

            function xorBlock(p, rate) {
                for { let i := 0 } lt(i, shr(3, rate)) { i := add(i, 1) } {
                    let lp := shl(5, i)
                    mstore(lp, xor(mload(lp), rev64(shr(192, mload(add(p, shl(3, i)))))))
                }
            }

            // SHAKE absorb of len bytes at inp (domain byte 0x1F), permuted, ready to squeeze
            function absorb(rate, inp, len) {
                for { let i := 0 } lt(i, 800) { i := add(i, 32) } { mstore(i, 0) }
                let full := div(len, rate)
                for { let b := 0 } lt(b, full) { b := add(b, 1) } {
                    xorBlock(add(inp, mul(b, rate)), rate)
                    keccakf()
                }
                let t := 10752
                for { let i := 0 } lt(i, add(rate, 32)) { i := add(i, 32) } { mstore(add(t, i), 0) }
                let rest := sub(len, mul(full, rate))
                mcopy(t, add(inp, mul(full, rate)), rest)
                mstore8(add(t, rest), 0x1f)
                let lastp := add(t, sub(rate, 1))
                mstore8(lastp, or(byte(0, mload(lastp)), 0x80))
                xorBlock(t, rate)
                keccakf()
            }

            // one rate-sized block at out (24 bytes past it are clobbered), then permute
            function squeeze(rate, out) {
                for { let i := 0 } lt(i, shr(3, rate)) { i := add(i, 1) } {
                    mstore(add(out, shl(3, i)), shl(192, rev64(mload(shl(5, i)))))
                }
                keccakf()
            }

            // :: NTT (FIPS 204 Algorithms 41, 42) on six polynomials 8192 bytes apart, lazy reduction
            function ntt6(p) {
                let m := 0
                for { let len := 128 } gt(len, 0) { len := shr(1, len) } {
                    let gap := shl(5, len)
                    for { let start := 0 } lt(start, 256) { start := add(start, shl(1, len)) } {
                        m := add(m, 1)
                        let z := mload(add(2560, shl(5, m)))
                        let pa := add(p, shl(5, start))
                        let end := add(pa, gap)
                        for {} lt(pa, end) { pa := add(pa, 32) } {
                            let pb := add(pa, gap)
                            { let t := mulmod(z, mload(pb), 8380417) let a := mload(pa) mstore(pb, sub(add(a, 8380417), t)) mstore(pa, add(a, t)) }
                            { let t := mulmod(z, mload(add(pb, 8192)), 8380417) let a := mload(add(pa, 8192)) mstore(add(pb, 8192), sub(add(a, 8380417), t)) mstore(add(pa, 8192), add(a, t)) }
                            { let t := mulmod(z, mload(add(pb, 16384)), 8380417) let a := mload(add(pa, 16384)) mstore(add(pb, 16384), sub(add(a, 8380417), t)) mstore(add(pa, 16384), add(a, t)) }
                            { let t := mulmod(z, mload(add(pb, 24576)), 8380417) let a := mload(add(pa, 24576)) mstore(add(pb, 24576), sub(add(a, 8380417), t)) mstore(add(pa, 24576), add(a, t)) }
                            { let t := mulmod(z, mload(add(pb, 32768)), 8380417) let a := mload(add(pa, 32768)) mstore(add(pb, 32768), sub(add(a, 8380417), t)) mstore(add(pa, 32768), add(a, t)) }
                            { let t := mulmod(z, mload(add(pb, 40960)), 8380417) let a := mload(add(pa, 40960)) mstore(add(pb, 40960), sub(add(a, 8380417), t)) mstore(add(pa, 40960), add(a, t)) }
                        }
                    }
                }
            }

            // inputs below Q, outputs reduced below Q
            function invntt6(p) {
                let m := 256
                for { let len := 1 } lt(len, 256) { len := shl(1, len) } {
                    let gap := shl(5, len)
                    for { let start := 0 } lt(start, 256) { start := add(start, shl(1, len)) } {
                        m := sub(m, 1)
                        let z := sub(8380417, mload(add(2560, shl(5, m))))
                        let pa := add(p, shl(5, start))
                        let end := add(pa, gap)
                        for {} lt(pa, end) { pa := add(pa, 32) } {
                            let pb := add(pa, gap)
                            { let a := mload(pa) let b := mload(pb) mstore(pa, add(a, b)) mstore(pb, mulmod(z, sub(add(a, 4290773504), b), 8380417)) }
                            { let a := mload(add(pa, 8192)) let b := mload(add(pb, 8192)) mstore(add(pa, 8192), add(a, b)) mstore(add(pb, 8192), mulmod(z, sub(add(a, 4290773504), b), 8380417)) }
                            { let a := mload(add(pa, 16384)) let b := mload(add(pb, 16384)) mstore(add(pa, 16384), add(a, b)) mstore(add(pb, 16384), mulmod(z, sub(add(a, 4290773504), b), 8380417)) }
                            { let a := mload(add(pa, 24576)) let b := mload(add(pb, 24576)) mstore(add(pa, 24576), add(a, b)) mstore(add(pb, 24576), mulmod(z, sub(add(a, 4290773504), b), 8380417)) }
                            { let a := mload(add(pa, 32768)) let b := mload(add(pb, 32768)) mstore(add(pa, 32768), add(a, b)) mstore(add(pb, 32768), mulmod(z, sub(add(a, 4290773504), b), 8380417)) }
                            { let a := mload(add(pa, 40960)) let b := mload(add(pb, 40960)) mstore(add(pa, 40960), add(a, b)) mstore(add(pb, 40960), mulmod(z, sub(add(a, 4290773504), b), 8380417)) }
                        }
                    }
                }
                let pend := add(p, 49152)
                for { let i := p } lt(i, pend) { i := add(i, 32) } { mstore(i, mulmod(mload(i), 8347681, 8380417)) }
            }

            // :: key expansion
            function expandTr(pk) {
                absorb(136, pk, 1952)
                squeeze(136, 10752)
                mstore(111168, mload(10752))
                mstore(add(111168, 32), mload(add(10752, 32)))
            }

            // ExpandA (Algorithm 32), rows r0 and r0 + 1, packed 4 bytes a coefficient, big-endian
            function expandRows(pk, r0) {
                let seed := 11776
                for { let r := r0 } lt(r, add(r0, 2)) { r := add(r, 1) } {
                    for { let s := 0 } lt(s, 5) { s := add(s, 1) } {
                        mstore(seed, mload(pk))
                        mstore8(add(seed, 32), s)
                        mstore8(add(seed, 33), r)
                        absorb(168, seed, 34)
                        let out := add(add(111168, 64), shl(10, add(mul(r, 5), s)))
                        let n := 0
                        for {} lt(n, 256) {} {
                            squeeze(168, 10752)
                            for { let c := 0 } and(lt(c, 168), lt(n, 256)) { c := add(c, 3) } {
                                let w := mload(add(10752, c))
                                let z := or(or(byte(0, w), shl(8, byte(1, w))), shl(16, and(byte(2, w), 127)))
                                if lt(z, 8380417) {
                                    mstore(add(out, shl(2, n)), shl(224, z))
                                    n := add(n, 1)
                                }
                            }
                        }
                    }
                }
            }

            // NTT(t1 * 2^13), reduced, packed
            function expandT1(pk) {
                for { let i := 0 } lt(i, 6) { i := add(i, 1) } {
                    let src := add(add(pk, 32), mul(i, 320))
                    let row := add(11776, shl(13, i))
                    for { let j := 0 } lt(j, 64) { j := add(j, 1) } {
                        let w := mload(add(src, mul(j, 5)))
                        let b1 := byte(1, w)
                        let b2 := byte(2, w)
                        let b3 := byte(3, w)
                        let o := add(row, shl(7, j))
                        mstore(o, shl(13, or(byte(0, w), shl(8, and(b1, 3)))))
                        mstore(add(o, 32), shl(13, or(shr(2, b1), shl(6, and(b2, 15)))))
                        mstore(add(o, 64), shl(13, or(shr(4, b2), shl(4, and(b3, 63)))))
                        mstore(add(o, 96), shl(13, or(shr(6, b3), shl(2, byte(4, w)))))
                    }
                }
                ntt6(11776)
                for { let j := 0 } lt(j, 1536) { j := add(j, 1) } {
                    mstore(add(add(111168, 30784), shl(2, j)), shl(224, mod(mload(add(11776, shl(5, j))), 8380417)))
                }
            }

            // the whole expanded key from a public key in calldata (tests and the stateless path)
            function fullKey(pk) -> ok {
                ok := eq(calldataload(pk), 1952)
                if ok {
                    calldatacopy(151488, add(pk, 32), 1952)
                    expandTr(151488)
                    expandRows(151488, 0)
                    expandRows(151488, 2)
                    expandRows(151488, 4)
                    expandT1(151488)
                }
            }

            // the expanded key from the code of three part contracts (each a 0x00 byte, then the part)
            function loadStored(a0, a1, a2) -> ok {
                ok := and(and(eq(extcodesize(a0), 10305), eq(extcodesize(a1), 10241)), eq(extcodesize(a2), 16385))
                if ok {
                    extcodecopy(a0, 111168, 1, 10304)
                    extcodecopy(a1, add(111168, 10304), 1, 10240)
                    extcodecopy(a2, add(111168, 20544), 1, 16384)
                }
            }

            function loadSig(p, len) -> ok {
                ok := eq(len, 3309)
                if ok {
                    calldatacopy(148128, p, 3309)
                    mstore(add(148128, 3309), 0)
                }
            }

            // mu = H(tr || M', 64); external: M' = 0 || |ctx| || ctx || M; internal: M' = M
            function mu(m, mlen, c, clen, external_) {
                if gt(clen, 255) { revert(0, 0) }
                mstore(151488, mload(111168))
                mstore(add(151488, 32), mload(add(111168, 32)))
                let len := 64
                if external_ {
                    mstore8(add(151488, 64), 0)
                    mstore8(add(151488, 65), clen)
                    calldatacopy(add(151488, 66), c, clen)
                    len := add(66, clen)
                }
                calldatacopy(add(151488, len), m, mlen)
                absorb(136, 151488, add(len, mlen))
                squeeze(136, 10752)
                mstore(110080, mload(10752))
                mstore(add(110080, 32), mload(add(10752, 32)))
            }

            // :: Algorithm 8 with EK, mu (at W1) and SIG in place
            function core() -> ok {
                ok := hintUnpack()
                if ok { ok := zDecode() }
                if ok {
                    sampleInBall()
                    ntt6(60928)
                    products()
                    invntt6(11776)
                    useHints()
                    // c-tilde' = H(mu || w1Encode(w1), 48)
                    absorb(136, 110080, 832)
                    squeeze(136, 10752)
                    ok := and(iszero(xor(mload(10752), mload(148128))), iszero(shr(128, xor(mload(add(10752, 32)), mload(add(148128, 32))))))
                }
            }

            // HintBitUnpack (Algorithm 21), omega = 55, k = 6
            function hintUnpack() -> ok {
                ok := 1
                let y := add(148128, 3248)
                let idx := 0
                for { let i := 0 } lt(i, 6) { i := add(i, 1) } {
                    let lim := byte(0, mload(add(y, add(55, i))))
                    if or(lt(lim, idx), gt(lim, 55)) { ok := 0 }
                    let first := idx
                    let mask := 0
                    for {} and(lt(idx, lim), ok) { idx := add(idx, 1) } {
                        let cur := byte(0, mload(add(y, idx)))
                        if gt(idx, first) {
                            if iszero(lt(byte(0, mload(add(y, sub(idx, 1)))), cur)) { ok := 0 }
                        }
                        mask := or(mask, shl(cur, 1))
                    }
                    mstore(add(110976, shl(5, i)), mask)
                }
                for {} lt(idx, 55) { idx := add(idx, 1) } {
                    if byte(0, mload(add(y, idx))) { ok := 0 }
                }
            }

            // z: BitUnpack 20 bits, gamma1 = 2^19, and ||z|| < gamma1 - beta = 524092
            function zDecode() -> ok {
                let bad := 0
                for { let l := 0 } lt(l, 5) { l := add(l, 1) } {
                    let src := add(add(148128, 48), mul(l, 640))
                    let dst := add(60928, shl(13, l))
                    for { let j := 0 } lt(j, 128) { j := add(j, 1) } {
                        let w := mload(add(src, mul(j, 5)))
                        let b2 := byte(2, w)
                        let v0 := or(or(byte(0, w), shl(8, byte(1, w))), shl(16, and(b2, 15)))
                        let v1 := or(or(shr(4, b2), shl(4, byte(3, w))), shl(12, byte(4, w)))
                        bad := or(bad, or(or(lt(v0, 197), gt(v0, 1048379)), or(lt(v1, 197), gt(v1, 1048379))))
                        let o := add(dst, shl(6, j))
                        mstore(o, sub(8904705, v0))
                        mstore(add(o, 32), sub(8904705, v1))
                    }
                }
                ok := iszero(bad)
            }

            // SampleInBall (Algorithm 29), tau = 49, into CP
            function sampleInBall() {
                absorb(136, 148128, 48)
                squeeze(136, 10752)
                let signs := rev64(shr(192, mload(10752)))
                let pos := 8
                for { let i := 0 } lt(i, 8192) { i := add(i, 32) } { mstore(add(101888, i), 0) }
                for { let i := 207 } lt(i, 256) { i := add(i, 1) } {
                    let j := 256
                    for {} gt(j, i) {} {
                        if eq(pos, 136) {
                            squeeze(136, 10752)
                            pos := 0
                        }
                        j := byte(0, mload(add(10752, pos)))
                        pos := add(pos, 1)
                    }
                    mstore(add(101888, shl(5, i)), mload(add(101888, shl(5, j))))
                    mstore(add(101888, shl(5, j)), add(1, mul(and(signs, 1), 8380415)))
                    signs := shr(1, signs)
                }
            }

            // ACC row i = A-hat[i] . z-hat - c-hat * t1-hat[i], reduced (products below 9Q^2 each)
            function products() {
                for { let i := 0 } lt(i, 6) { i := add(i, 1) } {
                    let arow := add(add(111168, 36), mul(i, 5120))
                    let trow := add(add(111168, 30756), shl(10, i))
                    let out := add(11776, shl(13, i))
                    for { let j := 0 } lt(j, 256) { j := add(j, 1) } {
                        let o := shl(5, j)
                        let a := add(arow, shl(2, j))
                        let zo := add(60928, o)
                        let s := mul(and(mload(a), 0xffffffff), mload(zo))
                        s := add(s, mul(and(mload(add(a, 1024)), 0xffffffff), mload(add(zo, 8192))))
                        s := add(s, mul(and(mload(add(a, 2048)), 0xffffffff), mload(add(zo, 16384))))
                        s := add(s, mul(and(mload(add(a, 3072)), 0xffffffff), mload(add(zo, 24576))))
                        s := add(s, mul(and(mload(add(a, 4096)), 0xffffffff), mload(add(zo, 32768))))
                        let u := mul(and(mload(add(trow, shl(2, j))), 0xffffffff), mload(add(zo, 40960)))
                        mstore(add(out, o), mod(sub(add(s, 632082501845001), u), 8380417))
                    }
                }
            }

            // UseHint (Algorithm 40) with Decompose (Algorithm 36), gamma2 = (q-1)/32, then w1Encode (4 bits each)
            function useHints() {
                for { let i := 0 } lt(i, 6) { i := add(i, 1) } {
                    let rowp := add(11776, shl(13, i))
                    let mask := mload(add(110976, shl(5, i)))
                    let out := add(add(110080, 64), shl(7, i))
                    let low := 0
                    for { let j := 0 } lt(j, 256) { j := add(j, 1) } {
                        let r := mload(add(rowp, shl(5, j)))
                        let r0u := mod(r, 523776)
                        let big := gt(r0u, 261888)
                        let r1 := add(div(r, 523776), big)
                        // r1 = 16 only when r - r0 = q - 1: then r1 = 0 and r0 = r0 - 1
                        let special := eq(r1, 16)
                        r1 := mul(r1, iszero(special))
                        if and(shr(j, mask), 1) {
                            // r0 > 0: r1 + 1, otherwise r1 - 1, both mod 16
                            r1 := and(add(r1, add(15, shl(1, and(iszero(big), gt(r0u, special))))), 15)
                        }
                        switch and(j, 1)
                        case 0 { low := r1 }
                        default { mstore8(add(out, shr(1, j)), or(low, shl(4, r1))) }
                    }
                }
            }
        }
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.