Skip to content

Commit

Permalink
Failing less
Browse files Browse the repository at this point in the history
  • Loading branch information
citizen-stig committed Aug 22, 2023
1 parent bb10657 commit b3d4cd1
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 58 deletions.
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/demo-prover/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 46 additions & 42 deletions examples/demo-prover/methods/guest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/demo-stf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ sov-evm = { path = "../../module-system/module-implementations/sov-evm", optiona
[dev-dependencies]
sov-rollup-interface = { path = "../../rollup-interface", features = ["mocks"] }
sov-data-generators = { path = "../../module-system/utils/sov-data-generators" }
demo-stf = { path = ".", features = ["native"] }
tempfile = { workspace = true }
rand = "0.8"

Expand Down
7 changes: 4 additions & 3 deletions examples/demo-stf/src/sov-cli/native.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::File;
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::{fs, vec};
use std::vec;

use anyhow::Context;
use borsh::BorshSerialize;
Expand Down Expand Up @@ -136,9 +136,9 @@ impl PrivKeyAndAddress {
fn generate_and_save_to_file(priv_key_path: &Path) -> anyhow::Result<()> {
let priv_key = Self::generate();
let data = serde_json::to_string(&priv_key)?;
fs::create_dir_all(priv_key_path)?;
std::fs::create_dir_all(priv_key_path)?;
let path = Path::new(priv_key_path).join(format!("{}.json", priv_key.address));
fs::write(&path, data)?;
std::fs::write(&path, data)?;
println!(
"private key written to path: {}",
path.into_os_string().into_string().unwrap()
Expand Down Expand Up @@ -180,6 +180,7 @@ impl SerializedTx {

let sender_priv_key_data = serde_json::from_str::<PrivKeyAndAddress>(&priv_key_data)?;

println!("HA: {}", &sender_priv_key_data.hex_priv_key);
Ok(DefaultPrivateKey::from_hex(
&sender_priv_key_data.hex_priv_key,
)?)
Expand Down
1 change: 1 addition & 0 deletions module-system/sov-modules-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ risc0-zkvm-platform = { version = "0.16", optional = true }

[dev-dependencies]
bincode = { workspace = true }
sov-modules-api = { path = "../sov-modules-api", version = "0.1" }

[features]
bench = ["zk-cycle-macros", "risc0-zkvm", "risc0-zkvm-platform"]
Expand Down
19 changes: 8 additions & 11 deletions module-system/sov-modules-api/src/default_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSerialize};
use ed25519_dalek::ed25519::SignatureBytes;
//
use ed25519_dalek::{
Signature as DalekSignature, VerifyingKey as DalekPublicKey, PUBLIC_KEY_LENGTH,
};
Expand All @@ -12,8 +10,7 @@ use crate::{SigVerificationError, Signature};

#[cfg(feature = "native")]
pub mod private_key {

use ed25519_dalek::{SecretKey, Signer, SigningKey, SECRET_KEY_LENGTH};
use ed25519_dalek::{Signer, SigningKey, KEYPAIR_LENGTH};
use rand::rngs::OsRng;
use thiserror::Error;

Expand Down Expand Up @@ -48,15 +45,16 @@ pub mod private_key {
type Error = anyhow::Error;

fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
if value.len() != SECRET_KEY_LENGTH {
if value.len() != KEYPAIR_LENGTH {
anyhow::bail!(
"Invalid private key length: {}, expected {}",
value.len(),
SECRET_KEY_LENGTH
KEYPAIR_LENGTH
);
}
let secret_key: SecretKey = value.try_into()?;
let key_pair = SigningKey::from_bytes(&secret_key);
let reference = value.as_ptr() as *const [u8; KEYPAIR_LENGTH];
let value = unsafe { &*reference };
let key_pair = SigningKey::from_keypair_bytes(value)?;
Ok(Self { key_pair })
}
}
Expand Down Expand Up @@ -94,8 +92,7 @@ pub mod private_key {

pub fn from_hex(hex: &str) -> Result<Self, DefaultPrivateKeyHexDeserializationError> {
let bytes = hex::decode(hex)?;
Self::try_from(&bytes[..])
.map_err(DefaultPrivateKeyHexDeserializationError::PrivateKeyError)
Self::try_from(&bytes[..]).map_err(|e| e.into())
}

pub fn default_address(&self) -> Address {
Expand Down Expand Up @@ -208,7 +205,7 @@ impl FromStr for DefaultSignature {
fn from_str(s: &str) -> Result<Self, Self::Err> {
let bytes = hex::decode(s)?;

let bytes: SignatureBytes = bytes
let bytes: ed25519_dalek::ed25519::SignatureBytes = bytes
.try_into()
.map_err(|_| anyhow::anyhow!("Invalid signature"))?;

Expand Down

0 comments on commit b3d4cd1

Please sign in to comment.