mirror of
https://github.com/logos-blockchain/logos-blockchain-circuits.git
synced 2026-07-03 07:30:14 +00:00
Use serde_json to corrupt inputs for tests, instead of using hardcoded values.
This commit is contained in:
parent
cc41762cb5
commit
5f506b01cd
57
rust/Cargo.lock
generated
57
rust/Cargo.lock
generated
@ -208,6 +208,7 @@ dependencies = [
|
||||
"logos-blockchain-circuits-build",
|
||||
"logos-blockchain-circuits-common",
|
||||
"logos-blockchain-circuits-types",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -217,6 +218,7 @@ dependencies = [
|
||||
"logos-blockchain-circuits-build",
|
||||
"logos-blockchain-circuits-common",
|
||||
"logos-blockchain-circuits-types",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -226,6 +228,7 @@ dependencies = [
|
||||
"logos-blockchain-circuits-build",
|
||||
"logos-blockchain-circuits-common",
|
||||
"logos-blockchain-circuits-types",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -253,6 +256,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.9"
|
||||
@ -387,6 +396,48 @@ dependencies = [
|
||||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.150"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
@ -612,3 +663,9 @@ name = "zeroize"
|
||||
version = "1.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
|
||||
|
||||
@ -36,6 +36,7 @@ dirs = "^6"
|
||||
fd-lock = "^4"
|
||||
flate2 = "^1.1"
|
||||
libc = "^0.2"
|
||||
serde_json = "^1"
|
||||
tar = "^0.4"
|
||||
ureq = "^3.3"
|
||||
bytes = "^1.11"
|
||||
|
||||
@ -19,5 +19,8 @@ workspace = true
|
||||
lbc-types = { workspace = true }
|
||||
lbc-common = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
lbc-build = { workspace = true }
|
||||
|
||||
@ -75,11 +75,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_generate_witness_constraint_violation_returns_err() {
|
||||
let json = std::fs::read_to_string(&*INPUTS).unwrap();
|
||||
let bad_json = json.replace(
|
||||
"\"voucher_root\": \"20810875415353676096192834577269613981524168537821543897016159330974871397924\"",
|
||||
"\"voucher_root\": \"1\"",
|
||||
);
|
||||
let input = PocWitnessInput::new(bad_json).unwrap();
|
||||
let mut inputs: serde_json::Value = serde_json::from_str(&json).unwrap();
|
||||
inputs["voucher_root"] = serde_json::json!("1");
|
||||
let input = PocWitnessInput::new(serde_json::to_string(&inputs).unwrap()).unwrap();
|
||||
assert!(generate_witness(&input).is_err());
|
||||
}
|
||||
|
||||
|
||||
@ -19,5 +19,8 @@ workspace = true
|
||||
lbc-types = { workspace = true }
|
||||
lbc-common = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
lbc-build = { workspace = true }
|
||||
|
||||
@ -75,11 +75,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_generate_witness_constraint_violation_returns_err() {
|
||||
let json = std::fs::read_to_string(&*INPUTS).unwrap();
|
||||
let bad_json = json.replace(
|
||||
"\"ledger_aged\": \"9907496234164738674719754286318998202143315407023653151112941050435603056651\"",
|
||||
"\"ledger_aged\": \"1\"",
|
||||
);
|
||||
let input = PolWitnessInput::new(bad_json).unwrap();
|
||||
let mut inputs: serde_json::Value = serde_json::from_str(&json).unwrap();
|
||||
inputs["ledger_aged"] = serde_json::json!("1");
|
||||
let input = PolWitnessInput::new(serde_json::to_string(&inputs).unwrap()).unwrap();
|
||||
assert!(generate_witness(&input).is_err());
|
||||
}
|
||||
|
||||
|
||||
@ -19,5 +19,8 @@ workspace = true
|
||||
lbc-types = { workspace = true }
|
||||
lbc-common = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
lbc-build = { workspace = true }
|
||||
|
||||
@ -75,13 +75,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_generate_witness_constraint_violation_returns_err() {
|
||||
let json = std::fs::read_to_string(&*INPUTS).unwrap();
|
||||
// Swap core_root for a wrong value; the Merkle path no longer verifies,
|
||||
// so is_registered.out = 0 and the constraint at circom line 108 fires.
|
||||
let bad_json = json.replace(
|
||||
"\"core_root\": \"20423847801203321296654759690878714805328777188198550442842378955293864405749\"",
|
||||
"\"core_root\": \"1\"",
|
||||
);
|
||||
let input = PoqWitnessInput::new(bad_json).unwrap();
|
||||
let mut inputs: serde_json::Value = serde_json::from_str(&json).unwrap();
|
||||
inputs["core_root"] = serde_json::json!("1");
|
||||
let input = PoqWitnessInput::new(serde_json::to_string(&inputs).unwrap()).unwrap();
|
||||
assert!(generate_witness(&input).is_err());
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user