From 42a3c915e45651f18bb4986061f4bb70d63dede2 Mon Sep 17 00:00:00 2001 From: Martin Ondejka Date: Wed, 28 Jun 2023 17:19:10 +0200 Subject: [PATCH] Add transaction commitment precompile --- core/vm/contracts.go | 2 +- core/vm/contracts_test.go | 8 +- core/vm/mina_contracts.go | 67 +- ...minaPoseidon.json => fail-minaHasher.json} | 0 .../{minaPoseidon.json => minaHasher.json} | 7 + mina/Cargo.lock | 919 +++++++++++++++++- mina/Cargo.toml | 21 +- mina/lib/mina.h | 7 + mina/src/lib.rs | 95 +- mina/src/mina.rs | 33 + 10 files changed, 1104 insertions(+), 55 deletions(-) rename core/vm/testdata/precompiles/{fail-minaPoseidon.json => fail-minaHasher.json} (100%) rename core/vm/testdata/precompiles/{minaPoseidon.json => minaHasher.json} (70%) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 9c17e64379..04d4fdfab1 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -105,7 +105,7 @@ var PrecompiledContractsBLS = map[common.Address]PrecompiledContract{ } var PrecompiledContractsMina = map[common.Address]PrecompiledContract{ - common.BytesToAddress([]byte{0x50}): &MinaPoseidon{}, + common.BytesToAddress([]byte{0x50}): &MinaHasher{}, common.BytesToAddress([]byte{0x51}): &MinaSigner{}, } diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index 3f2d416879..d8c9dcf21e 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -65,7 +65,7 @@ var allPrecompiles = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{16}): &bls12381Pairing{}, common.BytesToAddress([]byte{17}): &bls12381MapG1{}, common.BytesToAddress([]byte{18}): &bls12381MapG2{}, - common.BytesToAddress([]byte{0x50}): &MinaPoseidon{}, + common.BytesToAddress([]byte{0x50}): &MinaHasher{}, common.BytesToAddress([]byte{0x51}): &MinaSigner{}, } @@ -313,7 +313,7 @@ func TestPrecompiledBLS12381G2MultiExp(t *testing.T) { testJson("blsG2MultiExp", func TestPrecompiledBLS12381Pairing(t *testing.T) { testJson("blsPairing", "10", t) } func TestPrecompiledBLS12381MapG1(t *testing.T) { testJson("blsMapG1", "11", t) } func TestPrecompiledBLS12381MapG2(t *testing.T) { testJson("blsMapG2", "12", t) } -func TestPrecompiledMinaPoseidon(t *testing.T) { testJson("minaPoseidon", "50", t) } +func TestPrecompiledMinaHasher(t *testing.T) { testJson("minaHasher", "50", t) } func TestPrecompiledMinaSigner(t *testing.T) { testJson("minaSigner", "51", t) } func BenchmarkPrecompiledBLS12381G1Add(b *testing.B) { benchJson("blsG1Add", "0a", b) } @@ -325,7 +325,7 @@ func BenchmarkPrecompiledBLS12381G2MultiExp(b *testing.B) { benchJson("blsG2Mult func BenchmarkPrecompiledBLS12381Pairing(b *testing.B) { benchJson("blsPairing", "10", b) } func BenchmarkPrecompiledBLS12381MapG1(b *testing.B) { benchJson("blsMapG1", "11", b) } func BenchmarkPrecompiledBLS12381MapG2(b *testing.B) { benchJson("blsMapG2", "12", b) } -func BenchmarkPrecompiledMinaPoseidon(b *testing.B) { benchJson("minaPoseidon", "50", b) } +func BenchmarkPrecompiledMinaHasher(b *testing.B) { benchJson("minaHasher", "50", b) } func BenchmarkPrecompiledMinaSigner(b *testing.B) { benchJson("minaSigner", "51", b) } // Failure tests @@ -338,7 +338,7 @@ func TestPrecompiledBLS12381G2MultiExpFail(t *testing.T) { testJsonFail("blsG2Mu func TestPrecompiledBLS12381PairingFail(t *testing.T) { testJsonFail("blsPairing", "10", t) } func TestPrecompiledBLS12381MapG1Fail(t *testing.T) { testJsonFail("blsMapG1", "11", t) } func TestPrecompiledBLS12381MapG2Fail(t *testing.T) { testJsonFail("blsMapG2", "12", t) } -func TestPrecompiledMinaPoseidonFail(t *testing.T) { testJsonFail("minaPoseidon", "50", t) } +func TestPrecompiledMinaHasherFail(t *testing.T) { testJsonFail("minaHasher", "50", t) } func TestPrecompiledMinaSignerFail(t *testing.T) { testJsonFail("minaSigner", "51", t) } func loadJson(name string) ([]precompiledTest, error) { diff --git a/core/vm/mina_contracts.go b/core/vm/mina_contracts.go index d500ed861b..6ebecc0f53 100644 --- a/core/vm/mina_contracts.go +++ b/core/vm/mina_contracts.go @@ -13,6 +13,10 @@ package vm // HashParameter hashParameter, // bytes32[] memory fields // ) external view returns (bytes32); +// +// function transasctionCommitment( +// bytes memory zkappCommand +// ) external view returns (bytes32); // } // // interface ISigner { @@ -42,6 +46,7 @@ import ( var sol_bool, _ = abi.NewType("bool", "", nil) var sol_uint8, _ = abi.NewType("uint8", "", nil) var sol_string, _ = abi.NewType("string", "", nil) +var sol_bytes, _ = abi.NewType("bytes", "", nil) var sol_bytes32, _ = abi.NewType("bytes32", "", nil) var sol_bytes32Arr, _ = abi.NewType("bytes32[]", "", nil) @@ -62,22 +67,13 @@ var ( errMinaCallingRustLibFailed = errors.New("calling rust library failed") ) -type MinaPoseidon struct{} +type MinaHasher struct{} -func (c *MinaPoseidon) RequiredGas(input []byte) uint64 { +func (c *MinaHasher) RequiredGas(input []byte) uint64 { return 1000 } -// 0x1f831f84 -var poseidonHashSignature = crypto.Keccak256([]byte("poseidonHash(uint8,bytes32[])"))[:4] - -func (c *MinaPoseidon) Run(input []byte) ([]byte, error) { - if len(input) < 4 || !bytes.Equal(input[:4], poseidonHashSignature) { - return packErr("Invalid signature"), errMinaInvalidSignature - } - - calldata := input[4:] - +func poseidonHash(calldata []byte) ([]byte, error) { unpacked, err := (abi.Arguments{{ Type: sol_uint8}, // hashParameter {Type: sol_bytes32Arr}, // fields @@ -111,6 +107,53 @@ func (c *MinaPoseidon) Run(input []byte) ([]byte, error) { return output_buffer[:], nil } +func transasctionCommitment(calldata []byte) ([]byte, error) { + unpacked, err := (abi.Arguments{{Type: sol_bytes}}).Unpack(calldata) + + if err != nil { + return packErr("Unable to unpack calldata"), err + } + + zkappCommand := unpacked[0].([]uint8) + + output_buffer := [32]byte{} + + if !C.transaction_commitment( + (*C.uint8_t)(&zkappCommand[0]), + C.uintptr_t(len(zkappCommand)), + (*C.uint8_t)(&output_buffer[0]), + ) { + return packErr("Calling Transaction Commitment failed"), errMinaCallingRustLibFailed + } + + return output_buffer[:], nil +} + +// 0x1f831f84 +var poseidonHashSignature = crypto.Keccak256([]byte("poseidonHash(uint8,bytes32[])"))[:4] + +// 0x1a7f99b6 +var transasctionCommitmentSignature = crypto.Keccak256([]byte("transasctionCommitment(bytes)"))[:4] + +func (c *MinaHasher) Run(input []byte) ([]byte, error) { + if len(input) < 4 { + return packErr("Invalid signature"), errMinaInvalidSignature + } + + signature := input[:4] + calldata := input[4:] + + if bytes.Equal(signature, poseidonHashSignature) { + return poseidonHash(calldata) + } + + if bytes.Equal(signature, transasctionCommitmentSignature) { + return transasctionCommitment(calldata) + } + + return packErr("Invalid signature"), errMinaInvalidSignature +} + type MinaSigner struct{} func (c *MinaSigner) RequiredGas(input []byte) uint64 { diff --git a/core/vm/testdata/precompiles/fail-minaPoseidon.json b/core/vm/testdata/precompiles/fail-minaHasher.json similarity index 100% rename from core/vm/testdata/precompiles/fail-minaPoseidon.json rename to core/vm/testdata/precompiles/fail-minaHasher.json diff --git a/core/vm/testdata/precompiles/minaPoseidon.json b/core/vm/testdata/precompiles/minaHasher.json similarity index 70% rename from core/vm/testdata/precompiles/minaPoseidon.json rename to core/vm/testdata/precompiles/minaHasher.json index e812b8f92f..abb573f297 100644 --- a/core/vm/testdata/precompiles/minaPoseidon.json +++ b/core/vm/testdata/precompiles/minaHasher.json @@ -40,5 +40,12 @@ "Name": "vector 6", "Gas": 1000, "NoBenchmark": false + }, + { + "Input": "1a7f99b6000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001ed01756ae9c3d6720d4e0404bb335498e59370db54a717b4088898483bfb3f1e850a00000000d290f924705fb714e91fedb9bed77e85bce8f5d932c3f4d692b20e4c3e5f9a3343c2baffce9ab0c2391e2f3de8ac891633338d827e6fd4f269331c248029b10601756ae9c3d6720d4e0404bb335498e59370db54a717b4088898483bfb3f1e850a000100000000000000000000000000000000000000000000000000000000000000010101010101010100010101010101010a01000000000000000000000000000000000000000000000000000000000000000000000001010100010101010101010101010101010102010100000001d290f924705fb714e91fedb9bed77e85bce8f5d932c3f4d692b20e4c3e5f9a3343c2baffce9ab0c2391e2f3de8ac891633338d827e6fd4f269331c248029b10600014ff72ff7bf9824551a1b2bd5a2bebdb0234732f6f967f5d727fd80864a35a810010100000000000000000000000000000000000000000000000000000000000000010101010101010100010101010101010a0000000000000000000000000000000000000000000000000000000000000000000000000101010001010101010101010101010101010201000000020200000000220100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "Expected": "9484a9d4aac1d64a958aa88dd1943a87216739980701a4c8e3963633a678603e", + "Name": "transaction commitment", + "Gas": 1000, + "NoBenchmark": false } ] diff --git a/mina/Cargo.lock b/mina/Cargo.lock index 7b1e9baa17..8dc18f04bf 100644 --- a/mina/Cargo.lock +++ b/mina/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "ahash" version = "0.7.6" @@ -13,11 +28,25 @@ dependencies = [ "version_check", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "ark-ec" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dea978406c4b1ca13c2db2373b05cc55429c3575b8b21f1b9ee859aa5b03dd42" +source = "git+https://github.com/openmina/algebra?branch=openmina#017531e7aaa15a2c856532b0843876e371b01122" dependencies = [ "ark-ff", "ark-serialize", @@ -31,8 +60,7 @@ dependencies = [ [[package]] name = "ark-ff" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b3235cc41ee7a12aaaf2c575a2ad7b46713a8a50bda2fc3b003a04845c05dd6" +source = "git+https://github.com/openmina/algebra?branch=openmina#017531e7aaa15a2c856532b0843876e371b01122" dependencies = [ "ark-ff-asm", "ark-ff-macros", @@ -43,15 +71,14 @@ dependencies = [ "num-traits", "paste", "rayon", - "rustc_version", + "rustc_version 0.3.3", "zeroize", ] [[package]] name = "ark-ff-asm" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" +source = "git+https://github.com/openmina/algebra?branch=openmina#017531e7aaa15a2c856532b0843876e371b01122" dependencies = [ "quote", "syn 1.0.109", @@ -60,8 +87,7 @@ dependencies = [ [[package]] name = "ark-ff-macros" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db2fd794a08ccb318058009eefdf15bcaaaaf6f8161eb3345f907222bac38b20" +source = "git+https://github.com/openmina/algebra?branch=openmina#017531e7aaa15a2c856532b0843876e371b01122" dependencies = [ "num-bigint", "num-traits", @@ -72,8 +98,7 @@ dependencies = [ [[package]] name = "ark-poly" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0f78f47537c2f15706db7e98fe64cc1711dbf9def81218194e17239e53e5aa" +source = "git+https://github.com/openmina/algebra?branch=openmina#017531e7aaa15a2c856532b0843876e371b01122" dependencies = [ "ark-ff", "ark-serialize", @@ -86,8 +111,7 @@ dependencies = [ [[package]] name = "ark-serialize" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6c2b318ee6e10f8c2853e73a83adc0ccb88995aa978d8a3408d492ab2ee671" +source = "git+https://github.com/openmina/algebra?branch=openmina#017531e7aaa15a2c856532b0843876e371b01122" dependencies = [ "ark-serialize-derive", "ark-std", @@ -97,8 +121,7 @@ dependencies = [ [[package]] name = "ark-serialize-derive" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dd4e5f0bf8285d5ed538d27fab7411f3e297908fd93c62195de8bee3f199e82" +source = "git+https://github.com/openmina/algebra?branch=openmina#017531e7aaa15a2c856532b0843876e371b01122" dependencies = [ "proc-macro2", "quote", @@ -116,6 +139,17 @@ dependencies = [ "rayon", ] +[[package]] +name = "async-channel" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + [[package]] name = "atty" version = "0.2.14" @@ -133,6 +167,27 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "bcs" version = "0.1.5" @@ -143,6 +198,34 @@ dependencies = [ "thiserror", ] +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "binprot" +version = "0.1.8" +source = "git+https://github.com/openmina/binprot-rs?rev=ead5ba916725abf8ab212b89985b47c79d1a006a#ead5ba916725abf8ab212b89985b47c79d1a006a" +dependencies = [ + "binprot_derive", + "byteorder", + "md5", +] + +[[package]] +name = "binprot_derive" +version = "0.1.7" +source = "git+https://github.com/openmina/binprot-rs?rev=ead5ba916725abf8ab212b89985b47c79d1a006a#ead5ba916725abf8ab212b89985b47c79d1a006a" +dependencies = [ + "quote", + "syn 1.0.109", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -170,6 +253,15 @@ dependencies = [ "digest 0.10.6", ] +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -184,6 +276,21 @@ name = "bs58" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" +dependencies = [ + "sha2 0.9.9", +] + +[[package]] +name = "bumpalo" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cbindgen" @@ -216,6 +323,21 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "time", + "wasm-bindgen", + "winapi", +] + [[package]] name = "clap" version = "3.2.23" @@ -240,6 +362,27 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "concurrent-queue" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + [[package]] name = "cpufeatures" version = "0.2.6" @@ -249,6 +392,15 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + [[package]] name = "crossbeam-channel" version = "0.5.7" @@ -348,6 +500,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version 0.4.0", + "syn 1.0.109", +] + [[package]] name = "digest" version = "0.9.0" @@ -363,11 +528,17 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ - "block-buffer", + "block-buffer 0.10.4", "crypto-common", "subtle", ] +[[package]] +name = "disjoint-set" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d102f1a462fdcdddce88d6d46c06c074a2d2749b262230333726b06c52bb7585" + [[package]] name = "either" version = "1.8.1" @@ -395,6 +566,12 @@ dependencies = [ "libc", ] +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + [[package]] name = "fastrand" version = "1.9.0" @@ -416,6 +593,95 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "futures" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" + +[[package]] +name = "futures-executor" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" + +[[package]] +name = "futures-macro" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.13", +] + +[[package]] +name = "futures-sink" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" + +[[package]] +name = "futures-task" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" + +[[package]] +name = "futures-util" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -433,8 +699,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", + "js-sys", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", +] + +[[package]] +name = "gimli" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" + +[[package]] +name = "groupmap" +version = "0.1.0" +source = "git+https://github.com/openmina/proof-systems?branch=ledger-newtypes#debf1501e0f319771ffc1d5a65de5b2cf60e44b8" +dependencies = [ + "ark-ec", + "ark-ff", + "rand", ] [[package]] @@ -488,6 +772,29 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "iana-time-zone" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -524,18 +831,77 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +[[package]] +name = "js-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "kimchi" +version = "0.1.0" +source = "git+https://github.com/openmina/proof-systems?branch=ledger-newtypes#debf1501e0f319771ffc1d5a65de5b2cf60e44b8" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-poly", + "ark-serialize", + "blake2", + "disjoint-set", + "groupmap", + "hex", + "itertools", + "mina-curves", + "mina-poseidon 0.1.0 (git+https://github.com/openmina/proof-systems?branch=ledger-newtypes)", + "num-bigint", + "num-derive", + "num-integer", + "num-traits", + "o1-utils", + "once_cell", + "poly-commitment", + "rand", + "rand_core", + "rayon", + "rmp-serde", + "serde", + "serde_with", + "strum", + "strum_macros", + "thiserror", + "turshi", +] + [[package]] name = "libc" version = "0.2.141" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +[[package]] +name = "libm" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" + [[package]] name = "linux-raw-sys" version = "0.3.1" @@ -551,6 +917,18 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "md5" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + [[package]] name = "memoffset" version = "0.8.0" @@ -564,9 +942,12 @@ dependencies = [ name = "mina" version = "0.1.0" dependencies = [ + "binprot", "cbindgen", "mina-hasher", + "mina-p2p-messages", "mina-signer", + "mina-tree", "num-bigint", "o1-utils", "serde", @@ -576,7 +957,7 @@ dependencies = [ [[package]] name = "mina-curves" version = "0.1.0" -source = "git+https://github.com/o1-labs/proof-systems?tag=0.1.0#2e7f353719bdcb90f1f346f796b8ea69a3c30ec5" +source = "git+https://github.com/openmina/proof-systems?branch=ledger-newtypes#debf1501e0f319771ffc1d5a65de5b2cf60e44b8" dependencies = [ "ark-ec", "ark-ff", @@ -585,20 +966,61 @@ dependencies = [ [[package]] name = "mina-hasher" version = "0.1.0" -source = "git+https://github.com/o1-labs/proof-systems?tag=0.1.0#2e7f353719bdcb90f1f346f796b8ea69a3c30ec5" +source = "git+https://github.com/openmina/proof-systems?branch=ledger-newtypes#debf1501e0f319771ffc1d5a65de5b2cf60e44b8" dependencies = [ "ark-ff", "bitvec", "mina-curves", - "mina-poseidon", + "mina-poseidon 0.1.0 (git+https://github.com/openmina/proof-systems?branch=ledger-newtypes)", "o1-utils", "serde", ] +[[package]] +name = "mina-p2p-messages" +version = "0.6.4" +source = "git+https://github.com/openmina/mina-p2p-messages-rs?branch=signed-amount#97cce0286aef69c26f3752c06d47daf4298a3656" +dependencies = [ + "ark-ff", + "base64", + "binprot", + "binprot_derive", + "blake2", + "bs58", + "derive_more", + "hex", + "mina-curves", + "mina-hasher", + "mina-poseidon 0.1.0 (git+https://github.com/o1-labs/proof-systems?rev=373a294cf87f94d1bb518a248fbf71364aa73526)", + "mina-signer", + "o1-utils", + "serde", + "serde_json", + "sha2 0.10.6", + "thiserror", +] + [[package]] name = "mina-poseidon" version = "0.1.0" -source = "git+https://github.com/o1-labs/proof-systems?tag=0.1.0#2e7f353719bdcb90f1f346f796b8ea69a3c30ec5" +source = "git+https://github.com/openmina/proof-systems?branch=ledger-newtypes#debf1501e0f319771ffc1d5a65de5b2cf60e44b8" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-poly", + "mina-curves", + "o1-utils", + "once_cell", + "rand", + "rayon", + "serde", + "serde_with", +] + +[[package]] +name = "mina-poseidon" +version = "0.1.0" +source = "git+https://github.com/o1-labs/proof-systems?rev=373a294cf87f94d1bb518a248fbf71364aa73526#373a294cf87f94d1bb518a248fbf71364aa73526" dependencies = [ "ark-ec", "ark-ff", @@ -615,7 +1037,7 @@ dependencies = [ [[package]] name = "mina-signer" version = "0.1.0" -source = "git+https://github.com/o1-labs/proof-systems?tag=0.1.0#2e7f353719bdcb90f1f346f796b8ea69a3c30ec5" +source = "git+https://github.com/openmina/proof-systems?branch=ledger-newtypes#debf1501e0f319771ffc1d5a65de5b2cf60e44b8" dependencies = [ "ark-ec", "ark-ff", @@ -627,10 +1049,67 @@ dependencies = [ "mina-hasher", "o1-utils", "rand", - "sha2", + "sha2 0.10.6", "thiserror", ] +[[package]] +name = "mina-tree" +version = "0.1.0" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-poly", + "ark-serialize", + "backtrace", + "base64", + "bincode", + "binprot", + "binprot_derive", + "bitvec", + "blake2", + "bs58", + "chrono", + "crc32fast", + "derive_more", + "getrandom", + "hex", + "itertools", + "kimchi", + "libc", + "mina-curves", + "mina-hasher", + "mina-p2p-messages", + "mina-poseidon 0.1.0 (git+https://github.com/openmina/proof-systems?branch=ledger-newtypes)", + "mina-signer", + "num-bigint", + "o1-utils", + "once_cell", + "packed_simd_2", + "poly-commitment", + "rand", + "rand_pcg", + "rand_seeder", + "rayon", + "serde", + "serde_json", + "sha2 0.10.6", + "static_assertions", + "tuple-map", + "uuid", + "wasm-bindgen", + "wasm_thread", +] + +[[package]] +name = "miniz_oxide" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +dependencies = [ + "adler", +] + [[package]] name = "num-bigint" version = "0.4.3" @@ -641,6 +1120,18 @@ dependencies = [ "num-integer", "num-traits", "rand", + "serde", +] + +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", ] [[package]] @@ -675,7 +1166,7 @@ dependencies = [ [[package]] name = "o1-utils" version = "0.1.0" -source = "git+https://github.com/o1-labs/proof-systems?tag=0.1.0#2e7f353719bdcb90f1f346f796b8ea69a3c30ec5" +source = "git+https://github.com/openmina/proof-systems?branch=ledger-newtypes#debf1501e0f319771ffc1d5a65de5b2cf60e44b8" dependencies = [ "ark-ec", "ark-ff", @@ -691,22 +1182,47 @@ dependencies = [ "rayon", "serde", "serde_with", - "sha2", + "sha2 0.10.6", "thiserror", ] +[[package]] +name = "object" +version = "0.30.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "os_str_bytes" version = "6.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" +[[package]] +name = "packed_simd_2" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1914cd452d8fccd6f9db48147b29fd4ae05bea9dc5d9ad578509f72415de282" +dependencies = [ + "cfg-if", + "libm", +] + [[package]] name = "paste" version = "1.0.12" @@ -723,6 +1239,42 @@ dependencies = [ "ucd-trie", ] +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "poly-commitment" +version = "0.1.0" +source = "git+https://github.com/openmina/proof-systems?branch=ledger-newtypes#debf1501e0f319771ffc1d5a65de5b2cf60e44b8" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-poly", + "ark-serialize", + "blake2", + "groupmap", + "itertools", + "mina-curves", + "mina-poseidon 0.1.0 (git+https://github.com/openmina/proof-systems?branch=ledger-newtypes)", + "o1-utils", + "once_cell", + "rand", + "rand_core", + "rayon", + "serde", + "serde_with", + "thiserror", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -783,6 +1335,24 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rand_pcg" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rand_seeder" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf2890aaef0aa82719a50e808de264f9484b74b442e1a3a0e5ee38243ac40bdb" +dependencies = [ + "rand_core", +] + [[package]] name = "rayon" version = "1.7.0" @@ -814,13 +1384,50 @@ dependencies = [ "bitflags", ] +[[package]] +name = "rmp" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44519172358fd6d58656c86ab8e7fbc9e1490c3e8f14d35ed78ca0dd07403c9f" +dependencies = [ + "byteorder", + "num-traits", + "paste", +] + +[[package]] +name = "rmp-serde" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5b13be192e0220b8afb7222aa5813cb62cc269ebb5cac346ca6487681d2913e" +dependencies = [ + "byteorder", + "rmp", + "serde", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + [[package]] name = "rustc_version" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" dependencies = [ - "semver", + "semver 0.11.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.17", ] [[package]] @@ -837,6 +1444,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "rustversion" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" + [[package]] name = "ryu" version = "1.0.13" @@ -858,6 +1471,12 @@ dependencies = [ "semver-parser", ] +[[package]] +name = "semver" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" + [[package]] name = "semver-parser" version = "0.10.2" @@ -920,6 +1539,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + [[package]] name = "sha2" version = "0.10.6" @@ -931,12 +1563,46 @@ dependencies = [ "digest 0.10.6", ] +[[package]] +name = "slab" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +dependencies = [ + "autocfg", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strsim" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" + +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 1.0.109", +] + [[package]] name = "subtle" version = "2.4.1" @@ -1019,6 +1685,17 @@ dependencies = [ "syn 2.0.13", ] +[[package]] +name = "time" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + [[package]] name = "toml" version = "0.5.11" @@ -1028,6 +1705,22 @@ dependencies = [ "serde", ] +[[package]] +name = "tuple-map" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d5919d7121237af683b7fa982450597b1eaa2643e597aec3b519e4e5ab3d62" + +[[package]] +name = "turshi" +version = "0.1.0" +source = "git+https://github.com/openmina/proof-systems?branch=ledger-newtypes#debf1501e0f319771ffc1d5a65de5b2cf60e44b8" +dependencies = [ + "ark-ff", + "hex", + "o1-utils", +] + [[package]] name = "typenum" version = "1.16.0" @@ -1046,18 +1739,110 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +[[package]] +name = "uuid" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d023da39d1fde5a8a3fe1f3e01ca9632ada0a63e9797de55a879d6e2236277be" +dependencies = [ + "getrandom", +] + [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.13", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.13", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" + +[[package]] +name = "wasm_thread" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a52fc987e67957cab58160d1ea273a2886972ef6f59c7fa0c02e9fe2c8e11706" +dependencies = [ + "async-channel", + "futures", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "web-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" @@ -1089,13 +1874,22 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets 0.48.0", +] + [[package]] name = "windows-sys" version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.2", ] [[package]] @@ -1104,13 +1898,28 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -1119,42 +1928,84 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + [[package]] name = "wyz" version = "0.5.1" diff --git a/mina/Cargo.toml b/mina/Cargo.toml index 4049088cdc..b7d4952064 100644 --- a/mina/Cargo.toml +++ b/mina/Cargo.toml @@ -9,9 +9,12 @@ edition = "2021" crate-type = ["staticlib"] [dependencies] -mina-hasher = { git = "https://github.com/o1-labs/proof-systems", tag = "0.1.0", version = "0.1.0" } -mina-signer = { git = "https://github.com/o1-labs/proof-systems", tag = "0.1.0", version = "0.1.0" } -o1-utils = { git = "https://github.com/o1-labs/proof-systems", tag = "0.1.0", version = "0.1.0" } +mina-tree = { version = "0.1.0", path = "../../ledger" } +mina-p2p-messages = { git = "https://github.com/openmina/mina-p2p-messages-rs", branch = "signed-amount", features = ["hashing"] } +mina-hasher = { git = "https://github.com/openmina/proof-systems", branch = "ledger-newtypes" } +mina-signer = { git = "https://github.com/openmina/proof-systems", branch = "ledger-newtypes" } +o1-utils = { git = "https://github.com/openmina/proof-systems", branch = "ledger-newtypes" } +binprot = { git = "https://github.com/openmina/binprot-rs", rev = "ead5ba916725abf8ab212b89985b47c79d1a006a" } [build-dependencies] cbindgen = "0.24.3" @@ -20,3 +23,15 @@ cbindgen = "0.24.3" num-bigint = "0.4.3" serde = "1.0.160" serde_json = "1.0.96" + +[patch.crates-io] +ark-ff = { git = "https://github.com/openmina/algebra", branch = "openmina" } +ark-ec = { git = "https://github.com/openmina/algebra", branch = "openmina" } +ark-poly = { git = "https://github.com/openmina/algebra", branch = "openmina" } +ark-serialize = { git = "https://github.com/openmina/algebra", branch = "openmina" } + +[patch.'https://github.com/o1-labs/proof-systems'] +mina-hasher = { git = "https://github.com/openmina/proof-systems", branch = "ledger-newtypes" } +mina-signer = { git = "https://github.com/openmina/proof-systems", branch = "ledger-newtypes" } +mina-curves = { git = "https://github.com/openmina/proof-systems", branch = "ledger-newtypes" } +o1-utils = { git = "https://github.com/openmina/proof-systems", branch = "ledger-newtypes" } diff --git a/mina/lib/mina.h b/mina/lib/mina.h index 84b5f591f9..d00617a5f8 100644 --- a/mina/lib/mina.h +++ b/mina/lib/mina.h @@ -24,3 +24,10 @@ bool verify(uint8_t network_id, const uint8_t *field_ptr, uintptr_t field_len, bool *output_ptr); + +/** + * * # Safety * this functions accepts raw pointer from golang + */ +bool transaction_commitment(const uint8_t *zkapp_command_ptr, + uintptr_t zkapp_command_len, + uint8_t *output_ptr); diff --git a/mina/src/lib.rs b/mina/src/lib.rs index 967c596afd..442377277c 100644 --- a/mina/src/lib.rs +++ b/mina/src/lib.rs @@ -2,8 +2,13 @@ mod mina; use std::array::TryFromSliceError; -use mina::{HashParameter, Message}; +use binprot::BinProtRead; +use mina::{full_transaction_commitment, HashParameter, Message}; +use mina_p2p_messages::v2::{ + MinaBaseUserCommandStableV2, MinaBaseZkappCommandTStableV1WireStableV1, +}; use mina_signer::{BaseField, CurvePoint, PubKey, ScalarField, Signature}; +use mina_tree::scan_state::transaction_logic::zkapp_command::ZkAppCommand; use o1_utils::FieldHelpers; pub const FIELD_SIZE: usize = 32; @@ -139,6 +144,44 @@ pub unsafe extern "C" fn verify( true } +/** + * # Safety + * this functions accepts raw pointer from golang + */ +#[no_mangle] +pub unsafe extern "C" fn transaction_commitment( + zkapp_command_ptr: *const u8, + zkapp_command_len: usize, + output_ptr: *mut u8, // 32 bytes +) -> bool { + if zkapp_command_ptr.is_null() || zkapp_command_len == 0 || output_ptr.is_null() { + return false; + } + + let mut raw_zkapp_command = + unsafe { std::slice::from_raw_parts(zkapp_command_ptr, zkapp_command_len * FIELD_SIZE) }; + + let p2p_user_command = match MinaBaseUserCommandStableV2::binprot_read(&mut raw_zkapp_command) { + Ok(p2p_user_command) => p2p_user_command, + Err(_) => return false, + }; + + let p2p_zkapp_command: MinaBaseZkappCommandTStableV1WireStableV1 = match p2p_user_command { + MinaBaseUserCommandStableV2::ZkappCommand(zkapp_command) => zkapp_command, + _ => return false, + }; + + let zkapp_command = ZkAppCommand::from(&p2p_zkapp_command); + + let commitment = full_transaction_commitment(&zkapp_command); + + let output = unsafe { std::slice::from_raw_parts_mut(output_ptr, FIELD_SIZE) }; + + output.copy_from_slice(&commitment.0.to_bytes()); + + true +} + #[cfg(test)] mod tests { use std::str::FromStr; @@ -266,6 +309,56 @@ mod tests { 0, std::ptr::null_mut() )); + assert!(!transaction_commitment( + std::ptr::null(), + 0, + std::ptr::null_mut() + )); } } + + #[test] + fn test_transaction_commitment() { + let expected_commitment = BaseField::from_str( + "28213846620687386246595472357080373779104425260189267168855581893969578656916", + ) + .expect("valid field element"); + + let zkapp_command_bytes: Vec = vec![ + 1, 117, 106, 233, 195, 214, 114, 13, 78, 4, 4, 187, 51, 84, 152, 229, 147, 112, 219, + 84, 167, 23, 180, 8, 136, 152, 72, 59, 251, 63, 30, 133, 10, 0, 0, 0, 0, 210, 144, 249, + 36, 112, 95, 183, 20, 233, 31, 237, 185, 190, 215, 126, 133, 188, 232, 245, 217, 50, + 195, 244, 214, 146, 178, 14, 76, 62, 95, 154, 51, 67, 194, 186, 255, 206, 154, 176, + 194, 57, 30, 47, 61, 232, 172, 137, 22, 51, 51, 141, 130, 126, 111, 212, 242, 105, 51, + 28, 36, 128, 41, 177, 6, 1, 117, 106, 233, 195, 214, 114, 13, 78, 4, 4, 187, 51, 84, + 152, 229, 147, 112, 219, 84, 167, 23, 180, 8, 136, 152, 72, 59, 251, 63, 30, 133, 10, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 10, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 0, 0, 0, 1, 210, 144, 249, + 36, 112, 95, 183, 20, 233, 31, 237, 185, 190, 215, 126, 133, 188, 232, 245, 217, 50, + 195, 244, 214, 146, 178, 14, 76, 62, 95, 154, 51, 67, 194, 186, 255, 206, 154, 176, + 194, 57, 30, 47, 61, 232, 172, 137, 22, 51, 51, 141, 130, 126, 111, 212, 242, 105, 51, + 28, 36, 128, 41, 177, 6, 0, 1, 79, 247, 47, 247, 191, 152, 36, 85, 26, 27, 43, 213, + 162, 190, 189, 176, 35, 71, 50, 246, 249, 103, 245, 215, 39, 253, 128, 134, 74, 53, + 168, 16, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 10, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 0, 0, 0, 2, 2, 0, 0, + 0, 0, 34, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + ]; + + let mut output = [0u8; 32]; + + assert!(unsafe { + transaction_commitment( + zkapp_command_bytes.as_ptr(), + zkapp_command_bytes.len(), + output.as_mut_ptr(), + ) + }); + + assert_eq!(BaseField::from_bytes(&output).unwrap(), expected_commitment); + } } diff --git a/mina/src/mina.rs b/mina/src/mina.rs index a61844737b..17864b17cb 100644 --- a/mina/src/mina.rs +++ b/mina/src/mina.rs @@ -1,5 +1,6 @@ use mina_hasher::{DomainParameter, Hashable, Hasher, ROInput}; use mina_signer::{BaseField, PubKey, Signature, Signer}; +use mina_tree::scan_state::transaction_logic::zkapp_command::{AccountUpdate, ZkAppCommand}; use o1_utils::{field_helpers::FieldHelpersError, FieldHelpers}; #[derive(Debug, Clone)] @@ -8,6 +9,7 @@ pub enum HashParameter { Mainnet = 0x00, Testnet = 0x01, Empty = 0x02, + TransactionCommitment = 0x03, } impl From for u8 { @@ -51,11 +53,32 @@ impl Hashable for Message { match network_id { HashParameter::Mainnet => "MinaSignatureMainnet".to_string().into(), HashParameter::Testnet => "CodaSignature".to_string().into(), + HashParameter::TransactionCommitment => "MinaAcctUpdateCons".to_string().into(), HashParameter::Empty => None, } } } +#[derive(Clone, Debug)] +pub struct TransactionCommitment(pub BaseField); + +impl TransactionCommitment { + fn create(account_updates_hash: BaseField) -> Self { + Self(account_updates_hash) + } + + fn create_complete(&self, memo_hash: BaseField, fee_payer_hash: BaseField) -> Self { + let mut hasher = + mina_hasher::create_kimchi::(HashParameter::TransactionCommitment); + + let msg = &Message { + fields: vec![memo_hash, fee_payer_hash, self.0], + }; + + TransactionCommitment(hasher.hash(msg)) + } +} + pub fn poseidon(msg: &Message, network_id: HashParameter) -> BaseField { let mut hasher = mina_hasher::create_kimchi::(network_id); @@ -72,3 +95,13 @@ pub fn verify( signer.verify(signature, pubkey, msg) } + +pub fn full_transaction_commitment(zkapp_command: &ZkAppCommand) -> TransactionCommitment { + let memo_hash = zkapp_command.memo.hash(); + let fee_payer_hash = AccountUpdate::of_fee_payer(zkapp_command.fee_payer.clone()).digest(); + let account_updates_hash = zkapp_command.account_updates_hash(); + + let txn_commitment = TransactionCommitment::create(account_updates_hash); + + txn_commitment.create_complete(memo_hash, fee_payer_hash) +}