Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error messages on ErgoTree evaluation #720

Merged
merged 74 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
2428e3e
make Evaluable::eval's environment a mutable ref;
greenhat Jul 17, 2023
0e819e9
add EvalError::WrappedWithEnvError with evaluation env attached;
greenhat Jul 18, 2023
65b129d
draft SourceSpan and SourceSpanWrapper;
greenhat Jul 19, 2023
35dd5ac
enrich Append eval error with source span;
greenhat Jul 21, 2023
a96a7c9
Move source_span module to the ergotree-ir crate root;
greenhat Jul 24, 2023
eda5e27
draft pretty printer types and smoke test;
greenhat Jul 24, 2023
8b3d624
draft Print trait IR nodes;
greenhat Jul 24, 2023
7a562f7
draft Printer trait tracking current position and indentation level;
greenhat Aug 1, 2023
7f28707
draft Print impl for Expr;
greenhat Aug 2, 2023
868076b
draft the expr printing and running eval again in reduce_to_crypto;
greenhat Aug 2, 2023
e46c92e
extract EvalError into a separate module;
greenhat Aug 3, 2023
e20f087
merge wrapped EvalError variants into one;
greenhat Aug 3, 2023
01cb82f
extract EvalErrorDetails and add wrap_with_src for EvalError;
greenhat Aug 3, 2023
c99f6ce
impl Print for BlockValue;
greenhat Aug 4, 2023
c10d084
formatting;
greenhat Aug 4, 2023
0eb274b
impl Print for ValDef and Constant;
greenhat Aug 7, 2023
8bb1181
impl Print for ValUse, fix indentations and new lines in pretty printer;
greenhat Aug 7, 2023
c6b94db
Rename Span to SourceSpan and switch it to offset+length based repres…
greenhat Aug 8, 2023
be311ac
impl Print for BinOp;
greenhat Aug 8, 2023
a948266
fix nested error wrapping, add division by zero eval test;
greenhat Aug 8, 2023
d353c71
fix spanned Expr construction in Print implementations;
greenhat Aug 8, 2023
e320143
rework wrapped EvalError variants, add custom Display impl for wrappe…
greenhat Sep 22, 2023
bf365dd
add source span test eval error;
greenhat Aug 9, 2023
9f8dfea
impl Print for GlobalVars;
greenhat Aug 11, 2023
e26d18e
impl pretty printing for ByIndex and add out of bounds error test;
greenhat Sep 22, 2023
955e751
add span check in pretty error tests;
greenhat Aug 15, 2023
a5e40f7
impl Display impl for Constant (primitive and composite types);
greenhat Aug 15, 2023
cf0efe3
Display impl for SType;
greenhat Aug 16, 2023
da54af0
implement Display for all Literal variants;
greenhat Aug 18, 2023
22ca326
set empty source span for IR nodes that can only fail at runtime due …
greenhat Aug 21, 2023
e355048
add details to error messages in EvalError variants;
greenhat Aug 21, 2023
8cf9c87
fix formatting;
greenhat Aug 21, 2023
922e2ad
update compiler tests expected results
greenhat Aug 21, 2023
54412d4
Wrap SubstConstants in Spanned;
greenhat Aug 22, 2023
c2747ad
Wrap ByteArrayToLong in Spanned;
greenhat Aug 22, 2023
ae4fd0f
Wrap ByteArrayToBigInt in Spanned;
greenhat Aug 22, 2023
afd73c6
wrap MethodCall in Spanned;
greenhat Aug 22, 2023
7ff21c0
wrap PropertyCall in Spanned;
greenhat Aug 22, 2023
47960ba
wrap Negation in Spanned
greenhat Aug 22, 2023
e9e24e1
wrap OptionGet in Spanned;
greenhat Aug 22, 2023
d8b4384
wrap OptionIsDefined in Spanned;
greenhat Aug 22, 2023
b0ef00f
wrap OptionGetOrElse in Spanned;
greenhat Aug 22, 2023
cc905f5
wrap ExtractRegisterAs in Spanned;
greenhat Aug 22, 2023
a2f2a6c
wrap Slice in Spanned;
greenhat Aug 22, 2023
984dbe6
wrap Fold in Spanned;
greenhat Aug 22, 2023
cbbc6d5
wrap Filter, Fold and ForAll in Spanned;
greenhat Aug 22, 2023
99489da
wrap SelectField in Spanned;
greenhat Aug 22, 2023
25c24f8
wrap SelectField and GetVar in Spanned;
greenhat Aug 22, 2023
dd6ac14
wrap Deserialize* into Spanned;
greenhat Aug 22, 2023
986fc41
wrap TreeLookup in Spanned;
greenhat Aug 22, 2023
1e282b6
fix expected formatting in pretty printer tests;
greenhat Aug 22, 2023
9eb85a1
fix formatting;
greenhat Aug 22, 2023
6bb6761
update expected source spans in binop pretty print test;
greenhat Aug 23, 2023
91e2a0f
skip ConstPlaceholder in pretty printer;
greenhat Aug 23, 2023
5b3873b
fix source span in expected pretty printer test;
greenhat Aug 23, 2023
824ed24
move Print trait and implementations into a separate module;
greenhat Sep 4, 2023
40301df
add EIP23 refresh contract as pretty printer test;
greenhat Sep 5, 2023
ec07000
add Print impl for various IR nodes and print EIP23 refresh contract;
greenhat Sep 6, 2023
b55a0b3
add EIP23 update contract as pretty printer test;
greenhat Sep 7, 2023
aa23f31
add EIP23 ballot contract as pretty printer test;
greenhat Sep 7, 2023
1456b1d
add EIP23 oracle contract as pretty printer test;
greenhat Sep 7, 2023
b81978c
add ageusd bank contract to pretty printer test
greenhat Sep 8, 2023
91c3cf4
add ageusd update contract to pretty printer test;
greenhat Sep 8, 2023
b1e4091
add eip14 amm pool and swap contracts to pretty printer tests;
greenhat Sep 11, 2023
4d09d26
add the rest of amm_conc_pool_* EIP22 auction contracts to the pretty…
greenhat Sep 13, 2023
d1b0e56
add doc comment;
greenhat Sep 13, 2023
0eefaef
pretty printer for ByteArrayTo* IR nodes;
greenhat Sep 14, 2023
7c99195
impl Print for LongToByteArray and CalcSha256;
greenhat Sep 19, 2023
1f7a246
implmennt pretty printing for And, Or, LogicalNot, Xor, SubstConstant…
greenhat Sep 20, 2023
b049864
fix build after rebase;
greenhat Sep 22, 2023
0bd29ad
implement pretty printing for BitInversion, OptionGetOrElse, Slice, F…
greenhat Sep 22, 2023
b6e6084
impl Print for DeserializeRegister and DeserializeContext
greenhat Sep 26, 2023
ee9b159
code formatting
greenhat Sep 27, 2023
3a62672
impl pretty printer for MultiplyGroup, Exponentiate, XorOf, TreeLooku…
greenhat Sep 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <denys@zadorozhnyi.com>"]
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
Loading