Skip to content

Commit

Permalink
Merge pull request #720 from ergoplatform/i353-eval-error-trace
Browse files Browse the repository at this point in the history
Better error messages on ErgoTree evaluation
  • Loading branch information
greenhat authored Sep 27, 2023
2 parents 5e77f04 + 3a62672 commit 9ab86db
Show file tree
Hide file tree
Showing 101 changed files with 3,245 additions and 455 deletions.
14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ members = [
"bindings/ergo-lib-wasm",
"bindings/ergo-lib-c-core",
"bindings/ergo-lib-c",
"bindings/ergo-lib-jni"
"bindings/ergo-lib-jni",
]

[workspace.package]
Expand All @@ -37,7 +37,7 @@ ergo-merkle-tree = { version = "^0.11.1", path = "./ergo-merkle-tree" }
ergo-rest = { version = "^0.9.1", path = "./ergo-rest" }
ergo-lib = { version = "^0.24.1", path = "./ergo-lib"}
k256 = { version = "0.13.1", features = ["arithmetic", "ecdsa"] }
elliptic-curve = {version = "0.12", features = [ "ff"]}
elliptic-curve = { version = "0.12", features = ["ff"] }
thiserror = "1"
bounded-vec = { version = "^0.7.0" }
bitvec = { version = "1.0.1" }
Expand All @@ -52,9 +52,12 @@ lazy_static = "1.4"
bs58 = "0.4.0"
base16 = "0.2.1"
base64 = "0.13.0"
indexmap = {version ="1.3.2", features = ["serde"]}
indexmap = { version = "1.3.2", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["arbitrary_precision", "preserve_order"] }
serde_json = { version = "1.0", features = [
"arbitrary_precision",
"preserve_order",
] }
serde_with = { version = "1.9.1", features = ["json"] }
rand = "0.8.5"
bytes = "1.1"
Expand All @@ -67,13 +70,14 @@ bounded-integer = { version = "^0.5", features = ["types"] }
url = "2.2"
getrandom = { version = "0.2.7" }
itertools = "0.10.3"
miette = { version = "5", features = ["fancy"] }

# dev-dependencies
proptest = { version = "=1.0", default-features = false, features = ["std"] }
proptest-derive = "0.3"
pretty_assertions = "1.3"
wasm-bindgen-test = "0.3.37"
expect-test = "1.0.1"
expect-test = "1.4.1"

[profile.release]
# Tell `rustc` to optimize for small code size.
Expand Down
9 changes: 9 additions & 0 deletions ergo-chain-types/src/ec_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ impl std::fmt::Debug for EcPoint {
}
}

#[allow(clippy::unwrap_used)]
impl std::fmt::Display for EcPoint {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(&base16::encode_lower(
&self.scorex_serialize_bytes().unwrap(),
))
}
}

