Off-Narrative-Labs / Tuxedo

Write UTXO-based Substrate Runtimes
https://off-narrative-labs.github.io/Tuxedo/
Apache License 2.0
58 stars 18 forks source link

Improve Verifier Trait: Redeemer type and block number access #172

Closed JoshOrndorff closed 9 months ago

JoshOrndorff commented 9 months ago

First, I've made a small change to the verify method where we also pass in the block number. This may seem like the beginning of a slippery slope about what data will be made available to verifiers. I think some good boundaries are block header data and stuff that is available to bitcoin scripts.

Second, we've added an associated type Redeemer. Previously we just accepted a slice of bytes to represent the redeemer. And the first thing that every redeemer did was decode it to some expected type. By having an associated type, the executive can do the decoding and handle errors. This makes life easier for Verifier writers. See the changes to ThresholdMultisig as an example of why the new interface is cleaner.

JoshOrndorff commented 9 months ago

Thanks @muraca and @gorzorg for making the macro better. One other thing we could do is make the function name snake case with this crate https://crates.io/crates/convert_case. Perhaps here or in a follow up. I'm fine with either.

github-actions[bot] commented 9 months ago

Coverage after merging joshy-verifier-beef-up into main will be

60.94%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
tuxedo-core/aggregator/src
   lib.rs99.16%100%100%99.13%186, 22, 84
tuxedo-core/no_bound/src
   clone_no_bound.rs36.63%100%30%37.36%24, 32–39, 56, 59–72, 74–87, 89, 91–95, 98–99
   debug_no_bound.rs32.73%100%30%33%101–105, 108–109, 24, 32–42, 58, 60–78, 80–95, 97–99
   default_no_bound.rs19.11%100%16.67%19.31%100–122, 124–131, 133, 136–147, 151–157, 32–39, 51, 54–80, 83–88, 91–99
   lib.rs100%100%100%100%
tuxedo-core/src
   constraint_checker.rs54.02%100%50%55.22%71–91
   dynamic_typing.rs83.33%100%70.59%88.37%
   executive.rs92.15%100%93.55%91.98%118, 144, 177, 209, 238, 249, 300, 327, 378–383, 385, 395–396, 401–402, 404, 407–408, 411, 413–414, 417–418, 420, 424–445, 447, 451–452, 454–455, 457, 460–477, 54
   genesis.rs43.69%100%42.86%43.75%102–103, 106, 158–160, 169, 36–49, 60, 62–65, 67–68, 70–72, 75–79, 81–83, 85–96, 98–99
   inherents.rs7.02%100%11.76%6.19%121–123, 159, 165–179, 181–207, 216–221, 223–232, 234, 55–57, 64–69, 71–79, 82, 84
   types.rs65.99%100%48%72.11%82–86, 88–91, 93–99
   utxo_set.rs90.91%100%100%88.89%39–40
   verifier.rs55.10%100%43.24%62.30%55, 62–64
tuxedo-core/src/verifier
   multi_signature.rs89.96%100%70%93.78%45, 71
   simple_signature.rs79.56%100%58.82%86.41%61, 63
tuxedo-parachain-core/register_validate_block/src
   lib.rs0%100%0%0%100–119, 12, 120–125, 128, 13, 130–131, 14–16, 18, 29–35, 38–46, 50, 54–56, 59–61, 64–66, 84–99
tuxedo-parachain-core/src
   collation_api.rs0%100%0%0%19–40
   lib.rs48.65%100%53.85%45.83%85–90, 94–96
   relay_state_snapshot.rs0%100%0%0%112, 128–140, 147–155, 157, 173–188, 193–202, 204–211, 223, 225, 227–233, 235–240, 242, 245–250, 252–257, 259–271, 274–286, 292–298, 303–310, 316–323, 330–337, 346–354, 362–370, 378–383, 389–394, 41, 54, 82
   tests.rs100%100%100%100%
tuxedo-template-runtime/src
   genesis.rs84.62%100%88.89%84.35%23–45
   lib.rs5.38%100%13.41%3.36%100–103, 126, 129, 134–136, 140–142, 204, 206, 208, 210, 212, 214, 216, 218, 221, 223, 226, 232, 241–248, 252, 261–282, 285–312, 315–434, 62–67, 98–99
wallet/src
   amoeba.rs0%100%0%0%100–106, 109–110, 112–118, 120–127, 19–48, 51–52, 54–99
   cli.rs0%100%0%0%100, 115, 119, 125, 128, 133, 144, 150, 17, 20, 22, 31, 36, 41, 48, 65, 77
   keystore.rs0%100%0%0%30–33, 38–45, 47–48, 51, 53–59, 65–73, 76–78, 80–82, 85–91, 93–94
   main.rs0%100%0%0%100–193, 196–203, 206–209, 211–213, 216–218, 220, 222, 225–231, 234–247, 250–253, 255–266, 268, 27–99
   money.rs0%100%0%0%100, 106–113, 115, 119–124, 128, 131, 133, 136–139, 141–142, 146, 150–153, 155, 160–166, 168–172, 175–176, 180–185, 187–188, 191–202, 204, 206, 22–23, 25–40, 43, 47–60, 63–69, 72–90, 94–99
   output_filter.rs100%100%100%100%
   rpc.rs0%100%0%0%16–21, 24–26, 28–44, 47–53, 55–58, 60–61
   sync.rs0%100%0%0%103–106, 113–114, 116, 119–122, 127–129, 132–133, 136–141, 143–145, 148, 150–151, 156–159, 162–163, 170–174, 176–182, 185–187, 189–190, 193–194, 199–202, 205, 207–208, 213–216, 219, 221–222, 225–231, 233–234, 237–238, 241–242, 245–246, 250–256, 259–263, 266, 268, 271, 273, 277, 279–280, 283–284, 287–294, 296–297, 300–301, 303, 305–306, 310–312, 314–315, 317–318, 320–321, 324–326, 328–329, 331–332, 334–335, 339, 341–342, 346, 348–353, 356–357, 360–362, 365, 368–371, 373, 376–379, 382, 385–386, 389–390, 395–400, 402, 404, 409–412, 415–416, 419–424, 426, 429–430, 434–435, 437, 439–441, 443–446, 449–450, 46–50, 54, 57–58, 61, 63–77, 82–86, 88–89, 94–99
   timestamp.rs0%100%0%0%12–17, 20–27
wardrobe/amoeba/src
   lib.rs59.33%100%26.83%71.56%121, 139, 178, 81
   tests.rs100%100%100%100%
wardrobe/kitties/src
   lib.rs47.76%100%26.72%57.14%100, 102–103, 107–109, 117–119, 121–123, 127–129, 133–134, 137–139, 143–145, 150–152, 154–155, 159–161, 172–192, 211–212, 215–222, 225, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 391, 40–42, 423,