diff --git a/Cargo.lock b/Cargo.lock index d506036..609ec4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -168,7 +168,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "banderwagon" version = "0.1.0" -source = "git+https://github.com/crate-crypto/rust-verkle?rev=6036bde9a8f416648213c59ad0c857b2a6f226f3#6036bde9a8f416648213c59ad0c857b2a6f226f3" +source = "git+https://github.com/crate-crypto/rust-verkle?rev=7688f0aedfb147d3d391abfe8495e46c46d72ce0#7688f0aedfb147d3d391abfe8495e46c46d72ce0" dependencies = [ "ark-ec", "ark-ed-on-bls12-381-bandersnatch", @@ -395,7 +395,7 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "ffi_interface" version = "0.1.0" -source = "git+https://github.com/crate-crypto/rust-verkle?rev=6036bde9a8f416648213c59ad0c857b2a6f226f3#6036bde9a8f416648213c59ad0c857b2a6f226f3" +source = "git+https://github.com/crate-crypto/rust-verkle?rev=7688f0aedfb147d3d391abfe8495e46c46d72ce0#7688f0aedfb147d3d391abfe8495e46c46d72ce0" dependencies = [ "banderwagon", "hex", @@ -522,7 +522,7 @@ dependencies = [ [[package]] name = "ipa-multipoint" version = "0.1.0" -source = "git+https://github.com/crate-crypto/rust-verkle?rev=6036bde9a8f416648213c59ad0c857b2a6f226f3#6036bde9a8f416648213c59ad0c857b2a6f226f3" +source = "git+https://github.com/crate-crypto/rust-verkle?rev=7688f0aedfb147d3d391abfe8495e46c46d72ce0#7688f0aedfb147d3d391abfe8495e46c46d72ce0" dependencies = [ "banderwagon", "hex", @@ -1039,13 +1039,14 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "verkle-db" version = "0.1.0" -source = "git+https://github.com/crate-crypto/rust-verkle?rev=6036bde9a8f416648213c59ad0c857b2a6f226f3#6036bde9a8f416648213c59ad0c857b2a6f226f3" +source = "git+https://github.com/crate-crypto/rust-verkle?rev=7688f0aedfb147d3d391abfe8495e46c46d72ce0#7688f0aedfb147d3d391abfe8495e46c46d72ce0" [[package]] name = "verkle-spec" version = "0.1.0" -source = "git+https://github.com/crate-crypto/rust-verkle?rev=6036bde9a8f416648213c59ad0c857b2a6f226f3#6036bde9a8f416648213c59ad0c857b2a6f226f3" +source = "git+https://github.com/crate-crypto/rust-verkle?rev=7688f0aedfb147d3d391abfe8495e46c46d72ce0#7688f0aedfb147d3d391abfe8495e46c46d72ce0" dependencies = [ + "banderwagon", "ethereum-types", "hex", "ipa-multipoint", @@ -1055,7 +1056,7 @@ dependencies = [ [[package]] name = "verkle-trie" version = "0.1.0" -source = "git+https://github.com/crate-crypto/rust-verkle?rev=6036bde9a8f416648213c59ad0c857b2a6f226f3#6036bde9a8f416648213c59ad0c857b2a6f226f3" +source = "git+https://github.com/crate-crypto/rust-verkle?rev=7688f0aedfb147d3d391abfe8495e46c46d72ce0#7688f0aedfb147d3d391abfe8495e46c46d72ce0" dependencies = [ "anyhow", "banderwagon", diff --git a/package-lock.json b/package-lock.json index bd45da0..a9b212e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "verkle-cryptography-wasm", - "version": "0.3.0", + "version": "0.3.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "verkle-cryptography-wasm", - "version": "0.3.0", + "version": "0.3.1", "license": "MIT/Apache", "dependencies": { "@scure/base": "^1.1.5" diff --git a/src.rs/Cargo.toml b/src.rs/Cargo.toml index 577e97d..be83c9b 100644 --- a/src.rs/Cargo.toml +++ b/src.rs/Cargo.toml @@ -15,11 +15,11 @@ default = ["console_error_panic_hook"] serde = { version = "1.0", features = ["derive"] } serde-wasm-bindgen = "0.3.0" wasm-bindgen = { version = "0.2.90", features = ["serde-serialize"] } -verkle-trie = { git = "https://github.com/crate-crypto/rust-verkle", rev = "6036bde9a8f416648213c59ad0c857b2a6f226f3" } -verkle-spec = { git = "https://github.com/crate-crypto/rust-verkle", rev = "6036bde9a8f416648213c59ad0c857b2a6f226f3" } -ipa-multipoint = { git = "https://github.com/crate-crypto/rust-verkle", rev = "6036bde9a8f416648213c59ad0c857b2a6f226f3" } -banderwagon = { git = "https://github.com/crate-crypto/rust-verkle", rev = "6036bde9a8f416648213c59ad0c857b2a6f226f3" } -ffi_interface = { git = "https://github.com/crate-crypto/rust-verkle", rev = "6036bde9a8f416648213c59ad0c857b2a6f226f3" } +verkle-trie = { git = "https://github.com/crate-crypto/rust-verkle", rev = "7688f0aedfb147d3d391abfe8495e46c46d72ce0" } +verkle-spec = { git = "https://github.com/crate-crypto/rust-verkle", rev = "7688f0aedfb147d3d391abfe8495e46c46d72ce0" } +ipa-multipoint = { git = "https://github.com/crate-crypto/rust-verkle", rev = "7688f0aedfb147d3d391abfe8495e46c46d72ce0" } +banderwagon = { git = "https://github.com/crate-crypto/rust-verkle", rev = "7688f0aedfb147d3d391abfe8495e46c46d72ce0" } +ffi_interface = { git = "https://github.com/crate-crypto/rust-verkle", rev = "7688f0aedfb147d3d391abfe8495e46c46d72ce0" } ark-ff = "0.4.0" ark-serialize = { version = "^0.4.0", default-features = false } diff --git a/src.rs/src/verkle_ffi_api.rs b/src.rs/src/verkle_ffi_api.rs index ab12f6d..79e84b5 100644 --- a/src.rs/src/verkle_ffi_api.rs +++ b/src.rs/src/verkle_ffi_api.rs @@ -34,8 +34,7 @@ impl Context { let address = js_value_to_bytes::<32>(address.into())?; let tree_index_le = js_value_to_bytes::<32>(tree_index_le.into())?; - let key = - ffi_interface::get_tree_key(&self.inner.committer, address, tree_index_le, sub_index); + let key = ffi_interface::get_tree_key(&self.inner, address, tree_index_le, sub_index); Ok(bytes_to_js_value(key).into()) } @@ -49,7 +48,7 @@ impl Context { scalars.extend(js_value_to_bytes::<32>(scalar.into())?); } - let commitment = ffi_interface::commit_to_scalars(&self.inner.committer, &scalars) + let commitment = ffi_interface::commit_to_scalars(&self.inner, &scalars) .map_err(|err| JsError::new(&format!("could not commit to scalars: {:?}", err)))?; Ok(bytes_to_js_value(commitment).into()) @@ -75,7 +74,7 @@ impl Context { scalars.extend([0u8; 16]); } - let commitment = ffi_interface::commit_to_scalars(&self.inner.committer, &scalars) + let commitment = ffi_interface::commit_to_scalars(&self.inner, &scalars) .map_err(|err| JsError::new(&format!("could not commit to scalars: {:?}", err)))?; Ok(bytes_to_js_value(commitment).into()) @@ -122,13 +121,17 @@ impl Context { /// /// This method does not return a scalar value, it returns 32 bytes. /// - /// Note: We plan to deprecate this method from the public API in favour of using hash commitment - /// This method will only be used internally once that is done. - #[wasm_bindgen(js_name = "deprecateSerializeCommitment")] + /// Note: This method is used to serialize the root node before placing it inside + /// of the block header. + /// The reason we use this method instead of `hashCommitment` is because + /// we want to be able to deserialize a commitment from the block header. + /// + /// This is not possible with `hashCommitment` as it is a one way function. + #[wasm_bindgen(js_name = "serializeCommitment")] pub fn serialize_commitment(&self, commitment: Uint8Array) -> Result { let commitment = js_value_to_bytes::<64>(commitment.into())?; - let hash = ffi_interface::deprecated_serialize_commitment(commitment); + let hash = ffi_interface::serialize_commitment(commitment); Ok(bytes_to_js_value(hash).into()) } @@ -158,7 +161,7 @@ impl Context { let new_scalar_value = js_value_to_bytes::<32>(new_scalar_value.into())?; let updated_commitment = ffi_interface::update_commitment( - &self.inner.committer, + &self.inner, commitment, commitment_index, old_scalar_value, diff --git a/src.ts/tests/ffi.spec.ts b/src.ts/tests/ffi.spec.ts index 8d44e97..2c75806 100644 --- a/src.ts/tests/ffi.spec.ts +++ b/src.ts/tests/ffi.spec.ts @@ -33,7 +33,7 @@ describe('bindings', () => { const key = ffi.getTreeKey(address, treeIndexLE, subIndex) const keyHex = bytesToHex(key) - const expected = '0x76a014d14e338c57342cda5187775c6b75e7f0ef292e81b176c7a5a700273700' + const expected = '0xff7e3916badeb510dfcdad458726273319280742e553d8d229bd676428147300' expect(keyHex).toBe(expected) }) @@ -55,7 +55,7 @@ describe('bindings', () => { const hash = verkleCrypto.getTreeKeyHash(address, treeIndexLE) const hashHex = bytesToHex(hash) - const expected = '0x76a014d14e338c57342cda5187775c6b75e7f0ef292e81b176c7a5a70027373a' + const expected = '0xff7e3916badeb510dfcdad458726273319280742e553d8d229bd676428147303' expect(hashHex).toBe(expected) }) @@ -144,7 +144,7 @@ describe('bindings', () => { ]) const commitment = ffi.commitToScalars([scalar]) - const commitmentHash = ffi.deprecateSerializeCommitment(commitment) + const commitmentHash = ffi.serializeCommitment(commitment) const commitmentHashHex = bytesToHex(commitmentHash) const expected = '0x6d40cf3d3097cb19b0ff686a068d53fb1250cc98bbd33766cf2cce00acb8b0a6' diff --git a/src.ts/verkleFFIBindings/verkleFFI.ts b/src.ts/verkleFFIBindings/verkleFFI.ts index ef6cbf8..04a4058 100644 --- a/src.ts/verkleFFIBindings/verkleFFI.ts +++ b/src.ts/verkleFFIBindings/verkleFFI.ts @@ -90,19 +90,9 @@ export function getTreeKeyHash( } // Commit to the chunks and compute a 32 byte value that we will denote as the hash - // - // Note: This 32 byte value is not a Scalar. It is just a 32 byte value. - // - // Note: that the .reverse() below is an implementation detail of the underlying - // Note: serialization code returning big endian. - // - // TODO: We want to eventually replace deprecateSerializeCommitment with `hashCommitment` - // TODO: This is a breaking change, so requires more coordination between different implementations - // TODO: once that is done, we can remove the .reverse and the deprecateSerializeCommitment method. - // const commitment = verkleFFI.commitTo16ByteScalars(chunks) - const serializedCommitment = verkleFFI.deprecateSerializeCommitment(commitment).reverse() - return serializedCommitment + const hash = verkleFFI.hashCommitment(commitment) + return hash } function concatenateUint8Arrays(array1: Uint8Array, array2: Uint8Array): Uint8Array {