impl EcPoint {
/// Number of bytes to represent any group element as byte array
pub const GROUP_SIZE: usize = 33;
Expand Down
7 changes: 6 additions & 1 deletion ergo-lib/src/chain/transaction/reduced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ impl SigmaSerializable for ReducedTransaction {
let cost = r.get_u64()?;
let extension = input.spending_proof.extension;
let reduced_input = ReducedInput {
reduction_result: ReductionResult { sigma_prop, cost },
reduction_result: ReductionResult {
sigma_prop,
cost,
env: Env::empty(),
},
extension: extension.clone(),
};
let unsigned_input = UnsignedInput {
Expand Down Expand Up @@ -167,6 +171,7 @@ pub mod arbitrary {
reduction_result: ReductionResult {
sigma_prop: sb.clone(),
cost: 0,
env: Env::empty(),
},
extension: unsigned_input.extension,
}),
Expand Down
90 changes: 54 additions & 36 deletions ergoscript-compiler/src/mir/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,25 @@ mod tests {
check(
"HEIGHT + HEIGHT",
expect![[r#"
BinOp(
BinOp {
kind: Arith(
Plus,
),
left: GlobalVars(
Height,
),
right: GlobalVars(
Height,
),
},
)"#]],
BinOp(
Spanned {
source_span: SourceSpan {
offset: 0,
length: 0,
},
expr: BinOp {
kind: Arith(
Plus,
),
left: GlobalVars(
Height,
),
right: GlobalVars(
Height,
),
},
},
)"#]],
)
}

Expand Down Expand Up @@ -154,16 +160,22 @@ mod tests {
"4+2",
expect![[r#"
BinOp(
BinOp {
kind: Arith(
Plus,
),
left: Const(
"4: SInt",
),
right: Const(
"2: SInt",
),
Spanned {
source_span: SourceSpan {
offset: 0,
length: 0,
},
expr: BinOp {
kind: Arith(
Plus,
),
left: Const(
"4: SInt",
),
right: Const(
"2: SInt",
),
},
},
)"#]],
);
Expand All @@ -174,19 +186,25 @@ mod tests {
check(
"4L+2L",
expect![[r#"
BinOp(
BinOp {
kind: Arith(
Plus,
),
left: Const(
"4: SLong",
),
right: Const(
"2: SLong",
),
},
)"#]],
BinOp(
Spanned {
source_span: SourceSpan {
offset: 0,
length: 0,
},
expr: BinOp {
kind: Arith(
Plus,
),
left: Const(
"4: SLong",
),
right: Const(
"2: SLong",
),
},
},
)"#]],
);
}
}
19 changes: 12 additions & 7 deletions ergotree-interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ authors = ["Denys Zadorozhnyi <[email protected]>"]
repository.workspace = true
edition.workspace = true
description = "ErgoTree interpreter"
exclude = [
"proptest-regressions/*"
]
exclude = ["proptest-regressions/*"]

[lib]
crate-type = ["cdylib", "rlib"]
Expand All @@ -31,22 +29,29 @@ base16 = { workspace = true }
proptest-derive = { workspace = true, optional = true }
bytes = { workspace = true }
num-bigint = { workspace = true }
bounded-vec = { workspace = true, features=["serde"] }
bounded-vec = { workspace = true, features = ["serde"] }
serde = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }
serde_with = { workspace = true, optional = true }
proptest = { workspace = true , optional = true }
proptest = { workspace = true, optional = true }
scorex_crypto_avltree = "0.1.0"
gf2_192 = { version = "^0.24.1", path = "../gf2_192" }
miette = { workspace = true }

[features]
default = ["json"]
json = ["serde", "serde_json", "serde_with", "bounded-vec/serde"]
arbitrary = ["proptest", "proptest-derive", "ergotree-ir/arbitrary", "ergo-chain-types/arbitrary", "gf2_192/arbitrary"]
arbitrary = [
"proptest",
"proptest-derive",
"ergotree-ir/arbitrary",
"ergo-chain-types/arbitrary",
"gf2_192/arbitrary",
]

[dev-dependencies]
ergotree-ir = { workspace = true, features = ["arbitrary"] }
ergoscript-compiler = { workspace = true }
proptest = { workspace = true }
sigma-test-util = { workspace = true }

expect-test = { workspace = true }
26 changes: 15 additions & 11 deletions ergotree-interpreter/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,9 @@ mod tests {
let encoder = AddressEncoder::new(NetworkPrefix::Mainnet);
let addr = encoder.parse_address_from_str(p2s_addr_str).unwrap();
assert!(addr.script().unwrap().proposition().is_ok());
let _script = addr.script().unwrap().proposition().unwrap();
// let script = addr.script().unwrap().proposition().unwrap();
// dbg!(&script);
// let res: bool = eval_out_wo_ctx::<SigmaProp>(script.as_ref())
// .try_into()
// .unwrap();
// let res: bool = eval_out_wo_ctx::<SigmaProp>(&script).try_into().unwrap();
// assert!(!res);
}

Expand All @@ -227,12 +225,9 @@ mod tests {
let p2s_addr_str = "cLPHJ3MHuKAHoCUwGhcEFw5sWJqvPwFyKxTRj1aUoMwgAz78Fg3zLXRhBup9Te1WLau1gZXNmXvUmeXGCd7QLeqB7ArrT3v5cg26piEtqymM6j2SkgYVCobgoAGKeTf6nMLxv1uVrLdjt1GnPxG1MuWj7Es7Dfumotbx9YEaxwqtTUC5SKsJc9LCpAmNWRAQbU6tVVEvmfwWivrGoZ3L5C4DMisxN3U";
let encoder = AddressEncoder::new(NetworkPrefix::Mainnet);
let addr = encoder.parse_address_from_str(p2s_addr_str).unwrap();
let _script = addr.script().unwrap().proposition().unwrap();
// dbg!(&script);
// let res: bool = eval_out_wo_ctx::<SigmaProp>(script.as_ref())
// .try_into()
// .unwrap();
// assert!(!res);
let _ = addr.script().unwrap().proposition().unwrap();
// let ctx = Rc::new(force_any_val::<Context>());
// let _ = reduce_to_crypto(&script, &Env::empty(), ctx).unwrap();
}

#[test]
Expand Down Expand Up @@ -284,6 +279,15 @@ mod tests {

let encoder = AddressEncoder::new(NetworkPrefix::Mainnet);
let addr = encoder.parse_address_from_str(p2s_str).unwrap();
let _script = addr.script().unwrap().proposition().unwrap();
let _ = addr.script().unwrap().proposition().unwrap();
// let ctx = Rc::new(force_any_val::<Context>());
// let res = reduce_to_crypto(&script, &Env::empty(), ctx).unwrap();
// match res.sigma_prop {
// SigmaBoolean::TrivialProp(b) => assert!(b),
// SigmaBoolean::ProofOfKnowledge(_) => {
// todo!()
// }
// SigmaBoolean::SigmaConjecture(_) => todo!(),
// }
}
}
Loading

0 comments on commit 9ab86db

Please sign in to comment.