diff --git a/world-chain-builder/Cargo.lock b/world-chain-builder/Cargo.lock index 124c930e..1d6e1f58 100644 --- a/world-chain-builder/Cargo.lock +++ b/world-chain-builder/Cargo.lock @@ -158,9 +158,9 @@ dependencies = [ [[package]] name = "alloy-dyn-abi" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b499852e1d0e9b8c6db0f24c48998e647c0d5762a01090f955106a7700e4611" +checksum = "1109c57718022ac84c194f775977a534e1b3969b405e55693a61c42187cc0612" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -252,9 +252,9 @@ dependencies = [ [[package]] name = "alloy-json-abi" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a438d4486b5d525df3b3004188f9d5cd1d65cd30ecc41e5a3ccef6f6342e8af9" +checksum = "c4cc0e59c803dd44d14fc0cfa9fea1f74cfa8fd9fb60ca303ced390c58c28d4e" dependencies = [ "alloy-primitives", "alloy-sol-type-parser", @@ -359,9 +359,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "260d3ff3bff0bb84599f032a2f2c6828180b0ea0cd41fdaf44f39cef3ba41861" +checksum = "a289ffd7448036f2f436b377f981c79ce0b2090877bad938d43387dc09931877" dependencies = [ "alloy-rlp", "arbitrary", @@ -370,8 +370,9 @@ dependencies = [ "const-hex", "derive_arbitrary", "derive_more 1.0.0", + "foldhash", "getrandom", - "hashbrown 0.14.5", + "hashbrown 0.15.0", "hex-literal", "indexmap 2.6.0", "itoa", @@ -719,9 +720,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68e7f6e8fe5b443f82b3f1e15abfa191128f71569148428e49449d01f6f49e8b" +checksum = "0409e3ba5d1de409997a7db8b8e9d679d52088c1dee042a85033affd3cadeab4" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", @@ -733,9 +734,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-expander" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b96ce28d2fde09abb6135f410c41fad670a3a770b6776869bd852f1df102e6f" +checksum = "a18372ef450d59f74c7a64a738f546ba82c92f816597fed1802ef559304c81f1" dependencies = [ "alloy-sol-macro-input", "const-hex", @@ -751,9 +752,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-input" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "906746396a8296537745711630d9185746c0b50c033d5e9d18b0a6eba3d53f90" +checksum = "f7bad89dd0d5f109e8feeaf787a9ed7a05a91a9a0efc6687d147a70ebca8eff7" dependencies = [ "const-hex", "dunce", @@ -766,9 +767,9 @@ dependencies = [ [[package]] name = "alloy-sol-type-parser" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc85178909a49c8827ffccfc9103a7ce1767ae66a801b69bdc326913870bf8e6" +checksum = "dbd3548d5262867c2c4be6223fe4f2583e21ade0ca1c307fd23bc7f28fca479e" dependencies = [ "serde", "winnow 0.6.20", @@ -776,9 +777,9 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86a533ce22525969661b25dfe296c112d35eb6861f188fd284f8bd4bb3842ae" +checksum = "4aa666f1036341b46625e72bd36878bf45ad0185f1b88601223e1ec6ed4b72b1" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -1457,26 +1458,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bindgen" -version = "0.69.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" -dependencies = [ - "bitflags 2.6.0", - "cexpr", - "clang-sys", - "itertools 0.12.1", - "lazy_static 1.5.0", - "lazycell", - "proc-macro2", - "quote", - "regex", - "rustc-hash 1.1.0", - "shlex", - "syn 2.0.79", -] - [[package]] name = "bindgen" version = "0.70.1" @@ -1936,9 +1917,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.24" +version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812acba72f0a070b003d3697490d2b55b837230ae7c6c6497f05cc2ddbb8d938" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" dependencies = [ "jobserver", "libc", @@ -3544,6 +3525,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "foreign-types" version = "0.3.2" @@ -3591,9 +3578,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", @@ -3606,9 +3593,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -3616,15 +3603,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" dependencies = [ "futures-core", "futures-task", @@ -3633,15 +3620,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", @@ -3650,15 +3637,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-timer" @@ -3672,9 +3659,9 @@ dependencies = [ [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -3933,6 +3920,12 @@ name = "hashbrown" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", + "serde", +] [[package]] name = "hasher" @@ -4679,15 +4672,6 @@ dependencies = [ "either", ] -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.13.0" @@ -5019,12 +5003,6 @@ dependencies = [ "spin", ] -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "leb128" version = "0.2.5" @@ -5083,11 +5061,11 @@ dependencies = [ [[package]] name = "libproc" -version = "0.14.8" +version = "0.14.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae9ea4b75e1a81675429dafe43441df1caea70081e82246a8cccf514884a88bb" +checksum = "e78a09b56be5adbcad5aa1197371688dc6bb249a26da3bca2011ee2fb987ebfb" dependencies = [ - "bindgen 0.69.4", + "bindgen", "errno", "libc", ] @@ -5211,11 +5189,11 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "lru" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" dependencies = [ - "hashbrown 0.14.5", + "hashbrown 0.15.0", ] [[package]] @@ -5783,12 +5761,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.1" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" -dependencies = [ - "portable-atomic", -] +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "oorandom" @@ -6193,18 +6168,18 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +checksum = "baf123a161dde1e524adf36f90bc5d8d3462824a9c43553ad07a8183161189ec" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" dependencies = [ "proc-macro2", "quote", @@ -6890,7 +6865,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "sync_wrapper 0.1.2", - "system-configuration", + "system-configuration 0.5.1", "tokio", "tokio-native-tls", "tower-service", @@ -6909,9 +6884,11 @@ checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64 0.22.1", "bytes", + "encoding_rs", "futures-channel", "futures-core", "futures-util", + "h2 0.4.6", "http 1.1.0", "http-body 1.0.1", "http-body-util", @@ -6936,6 +6913,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "sync_wrapper 1.0.1", + "system-configuration 0.6.1", "tokio", "tokio-native-tls", "tokio-rustls", @@ -8130,7 +8108,7 @@ name = "reth-mdbx-sys" version = "1.0.8" source = "git+https://github.com/paradigmxyz/reth?rev=c35b8be#c35b8beb35594bb3192caec7d4335ca567d45539" dependencies = [ - "bindgen 0.70.1", + "bindgen", "cc", ] @@ -10088,9 +10066,9 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.24" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" dependencies = [ "windows-sys 0.59.0", ] @@ -10411,9 +10389,9 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.10.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9720086b3357bcb44fce40117d769a4d068c70ecfa190850a980a71755f66fcc" +checksum = "8e28bdad6db2b8340e449f7108f020b3b092e8583a9e3fb82713e1d4e71fe817" dependencies = [ "base64 0.22.1", "chrono", @@ -10429,9 +10407,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "3.10.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f1abbfe725f27678f4663bcacb75a83e829fd464c25d78dd038a3a29e307cec" +checksum = "9d846214a9854ef724f3da161b426242d8de7c1fc7de2f89bb1efcb154dca79d" dependencies = [ "darling 0.20.10", "proc-macro2", @@ -10830,9 +10808,9 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab661c8148c2261222a4d641ad5477fd4bea79406a99056096a0b41b35617a5" +checksum = "f3a850d65181df41b83c6be01a7d91f5e9377c43d48faa5af7d95816f437f5a3" dependencies = [ "paste", "proc-macro2", @@ -10901,7 +10879,18 @@ checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" dependencies = [ "bitflags 1.3.2", "core-foundation", - "system-configuration-sys", + "system-configuration-sys 0.5.0", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags 2.6.0", + "core-foundation", + "system-configuration-sys 0.6.0", ] [[package]] @@ -10914,6 +10903,16 @@ dependencies = [ "libc", ] +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "tap" version = "1.0.1" @@ -11369,6 +11368,8 @@ dependencies = [ "color-eyre", "dotenvy", "hex", + "rand", + "reqwest 0.12.8", "semaphore", "serde", "serde_json", diff --git a/world-chain-builder/crates/toolkit/Cargo.toml b/world-chain-builder/crates/toolkit/Cargo.toml index b2ba7073..232ebc8b 100644 --- a/world-chain-builder/crates/toolkit/Cargo.toml +++ b/world-chain-builder/crates/toolkit/Cargo.toml @@ -20,8 +20,10 @@ bytes = "1.7.2" clap = { version = "4", features = ["derive", "env"] } eyre = { version = "0.6", package = "color-eyre" } hex = "0.4.3" +reqwest = "0.12" serde = { version = "1", features = ["derive"] } serde_json = "1.0" tokio = { version = "1", features = ["full"] } dotenvy = "0.15.7" chrono = "0.4" +rand = "0.8.5" diff --git a/world-chain-builder/crates/toolkit/README.md b/world-chain-builder/crates/toolkit/README.md new file mode 100644 index 00000000..b088fd1a --- /dev/null +++ b/world-chain-builder/crates/toolkit/README.md @@ -0,0 +1,51 @@ +# Creating human verified txs + +## 0. Info +In order to create a PBH transaction we'll need 2 bits of secret information: +1. A wallet private key +2. An identity secret + +For the wallet we'll use the default test mnemonic used by both Anvil and Reth `test test test test test test test test test test test junk`. We can find the private key with the following command + +```bash +> cast wallet private-key --mnemonic "test test test test test test test test test test test junk" --mnemonic-index 0 +0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +``` + +The identity secret is a little weird since we never actually access it directly. Instead we use a seed to deterministicly generate an identity. For the purpose of testing we can use `11ff11` as our testing seed (the associated identity commitment is included in the staging sequencer). + +## 1. Craft a transaction with `cast mktx` +```bash +# Sends 1ETH from 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 to 0x8603937E3F761958187207aeab2714ECA1C1D031 +> cast mktx --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 0x8603937E3F761958187207aeab2714ECA1C1D031 --value 1ether +``` + +This should return +``` +0x02f870827a6980018477359401825209948603937e3f761958187207aeab2714eca1c1d031880de0b6b3a764000080c001a00ff6b2d8e020715137f19cbecf3b162576de99ce1b96b7158dafe2962e7d4c9ea0429a0a04cf25ba60444c0275f05bd83c20198be1612b6c08e30243d5feae71e4 +``` + +which we'll use in the next step + +## 2. Prove the transaction for PBH +```bash +> export IDENTITY=11ff11 +> export INCLUSION_PROOF_URL=https://signup-orb-ethereum.stage-crypto.worldcoin.dev/inclusionProof +> ./x prove -t 0x02f870827a6980018477359401825209948603937e3f761958187207aeab2714eca1c1d031880de0b6b3a764000080c001a00ff6b2d8e020715137f19cbecf3b162576de99ce1b96b7158dafe2962e7d4c9ea0429a0a04cf25ba60444c0275f05bd83c20198be1612b6c08e30243d5feae71e4 -N 3 +``` + +This should return +``` +02f870827a6980018477359401825209948603937e3f761958187207aeab2714eca1c1d031880de0b6b3a764000080c001a00ff6b2d8e020715137f19cbecf3b162576de99ce1b96b7158dafe2962e7d4c9ea0429a0a04cf25ba60444c0275f05bd83c20198be1612b6c08e30243d5feae71e4f901918b76312d3130323032342d339fba535b5fad84465fa11734ec0b5c932eef8abe2be0bc41b6dacf142efd2e36a02e1d5d3e2d601502f61491450ff8306522fd51153f0530c964f41f137d3fc62c9f2b7a5d363c79e99a8b2beca564b151cc7ec6f91c8bc2a105286deb68954ac7a001df1992cc8c17d0e2b2c2763b49f0fae836a2e967a24c8fa602ce3c17b7dbf4b901000885d05bc5474812458e3a0c8221cd1a1d206a3d14b88803549f08d80b3c6e1e25382e980a49388418261b5c928ce66bd33ee02f41e89e1d072d01c1e151830b0b6022659ce65dde6fc3f21110619c47e31174998b08e25534357a317ad1b7870e7a7044de43bf4a54f7b38a798a03c4404fc4ec8a543f7459555d9084e3f9c62ff7fe8b898e5529538b4d4c4a5cc7d51ad625bb68db07938f0a403968480ed808257ebbb03be708586a764a1eff0e024938440b7401ffba4982776fcfac932503907056ee0171baa1bc02d184afb154270122368a45fc51c66a9ed4c6692ade298500aa348decf3d713ce22e59acc886e43d6064c1c652bbcde38cf893e0392 +``` + +which is a concatenation of both the raw transaction and the PBH proof. + +We can now take this payload and publish it + +## 3. Publish the payload +Assuming you're env vars are pointing to an instance of the world chain builder, we can simply run: +```bash +> cast publish 02f870827a6980018477359401825209948603937e3f761958187207aeab2714eca1c1d031880de0b6b3a764000080c001a00ff6b2d8e020715137f19cbecf3b162576de99ce1b96b7158dafe2962e7d4c9ea0429a0a04cf25ba60444c0275f05bd83c20198be1612b6c08e30243d5feae71e4f901918b76312d3130323032342d339fba535b5fad84465fa11734ec0b5c932eef8abe2be0bc41b6dacf142efd2e36a02e1d5d3e2d601502f61491450ff8306522fd51153f0530c964f41f137d3fc62c9f2b7a5d363c79e99a8b2beca564b151cc7ec6f91c8bc2a105286deb68954ac7a001df1992cc8c17d0e2b2c2763b49f0fae836a2e967a24c8fa602ce3c17b7dbf4b901000885d05bc5474812458e3a0c8221cd1a1d206a3d14b88803549f08d80b3c6e1e25382e980a49388418261b5c928ce66bd33ee02f41e89e1d072d01c1e151830b0b6022659ce65dde6fc3f21110619c47e31174998b08e25534357a317ad1b7870e7a7044de43bf4a54f7b38a798a03c4404fc4ec8a543f7459555d9084e3f9c62ff7fe8b898e5529538b4d4c4a5cc7d51ad625bb68db07938f0a403968480ed808257ebbb03be708586a764a1eff0e024938440b7401ffba4982776fcfac932503907056ee0171baa1bc02d184afb154270122368a45fc51c66a9ed4c6692ade298500aa348decf3d713ce22e59acc886e43d6064c1c652bbcde38cf893e0392 +``` + diff --git a/world-chain-builder/crates/toolkit/src/cli.rs b/world-chain-builder/crates/toolkit/src/cli.rs index 09bbae08..4000801d 100644 --- a/world-chain-builder/crates/toolkit/src/cli.rs +++ b/world-chain-builder/crates/toolkit/src/cli.rs @@ -8,7 +8,9 @@ pub mod identity_source; pub mod inclusion_proof_source; mod utils; +/// A CLI utility for proving raw Ethereum transactions #[derive(Debug, Clone, Parser)] +#[clap(version, about)] pub struct Opt { #[clap(subcommand)] pub cmd: Cmd, @@ -16,9 +18,16 @@ pub struct Opt { #[derive(Debug, Clone, Parser)] pub enum Cmd { + /// Proves a transaction and returns a hex encoded payload ready to be sent to a World Chain Builder + /// + /// Note that it's necessary to provide the identity and inclusion proof + /// and there exist multiple ways to provide them + /// + /// For the identity in testing the simplest way is to use a predefined identity secret via `-I 11ff11` flag or `export IDENTITY=11ff11` env var + /// + /// For the inclusion proof you can fetch it dynamically from the (staging) sequencer API via `--inclusion-proof-url https://signup-orb-ethereum.stage-crypto.worldcoin.dev/inclusionProof` + /// or `export INCLUSION_PROOF_URL=https://signup-orb-ethereum.stage-crypto.worldcoin.dev/inclusionProof` env var Prove(ProveArgs), - - Send(SendArgs), } #[derive(Debug, Clone, Parser)] diff --git a/world-chain-builder/crates/toolkit/src/cli/identity_source.rs b/world-chain-builder/crates/toolkit/src/cli/identity_source.rs index 09c397eb..ba75c0ed 100644 --- a/world-chain-builder/crates/toolkit/src/cli/identity_source.rs +++ b/world-chain-builder/crates/toolkit/src/cli/identity_source.rs @@ -12,6 +12,7 @@ pub struct IdentitySource { #[clap( short = 'I', long, + env, conflicts_with = "identity_file", required_unless_present = "identity_file", value_parser = bytes_mut_parse_hex diff --git a/world-chain-builder/crates/toolkit/src/cli/inclusion_proof_source.rs b/world-chain-builder/crates/toolkit/src/cli/inclusion_proof_source.rs index 441306f2..d44c6ba0 100644 --- a/world-chain-builder/crates/toolkit/src/cli/inclusion_proof_source.rs +++ b/world-chain-builder/crates/toolkit/src/cli/inclusion_proof_source.rs @@ -4,6 +4,7 @@ use clap::Args; use semaphore::poseidon_tree::Proof; use super::utils::parse_from_json; +use crate::InclusionProof; #[derive(Debug, Clone, Args)] pub struct InclusionProofSource { @@ -13,32 +14,55 @@ pub struct InclusionProofSource { long, value_parser = parse_from_json::, conflicts_with = "inclusion_proof_file", - required_unless_present = "inclusion_proof_file" + conflicts_with = "inclusion_proof_url", + required_unless_present = "inclusion_proof_file", + required_unless_present = "inclusion_proof_url" )] - pub inclusion_proof: Option, + pub inclusion_proof: Option, #[clap( long, conflicts_with = "inclusion_proof", - required_unless_present = "inclusion_proof" + conflicts_with = "inclusion_proof_url", + required_unless_present = "inclusion_proof", + required_unless_present = "inclusion_proof_url" )] pub inclusion_proof_file: Option, - // TODO: Add fetching from signup-sequencer/world-tree - // TODO: Add fetching from smart contract via RPC + /// Endpoint to fetch the inclusion proof from + /// + /// i.e. https://world-tree.crypto.worldcoin.dev/inclusionProof + #[clap( + long, + env, + conflicts_with = "inclusion_proof", + conflicts_with = "inclusion_proof_file", + required_unless_present = "inclusion_proof", + required_unless_present = "inclusion_proof_file" + )] + pub inclusion_proof_url: Option, } impl InclusionProofSource { - pub fn load(&self) -> Proof { - if let Some(inclusion_proof) = self.inclusion_proof.clone() { - return inclusion_proof; + pub fn into_variant(self) -> InclusionProofSourceVariant { + if let Some(inclusion_proof) = self.inclusion_proof { + return InclusionProofSourceVariant::Proof(inclusion_proof); + } + + if let Some(inclusion_proof_file) = self.inclusion_proof_file { + return InclusionProofSourceVariant::File(inclusion_proof_file); } - if let Some(inclusion_proof_file) = &self.inclusion_proof_file { - let inclusion_proof = std::fs::read(inclusion_proof_file).unwrap(); - return serde_json::from_slice(&inclusion_proof).unwrap(); + if let Some(inclusion_proof_url) = self.inclusion_proof_url { + return InclusionProofSourceVariant::Url(inclusion_proof_url); } unreachable!() } } + +pub enum InclusionProofSourceVariant { + Proof(InclusionProof), + File(PathBuf), + Url(String), +} diff --git a/world-chain-builder/crates/toolkit/src/cli/utils.rs b/world-chain-builder/crates/toolkit/src/cli/utils.rs index ebbdd87a..d79064ce 100644 --- a/world-chain-builder/crates/toolkit/src/cli/utils.rs +++ b/world-chain-builder/crates/toolkit/src/cli/utils.rs @@ -8,12 +8,10 @@ pub fn bytes_mut_parse_hex(s: &str) -> eyre::Result { } pub fn bytes_parse_hex(s: &str) -> eyre::Result { - Ok(Bytes::from( - hex::decode(s.trim_start_matches("0x"))?, - )) + Ok(Bytes::from(hex::decode(s.trim_start_matches("0x"))?)) } -pub fn parse_from_json<'a, T>(s: &'a str) -> eyre::Result +pub fn parse_from_json(s: &str) -> eyre::Result where T: DeserializeOwned, { diff --git a/world-chain-builder/crates/toolkit/src/main.rs b/world-chain-builder/crates/toolkit/src/main.rs index e2293f9c..aef3367c 100644 --- a/world-chain-builder/crates/toolkit/src/main.rs +++ b/world-chain-builder/crates/toolkit/src/main.rs @@ -1,29 +1,49 @@ use alloy_consensus::TxEnvelope; use alloy_rlp::Decodable; use clap::Parser; +use cli::inclusion_proof_source::InclusionProofSourceVariant; use cli::{Cmd, Opt}; -use semaphore::hash_to_field; +use semaphore::identity::Identity; +use semaphore::poseidon_tree::Proof; +use semaphore::{hash_to_field, Field}; +use serde::{Deserialize, Serialize}; use world_chain_builder::date_marker::DateMarker; use world_chain_builder::external_nullifier::ExternalNullifier; +use world_chain_builder::pbh::semaphore::SemaphoreProof; mod cli; +#[derive(Debug, Clone, Serialize, Deserialize)] +struct InclusionProof { + root: Field, + proof: Proof, +} + #[tokio::main] async fn main() -> eyre::Result<()> { dotenvy::dotenv().ok(); let args = Opt::parse(); - println!("{:#?}", args); match args.cmd { Cmd::Prove(prove_args) => { - let tx: TxEnvelope = TxEnvelope::decode(&mut prove_args.tx.as_ref())?; + let raw_tx_bytes = prove_args.tx; + let tx: TxEnvelope = TxEnvelope::decode(&mut raw_tx_bytes.as_ref())?; let tx_hash = tx.tx_hash(); let signal_hash = hash_to_field(tx_hash.as_ref()); let identity = prove_args.identity_source.load(); - let merkle_proof = prove_args.inclusion_proof_source.load(); + + let inclusion_proof_proof_src = + prove_args.inclusion_proof_source.clone().into_variant(); + let inclusion_proof = match inclusion_proof_proof_src { + InclusionProofSourceVariant::Proof(proof) => proof, + InclusionProofSourceVariant::File(file) => load_inclusion_proof_file(file)?, + InclusionProofSourceVariant::Url(url) => { + fetch_inclusion_proof(&url, &identity).await? + } + }; let date = prove_args .custom_date @@ -36,13 +56,57 @@ async fn main() -> eyre::Result<()> { let semaphore_proof = semaphore::protocol::generate_proof( &identity, - &merkle_proof, + &inclusion_proof.proof, external_nullifier_hash, signal_hash, )?; + + let nullifier_hash = + semaphore::protocol::generate_nullifier_hash(&identity, external_nullifier_hash); + + let proof = SemaphoreProof { + external_nullifier: external_nullifier.to_string(), + external_nullifier_hash, + nullifier_hash, + signal_hash, + root: inclusion_proof.root, + proof: world_chain_builder::pbh::semaphore::Proof(semaphore_proof), + }; + + let encoded = alloy_rlp::encode(proof); + + let concatenated_bytes = [raw_tx_bytes.as_ref(), encoded.as_slice()].concat(); + + let encoded_hex = hex::encode(concatenated_bytes); + + println!("{}", encoded_hex); } - _ => unimplemented!(), } Ok(()) } + +fn load_inclusion_proof_file(path: impl AsRef) -> eyre::Result { + let file = std::fs::File::open(path)?; + let proof = serde_json::from_reader(file)?; + + Ok(proof) +} + +async fn fetch_inclusion_proof(url: &str, identity: &Identity) -> eyre::Result { + let client = reqwest::Client::new(); + + let commitment = identity.commitment(); + let response = client + .post(url) + .json(&serde_json::json! {{ + "identityCommitment": commitment, + }}) + .send() + .await? + .error_for_status()?; + + let proof: InclusionProof = response.json().await?; + + Ok(proof) +} diff --git a/world-chain-builder/src/lib.rs b/world-chain-builder/src/lib.rs index e47976de..ed8a0bd9 100644 --- a/world-chain-builder/src/lib.rs +++ b/world-chain-builder/src/lib.rs @@ -1,10 +1,10 @@ +pub mod date_marker; #[cfg(test)] pub mod e2e_tests; +pub mod external_nullifier; pub mod node; pub mod payload; pub mod pbh; pub mod pool; pub mod primitives; pub mod rpc; -pub mod external_nullifier; -pub mod date_marker; diff --git a/world-chain-builder/x b/world-chain-builder/x index 52fb6922..3e5a683f 100755 --- a/world-chain-builder/x +++ b/world-chain-builder/x @@ -1,7 +1,7 @@ #!/bin/bash if [ -n "$RELEASE" ]; then - cargo run --release --package toolkit "$@" + cargo run --release --package toolkit -- "$@" else - cargo run --package toolkit "$@" + cargo run --package toolkit -- "$@" fi