diff --git a/contrib/mir/Cargo.lock b/contrib/mir/Cargo.lock index 8efd202f581a78a660978b069c6d8b010efa9461..0adcdce1b6a58c102567cff35555c4aa9466bd6a 100644 --- a/contrib/mir/Cargo.lock +++ b/contrib/mir/Cargo.lock @@ -721,6 +721,8 @@ dependencies = [ "lalrpop", "lalrpop-util", "logos", + "num-bigint", + "num-traits", "tezos_crypto_rs", "tezos_data_encoding", "thiserror", diff --git a/contrib/mir/Cargo.toml b/contrib/mir/Cargo.toml index 7d4d25bfdb281cc2e571eeac3e48b938b41a2362..57bc45a3e2688514a9b09e4151a67ff23a43a10a 100644 --- a/contrib/mir/Cargo.toml +++ b/contrib/mir/Cargo.toml @@ -17,6 +17,8 @@ tezos_crypto_rs = "0.5" typed-arena = "2" base58="0.2" cryptoxide="0.4" +num-bigint="0.3" +num-traits="0.2" [[bin]] name = "tzt_runner" diff --git a/contrib/mir/src/ast.rs b/contrib/mir/src/ast.rs index 1698bca6556adc4c5dfe9957c68c5efb95e67ad0..18e8dd4875b1cbaeb95e8f165b5c5e66a9c7f4b4 100644 --- a/contrib/mir/src/ast.rs +++ b/contrib/mir/src/ast.rs @@ -18,6 +18,7 @@ pub mod or; pub mod overloads; pub use micheline::Micheline; +use num_bigint::{BigInt, BigUint}; use std::collections::{BTreeMap, BTreeSet}; pub use tezos_crypto_rs::hash::ChainId; use typed_arena::Arena; @@ -85,8 +86,8 @@ impl Type { pub fn size_for_gas(&self) -> usize { use Type::*; match self { - Nat | Int | Bool | Mutez | String | Unit | Never | Operation | Address | ChainId | Bytes - | Key | Signature | KeyHash => 1, + Nat | Int | Bool | Mutez | String | Unit | Never | Operation | Address | ChainId + | Bytes | Key | Signature | KeyHash => 1, Pair(p) | Or(p) | Map(p) => 1 + p.0.size_for_gas() + p.1.size_for_gas(), Option(x) | List(x) | Set(x) | Contract(x) => 1 + x.size_for_gas(), } @@ -123,8 +124,8 @@ impl Type { #[derive(Debug, Clone, Eq, PartialEq)] pub enum TypedValue { - Int(i128), - Nat(u128), + Int(BigInt), + Nat(BigUint), Mutez(i64), Bool(bool), String(String), @@ -231,6 +232,18 @@ impl TypedValue { counter: c, })) } + + /// Helper for more easily constructing `Int` variant with literals. Mostly + /// useful in tests. + pub fn int(n: impl Into) -> Self { + Self::Int(n.into()) + } + + /// Helper for more easily constructing `Nat` variant with literals. Mostly + /// useful in tests. + pub fn nat(n: u32) -> Self { + Self::Nat(n.into()) + } } #[derive(Debug, Eq, PartialEq, Clone)] diff --git a/contrib/mir/src/ast/comparable.rs b/contrib/mir/src/ast/comparable.rs index ab56bc0af778394c82560d77005f887da42a2dad..99a10a2acfc68cfcf5dc8dd7bf182809e1cfe2e2 100644 --- a/contrib/mir/src/ast/comparable.rs +++ b/contrib/mir/src/ast/comparable.rs @@ -81,13 +81,13 @@ mod tests { }; } - assert_cmp!(Int; -1; 0; Less); - assert_cmp!(Int; -1; -1; Equal); - assert_cmp!(Int; -1; -2; Greater); + assert_cmp!(V::int; -1; 0; Less); + assert_cmp!(V::int; -1; -1; Equal); + assert_cmp!(V::int; -1; -2; Greater); - assert_cmp!(Nat; 3; 4; Less); - assert_cmp!(Nat; 4; 4; Equal); - assert_cmp!(Nat; 5; 4; Greater); + assert_cmp!(V::nat; 3; 4; Less); + assert_cmp!(V::nat; 4; 4; Equal); + assert_cmp!(V::nat; 5; 4; Greater); assert_cmp!(Mutez; 3; 4; Less); assert_cmp!(Mutez; 3; 3; Equal); @@ -105,31 +105,31 @@ mod tests { assert_cmp!(String; "foo".to_owned(); "bar".to_owned(); Greater); assert_cmp!(V::new_option; None; None; Equal); - assert_cmp!(V::new_option; None; Some(Int(3)); Less); - assert_cmp!(V::new_option; Some(Int(3)); None; Greater); - assert_cmp!(V::new_option; Some(Int(3)); Some(Int(4)); Less); - assert_cmp!(V::new_option; Some(Int(4)); Some(Int(4)); Equal); - assert_cmp!(V::new_option; Some(Int(4)); Some(Int(3)); Greater); - - assert_cmp!(V::new_pair; Int(3), Nat(4); Int(3), Nat(5); Less); - assert_cmp!(V::new_pair; Int(3), Nat(4); Int(4), Nat(4); Less); - assert_cmp!(V::new_pair; Int(3), Nat(4); Int(3), Nat(4); Equal); - assert_cmp!(V::new_pair; Int(4), Nat(4); Int(3), Nat(4); Greater); - assert_cmp!(V::new_pair; Int(3), Nat(5); Int(3), Nat(4); Greater); + assert_cmp!(V::new_option; None; Some(V::int(3)); Less); + assert_cmp!(V::new_option; Some(V::int(3)); None; Greater); + assert_cmp!(V::new_option; Some(V::int(3)); Some(V::int(4)); Less); + assert_cmp!(V::new_option; Some(V::int(4)); Some(V::int(4)); Equal); + assert_cmp!(V::new_option; Some(V::int(4)); Some(V::int(3)); Greater); + + assert_cmp!(V::new_pair; V::int(3), V::nat(4); V::int(3), V::nat(5); Less); + assert_cmp!(V::new_pair; V::int(3), V::nat(4); V::int(4), V::nat(4); Less); + assert_cmp!(V::new_pair; V::int(3), V::nat(4); V::int(3), V::nat(4); Equal); + assert_cmp!(V::new_pair; V::int(4), V::nat(4); V::int(3), V::nat(4); Greater); + assert_cmp!(V::new_pair; V::int(3), V::nat(5); V::int(3), V::nat(4); Greater); use crate::ast::Or; - assert_cmp!(V::new_or; Or::Left(Int(3)); Or::Left(Int(4)); Less); - assert_cmp!(V::new_or; Or::Left(Int(5)); Or::Left(Int(4)); Greater); - assert_cmp!(V::new_or; Or::Left(Int(4)); Or::Left(Int(4)); Equal); - assert_cmp!(V::new_or; Or::Right(Int(3)); Or::Right(Int(4)); Less); - assert_cmp!(V::new_or; Or::Right(Int(5)); Or::Right(Int(4)); Greater); - assert_cmp!(V::new_or; Or::Right(Int(4)); Or::Right(Int(4)); Equal); - assert_cmp!(V::new_or; Or::Left(Int(5)); Or::Right(Int(3)); Less); - assert_cmp!(V::new_or; Or::Right(Int(3)); Or::Left(Int(5)); Greater); + assert_cmp!(V::new_or; Or::Left(V::int(3)); Or::Left(V::int(4)); Less); + assert_cmp!(V::new_or; Or::Left(V::int(5)); Or::Left(V::int(4)); Greater); + assert_cmp!(V::new_or; Or::Left(V::int(4)); Or::Left(V::int(4)); Equal); + assert_cmp!(V::new_or; Or::Right(V::int(3)); Or::Right(V::int(4)); Less); + assert_cmp!(V::new_or; Or::Right(V::int(5)); Or::Right(V::int(4)); Greater); + assert_cmp!(V::new_or; Or::Right(V::int(4)); Or::Right(V::int(4)); Equal); + assert_cmp!(V::new_or; Or::Left(V::int(5)); Or::Right(V::int(3)); Less); + assert_cmp!(V::new_or; Or::Right(V::int(3)); Or::Left(V::int(5)); Greater); // different types don't compare - assert_eq!(Bool(true).partial_cmp(&Int(5)), None); + assert_eq!(Bool(true).partial_cmp(&V::int(5)), None); } #[test] @@ -199,8 +199,9 @@ mod tests { #[should_panic(expected = "Comparing incomparable values in TypedValue")] fn compare_different_comparable() { // Comparable panics on different types + use TypedValue as V; use TypedValue::*; - let _ = Bool(true).cmp(&Int(5)); //panics + let _ = Bool(true).cmp(&V::int(5)); //panics } } diff --git a/contrib/mir/src/ast/micheline.rs b/contrib/mir/src/ast/micheline.rs index 69afea907241dba5f556b166802e5011da1a6a2b..d35e9311315cff17b529b0ee497768bf802e5085 100644 --- a/contrib/mir/src/ast/micheline.rs +++ b/contrib/mir/src/ast/micheline.rs @@ -5,6 +5,7 @@ /* */ /******************************************************************************/ +use num_bigint::{BigInt, BigUint}; use typed_arena::Arena; use super::annotations::{Annotations, NO_ANNS}; @@ -12,7 +13,7 @@ use crate::lexer::Prim; #[derive(Debug, Clone, Eq, PartialEq)] pub enum Micheline<'a> { - Int(i128), + Int(BigInt), String(String), Bytes(Vec), /// Application of a Micheline primitive to some arguments with optional @@ -43,10 +44,22 @@ impl<'a> Micheline<'a> { impl<'a> From for Micheline<'a> { fn from(x: i128) -> Self { + Micheline::Int(x.into()) + } +} + +impl<'a> From for Micheline<'a> { + fn from(x: BigInt) -> Self { Micheline::Int(x) } } +impl<'a> From for Micheline<'a> { + fn from(x: BigUint) -> Self { + Micheline::Int(x.into()) + } +} + impl<'a> From for Micheline<'a> { fn from(x: String) -> Self { Micheline::String(x) @@ -312,14 +325,14 @@ pub mod test_helpers { assert_eq!(app!(True), Micheline::App(Prim::True, &[], NO_ANNS)); assert_eq!( app!(DUP[3]), - Micheline::App(Prim::DUP, &[Micheline::Int(3)], NO_ANNS) + Micheline::App(Prim::DUP, &[Micheline::Int(3.into())], NO_ANNS) ); assert_eq!( app!(DIP[3, seq!{ app!(DROP) }]), Micheline::App( Prim::DIP, &[ - Micheline::Int(3), + Micheline::Int(3.into()), Micheline::Seq(&[Micheline::App(Prim::DROP, &[], NO_ANNS)]) ], NO_ANNS diff --git a/contrib/mir/src/gas.rs b/contrib/mir/src/gas.rs index ee8adf94144b1eae153b99ea8f2ca3c55992c35a..a73afdaed70cfdfc0f1445e500ac0c5d3ae63b3a 100644 --- a/contrib/mir/src/gas.rs +++ b/contrib/mir/src/gas.rs @@ -5,6 +5,8 @@ /* */ /******************************************************************************/ +use num_bigint::{BigInt, BigUint}; + #[derive(Debug)] pub struct Gas { milligas_amount: Option, @@ -64,6 +66,12 @@ impl AsGasCost for checked::Checked { } } +impl AsGasCost for checked::Checked { + fn as_gas_cost(&self) -> Result { + self.ok_or(OutOfGas)?.try_into().map_err(|_| OutOfGas) + } +} + /// A hack to get the integral logarithm base 2, rounded up. /// Rounds up to the nearest power of 2 and counts trailing zeroes. Thus, /// @@ -166,10 +174,32 @@ pub mod tc_cost { } } +pub trait BigIntByteSize { + /// Minimal size in bytes a given bigint is representable in. + fn byte_size(&self) -> u64; +} + +/// Bit size divided by 8, rounded up +fn bits_to_bytes(bits: u64) -> u64 { + (bits + 7) >> 3 +} + +impl BigIntByteSize for BigInt { + fn byte_size(&self) -> u64 { + bits_to_bytes(self.bits()) + } +} + +impl BigIntByteSize for BigUint { + fn byte_size(&self) -> u64 { + bits_to_bytes(self.bits()) + } +} + pub mod interpret_cost { use checked::Checked; - use super::{AsGasCost, OutOfGas}; + use super::{AsGasCost, BigIntByteSize, OutOfGas}; use crate::ast::{Key, KeyHash, Micheline, Or, TypedValue}; pub const DIP: u32 = 10; @@ -253,18 +283,16 @@ pub mod interpret_cost { mb_n.map_or(Ok(DUP), dupn) } - pub fn add_int(i1: T, i2: T) -> Result { - // NB: eventually when using BigInts, use BigInt::bits() &c - use std::mem::size_of_val; + pub fn add_int(i1: &impl BigIntByteSize, i2: &impl BigIntByteSize) -> Result { // max is copied from the Tezos protocol, ostensibly adding two big ints depends on // the larger of the two due to result allocation - let sz = Checked::from(std::cmp::max(size_of_val(&i1), size_of_val(&i2))); + let sz = Checked::from(std::cmp::max(i1.byte_size(), i2.byte_size())); (35 + (sz >> 1)).as_gas_cost() } pub fn compare(v1: &TypedValue, v2: &TypedValue) -> Result { use TypedValue as V; - let cmp_bytes = |s1: usize, s2: usize| { + let cmp_bytes = |s1: u64, s2: u64| { // Approximating 35 + 0.024413 x term let v = Checked::from(std::cmp::min(s1, s2)); (35 + (v >> 6) + (v >> 7)).as_gas_cost() @@ -274,7 +302,7 @@ pub mod interpret_cost { (c + compare(&l.0, &r.0)? + compare(&l.1, &r.1)?).as_gas_cost() }; let cmp_option = Checked::from(10u32); - const ADDRESS_SIZE: usize = 20 + 31; // hash size + max entrypoint size + const ADDRESS_SIZE: u64 = 20 + 31; // hash size + max entrypoint size const CMP_CHAIN_ID: u32 = 30; const CMP_KEY: u32 = 92; // hard-coded in the protocol const CMP_SIGNATURE: u32 = 92; // hard-coded in the protocol @@ -284,16 +312,10 @@ pub mod interpret_cost { unreachable!("Comparison of incomparable values") } Ok(match (v1, v2) { - (V::Nat(l), V::Nat(r)) => { - // NB: eventually when using BigInts, use BigInt::bits() &c - cmp_bytes(std::mem::size_of_val(l), std::mem::size_of_val(r))? - } + (V::Nat(l), V::Nat(r)) => cmp_bytes(l.byte_size(), r.byte_size())?, (V::Nat(_), _) => incomparable(), - (V::Int(l), V::Int(r)) => { - // NB: eventually when using BigInts, use BigInt::bits() &c - cmp_bytes(std::mem::size_of_val(l), std::mem::size_of_val(r))? - } + (V::Int(l), V::Int(r)) => cmp_bytes(l.byte_size(), r.byte_size())?, (V::Int(_), _) => incomparable(), (V::Bool(_), V::Bool(_)) => cmp_bytes(1, 1)?, @@ -302,7 +324,7 @@ pub mod interpret_cost { (V::Mutez(_), V::Mutez(_)) => cmp_bytes(8, 8)?, (V::Mutez(_), _) => incomparable(), - (V::String(l), V::String(r)) => cmp_bytes(l.len(), r.len())?, + (V::String(l), V::String(r)) => cmp_bytes(l.len() as u64, r.len() as u64)?, (V::String(_), _) => incomparable(), (V::Unit, V::Unit) => 10, @@ -326,7 +348,7 @@ pub mod interpret_cost { (V::ChainId(..), V::ChainId(..)) => CMP_CHAIN_ID, (V::ChainId(_), _) => incomparable(), - (V::Bytes(l), V::Bytes(r)) => cmp_bytes(l.len(), r.len())?, + (V::Bytes(l), V::Bytes(r)) => cmp_bytes(l.len() as u64, r.len() as u64)?, (V::Bytes(_), _) => incomparable(), (V::Key(_), V::Key(_)) => CMP_KEY, @@ -335,7 +357,9 @@ pub mod interpret_cost { (V::Signature(_), V::Signature(_)) => CMP_SIGNATURE, (V::Signature(_), _) => incomparable(), - (V::KeyHash(_), V::KeyHash(_)) => cmp_bytes(KeyHash::BYTE_SIZE, KeyHash::BYTE_SIZE)?, + (V::KeyHash(_), V::KeyHash(_)) => { + cmp_bytes(KeyHash::BYTE_SIZE as u64, KeyHash::BYTE_SIZE as u64)? + } (V::KeyHash(_), _) => incomparable(), (V::Or(l), V::Or(r)) => match (l.as_ref(), r.as_ref()) { @@ -406,13 +430,13 @@ pub mod interpret_cost { /// Measures size of Michelson using several metrics. pub struct MichelineSize { /// Total number of nodes (including leaves). - nodes_num: Checked, + nodes_num: Checked, /// Total size of string and bytes literals. - str_byte: Checked, + str_byte: Checked, /// Total size of zarith numbers, in bytes. - zariths: Checked, + zariths: Checked, } impl Default for MichelineSize { @@ -438,14 +462,9 @@ pub mod interpret_cost { fn collect_micheline_size<'a>(mich: &'a Micheline<'a>, size: &mut MichelineSize) { size.nodes_num += 1; match mich { - Micheline::String(s) => size.str_byte += s.len(), - Micheline::Bytes(bs) => size.str_byte += bs.len(), - Micheline::Int(i) => { - // NB: eventually when using BigInts, use BigInt::bits() &c - let bits = std::mem::size_of_val(i); - let bytes = (bits + 7) / 8; - size.zariths += bytes; - } + Micheline::String(s) => size.str_byte += s.len() as u64, + Micheline::Bytes(bs) => size.str_byte += bs.len() as u64, + Micheline::Int(i) => size.zariths += i.byte_size(), Micheline::Seq(ms) => { for m in *ms { collect_micheline_size(m, size) @@ -464,7 +483,7 @@ pub mod interpret_cost { Ann::Variable(a) => a.len() + 1, Ann::Type(a) => a.len() + 1, Ann::Special(a) => a.len(), - } + } as u64 } } } diff --git a/contrib/mir/src/interpreter.rs b/contrib/mir/src/interpreter.rs index d728e6c3db9fe1d834761ee52d58242da3bd2d2f..f180da66d08ac4eb92f1dc1b9dfebb4b013deb02 100644 --- a/contrib/mir/src/interpreter.rs +++ b/contrib/mir/src/interpreter.rs @@ -5,6 +5,8 @@ /* */ /******************************************************************************/ +use num_bigint::{BigInt, BigUint}; +use num_traits::{Signed, Zero}; use typed_arena::Arena; use crate::ast::annotations::NO_ANNS; @@ -55,7 +57,7 @@ impl ContractScript { V::Pair(p) => match *p { (V::List(vec), storage) => Ok(( vec.into_iter() - .map(|x| (*irrefutable_match!(x; TypedValue::Operation))), + .map(|x| (*irrefutable_match!(x; V::Operation))), storage, )), (v, _) => panic!("expected `list operation`, got {:?}", v), @@ -128,33 +130,29 @@ fn interpret_one(i: &Instruction, ctx: &mut Ctx, stack: &mut IStack) -> Result<( overloads::Add::IntInt => { let o1 = pop!(V::Int); let o2 = pop!(V::Int); - ctx.gas.consume(interpret_cost::add_int(o1, o2)?)?; + ctx.gas.consume(interpret_cost::add_int(&o1, &o2)?)?; let sum = o1 + o2; stack.push(V::Int(sum)); } overloads::Add::NatNat => { let o1 = pop!(V::Nat); let o2 = pop!(V::Nat); - ctx.gas.consume(interpret_cost::add_int(o1, o2)?)?; + ctx.gas.consume(interpret_cost::add_int(&o1, &o2)?)?; let sum = o1 + o2; stack.push(V::Nat(sum)); } overloads::Add::IntNat => { let o1 = pop!(V::Int); - // this potentially overflows on i128, but can't overflow on - // bigints, unwrap for now - let o2 = pop!(V::Nat).try_into().unwrap(); - ctx.gas.consume(interpret_cost::add_int(o1, o2)?)?; - let sum = o1 + o2; + let o2 = pop!(V::Nat); + ctx.gas.consume(interpret_cost::add_int(&o1, &o2)?)?; + let sum = o1 + BigInt::from(o2); stack.push(V::Int(sum)); } overloads::Add::NatInt => { - // this potentially overflows on i128, but can't overflow on - // bigints, unwrap for now - let o1 = pop!(V::Nat).try_into().unwrap(); + let o1 = pop!(V::Nat); let o2 = pop!(V::Int); - ctx.gas.consume(interpret_cost::add_int(o1, o2)?)?; - let sum = o1 + o2; + ctx.gas.consume(interpret_cost::add_int(&o1, &o2)?)?; + let sum = BigInt::from(o1) + o2; stack.push(V::Int(sum)); } overloads::Add::MutezMutez => { @@ -186,17 +184,17 @@ fn interpret_one(i: &Instruction, ctx: &mut Ctx, stack: &mut IStack) -> Result<( I::Gt => { ctx.gas.consume(interpret_cost::GT)?; let i = pop!(V::Int); - stack.push(V::Bool(i > 0)); + stack.push(V::Bool(i.is_positive())); } I::Eq => { ctx.gas.consume(interpret_cost::EQ)?; let i = pop!(V::Int); - stack.push(V::Bool(i == 0)); + stack.push(V::Bool(i.is_zero())); } I::Le => { ctx.gas.consume(interpret_cost::LE)?; let i = pop!(V::Int); - stack.push(V::Bool(i <= 0)); + stack.push(V::Bool(!i.is_positive())); } I::If(nested_t, nested_f) => { ctx.gas.consume(interpret_cost::IF)?; @@ -247,7 +245,7 @@ fn interpret_one(i: &Instruction, ctx: &mut Ctx, stack: &mut IStack) -> Result<( I::Int => { let i = pop!(V::Nat); ctx.gas.consume(interpret_cost::INT_NAT)?; - stack.push(V::Int(i.try_into().unwrap())); + stack.push(V::Int(i.into())); } I::Loop(nested) => { ctx.gas.consume(interpret_cost::LOOP_ENTER)?; @@ -454,7 +452,7 @@ fn interpret_one(i: &Instruction, ctx: &mut Ctx, stack: &mut IStack) -> Result<( let contract_address = pop!(V::Contract); let counter = ctx.operation_counter(); ctx.gas.consume(interpret_cost::TRANSFER_TOKENS)?; - stack.push(TypedValue::new_operation( + stack.push(V::new_operation( Operation::TransferTokens(TransferTokens { param, amount: mutez_amount, @@ -467,7 +465,7 @@ fn interpret_one(i: &Instruction, ctx: &mut Ctx, stack: &mut IStack) -> Result<( let opt_keyhash = pop!(V::Option).map(|kh| irrefutable_match!(*kh; V::KeyHash)); let counter: u128 = ctx.operation_counter(); ctx.gas.consume(interpret_cost::SET_DELEGATE)?; - stack.push(TypedValue::new_operation( + stack.push(V::new_operation( Operation::SetDelegate(SetDelegate(opt_keyhash)), counter, )) @@ -479,8 +477,8 @@ fn interpret_one(i: &Instruction, ctx: &mut Ctx, stack: &mut IStack) -> Result<( } I::Slice(overload) => { fn validate_bounds( - offset: u128, - length: u128, + offset: BigUint, + length: BigUint, actual_length: usize, ) -> Option> { // If `offset` or `offset + length` are greater than `usize::MAX`, `SLICE` will return `None`. @@ -550,8 +548,8 @@ mod interpreter_tests { #[test] fn test_add() { - let mut stack = stk![V::Nat(10), V::Nat(20)]; - let expected_stack = stk![V::Nat(30)]; + let mut stack = stk![V::nat(10), V::nat(20)]; + let expected_stack = stk![V::nat(30)]; let mut ctx = Ctx::default(); assert!(interpret_one(&Add(overloads::Add::NatNat), &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); @@ -598,8 +596,8 @@ mod interpreter_tests { #[test] fn test_dip() { - let mut stack = stk![V::Nat(20), V::Nat(5), V::Nat(10)]; - let expected_stack = stk![V::Nat(25), V::Nat(10)]; + let mut stack = stk![V::nat(20), V::nat(5), V::nat(10)]; + let expected_stack = stk![V::nat(25), V::nat(10)]; let mut ctx = Ctx::default(); assert!(interpret_one( &Dip(None, vec![Add(overloads::Add::NatNat)]), @@ -612,8 +610,8 @@ mod interpreter_tests { #[test] fn test_dip2() { - let mut stack = stk![V::Nat(20), V::Nat(5), V::Nat(10)]; - let expected_stack = stk![V::Nat(5), V::Nat(10)]; + let mut stack = stk![V::nat(20), V::nat(5), V::nat(10)]; + let expected_stack = stk![V::nat(5), V::nat(10)]; let mut ctx = Ctx::default(); assert!(interpret_one(&Dip(Some(2), vec![Drop(None)]), &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); @@ -621,8 +619,8 @@ mod interpreter_tests { #[test] fn test_drop() { - let mut stack = stk![V::Nat(20), V::Nat(5), V::Nat(10)]; - let expected_stack = stk![V::Nat(20), V::Nat(5)]; + let mut stack = stk![V::nat(20), V::nat(5), V::nat(10)]; + let expected_stack = stk![V::nat(20), V::nat(5)]; let mut ctx = Ctx::default(); assert!(interpret_one(&Drop(None), &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); @@ -630,8 +628,8 @@ mod interpreter_tests { #[test] fn test_drop2() { - let mut stack = stk![V::Nat(20), V::Nat(5), V::Nat(10)]; - let expected_stack = stk![V::Nat(20)]; + let mut stack = stk![V::nat(20), V::nat(5), V::nat(10)]; + let expected_stack = stk![V::nat(20)]; let mut ctx = Ctx::default(); assert!(interpret_one(&Drop(Some(2)), &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); @@ -639,8 +637,8 @@ mod interpreter_tests { #[test] fn test_dup() { - let mut stack = stk![V::Nat(20), V::Nat(5), V::Nat(10)]; - let expected_stack = stk![V::Nat(20), V::Nat(5), V::Nat(10), V::Nat(10)]; + let mut stack = stk![V::nat(20), V::nat(5), V::nat(10)]; + let expected_stack = stk![V::nat(20), V::nat(5), V::nat(10), V::nat(10)]; let mut ctx = Ctx::default(); assert!(interpret_one(&Dup(None), &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); @@ -648,8 +646,8 @@ mod interpreter_tests { #[test] fn test_dup2() { - let mut stack = stk![V::Nat(20), V::Nat(5), V::Nat(10)]; - let expected_stack = stk![V::Nat(20), V::Nat(5), V::Nat(10), V::Nat(5)]; + let mut stack = stk![V::nat(20), V::nat(5), V::nat(10)]; + let expected_stack = stk![V::nat(20), V::nat(5), V::nat(10), V::nat(5)]; let mut ctx = Ctx::default(); assert!(interpret_one(&Dup(Some(2)), &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); @@ -657,8 +655,8 @@ mod interpreter_tests { #[test] fn test_gt() { - let mut stack = stk![V::Int(20), V::Int(10)]; - let expected_stack = stk![V::Int(20), V::Bool(true)]; + let mut stack = stk![V::int(20), V::int(10)]; + let expected_stack = stk![V::int(20), V::Bool(true)]; let mut ctx = Ctx::default(); assert!(interpret_one(&Gt, &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); @@ -666,8 +664,8 @@ mod interpreter_tests { #[test] fn test_gt_false() { - let mut stack = stk![V::Int(20), V::Int(-10)]; - let expected_stack = stk![V::Int(20), V::Bool(false)]; + let mut stack = stk![V::int(20), V::int(-10)]; + let expected_stack = stk![V::int(20), V::Bool(false)]; let mut ctx = Ctx::default(); assert!(interpret_one(&Gt, &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); @@ -675,8 +673,8 @@ mod interpreter_tests { #[test] fn test_eq() { - let mut stack = stk![V::Int(20), V::Int(0)]; - let expected_stack = stk![V::Int(20), V::Bool(true)]; + let mut stack = stk![V::int(20), V::int(0)]; + let expected_stack = stk![V::int(20), V::Bool(true)]; let mut ctx = Ctx::default(); assert!(interpret_one(&Eq, &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); @@ -684,8 +682,8 @@ mod interpreter_tests { #[test] fn test_eq_false() { - let mut stack = stk![V::Int(20), V::Int(1)]; - let expected_stack = stk![V::Int(20), V::Bool(false)]; + let mut stack = stk![V::int(20), V::int(1)]; + let expected_stack = stk![V::int(20), V::Bool(false)]; let mut ctx = Ctx::default(); assert!(interpret_one(&Eq, &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); @@ -693,8 +691,8 @@ mod interpreter_tests { #[test] fn test_le() { - let mut stack = stk![V::Int(20), V::Int(-1)]; - let expected_stack = stk![V::Int(20), V::Bool(true)]; + let mut stack = stk![V::int(20), V::int(-1)]; + let expected_stack = stk![V::int(20), V::Bool(true)]; let mut ctx = Ctx::default(); assert!(interpret_one(&Le, &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); @@ -702,8 +700,8 @@ mod interpreter_tests { #[test] fn test_le_false() { - let mut stack = stk![V::Int(20), V::Int(1)]; - let expected_stack = stk![V::Int(20), V::Bool(false)]; + let mut stack = stk![V::int(20), V::int(1)]; + let expected_stack = stk![V::int(20), V::Bool(false)]; let mut ctx = Ctx::default(); assert!(interpret_one(&Le, &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); @@ -711,8 +709,8 @@ mod interpreter_tests { #[test] fn test_if_t() { - let mut stack = stk![V::Int(20), V::Int(5), V::Bool(true)]; - let expected_stack = stk![V::Int(20)]; + let mut stack = stk![V::int(20), V::int(5), V::Bool(true)]; + let expected_stack = stk![V::int(20)]; let mut ctx = Ctx::default(); assert!(interpret_one( &If(vec![Drop(None)], vec![Add(overloads::Add::IntInt)]), @@ -725,8 +723,8 @@ mod interpreter_tests { #[test] fn test_if_f() { - let mut stack = stk![V::Int(20), V::Int(5), V::Bool(false)]; - let expected_stack = stk![V::Int(25)]; + let mut stack = stk![V::int(20), V::int(5), V::Bool(false)]; + let expected_stack = stk![V::int(25)]; let mut ctx = Ctx::default(); assert!(interpret_one( &If(vec![Drop(None)], vec![Add(overloads::Add::IntInt)]), @@ -739,8 +737,8 @@ mod interpreter_tests { #[test] fn test_int() { - let mut stack = stk![V::Nat(20), V::Nat(10)]; - let expected_stack = stk![V::Nat(20), V::Int(10)]; + let mut stack = stk![V::nat(20), V::nat(10)]; + let expected_stack = stk![V::nat(20), V::int(10)]; let mut ctx = Ctx::default(); assert!(interpret_one(&Int, &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); @@ -748,21 +746,21 @@ mod interpreter_tests { #[test] fn test_push() { - let mut stack = stk![V::Nat(20), V::Nat(10)]; - let expected_stack = stk![V::Nat(20), V::Nat(10), V::Nat(0)]; + let mut stack = stk![V::nat(20), V::nat(10)]; + let expected_stack = stk![V::nat(20), V::nat(10), V::nat(0)]; let mut ctx = Ctx::default(); - assert!(interpret_one(&Push(V::Nat(0)), &mut ctx, &mut stack).is_ok()); + assert!(interpret_one(&Push(V::nat(0)), &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); } #[test] fn test_loop_0() { - let mut stack = stk![V::Nat(20), V::Nat(10), V::Bool(false)]; - let expected_stack = stk![V::Nat(20), V::Nat(10)]; + let mut stack = stk![V::nat(20), V::nat(10), V::Bool(false)]; + let expected_stack = stk![V::nat(20), V::nat(10)]; let mut ctx = Ctx::default(); assert!(interpret_one( &Loop(vec![ - Push(V::Nat(1)), + Push(V::nat(1)), Add(overloads::Add::NatNat), Push(V::Bool(false)) ]), @@ -775,12 +773,12 @@ mod interpreter_tests { #[test] fn test_loop_1() { - let mut stack = stk![V::Nat(20), V::Nat(10), V::Bool(true)]; - let expected_stack = stk![V::Nat(20), V::Nat(11)]; + let mut stack = stk![V::nat(20), V::nat(10), V::Bool(true)]; + let expected_stack = stk![V::nat(20), V::nat(11)]; let mut ctx = Ctx::default(); assert!(interpret_one( &Loop(vec![ - Push(V::Nat(1)), + Push(V::nat(1)), Add(overloads::Add::NatNat), Push(V::Bool(false)) ]), @@ -793,12 +791,12 @@ mod interpreter_tests { #[test] fn test_loop_many() { - let mut stack = stk![V::Nat(20), V::Int(10), V::Bool(true)]; - let expected_stack = stk![V::Nat(20), V::Int(0)]; + let mut stack = stk![V::nat(20), V::int(10), V::Bool(true)]; + let expected_stack = stk![V::nat(20), V::int(0)]; let mut ctx = Ctx::default(); assert!(interpret_one( &Loop(vec![ - Push(V::Int(-1)), + Push(V::int(-1)), Add(overloads::Add::IntInt), Dup(None), Gt @@ -814,7 +812,7 @@ mod interpreter_tests { fn test_iter_list_many() { let mut stack = stk![ V::List(vec![].into()), - V::List((1..5).map(V::Int).collect()) + V::List((1..5).map(V::int).collect()) ]; assert!(interpret_one( &Iter(overloads::Iter::List, vec![Cons]), @@ -824,7 +822,7 @@ mod interpreter_tests { .is_ok()); // NB: walking a list start-to-end and CONSing each element effectively // reverses the list. - assert_eq!(stack, stk![V::List((1..5).rev().map(V::Int).collect())]); + assert_eq!(stack, stk![V::List((1..5).rev().map(V::int).collect())]); } #[test] @@ -844,7 +842,7 @@ mod interpreter_tests { let mut stack = stk![ V::List(vec![].into()), V::Set( - vec![(V::Int(1)), (V::Int(2)), (V::Int(3)),] + vec![(V::int(1)), (V::int(2)), (V::int(3)),] .into_iter() .collect() ) @@ -861,21 +859,21 @@ mod interpreter_tests { // NB: traversing the set start-to-end, we're CONSing to a // list, thus the first element of the map is the last element // of the list. - vec![V::Int(3), V::Int(2), V::Int(1),].into() + vec![V::int(3), V::int(2), V::int(1),].into() )] ); } #[test] fn test_iter_set_zero() { - let mut stack = stk![V::Int(0), V::Set(BTreeSet::new())]; + let mut stack = stk![V::int(0), V::Set(BTreeSet::new())]; assert!(interpret_one( &Iter(overloads::Iter::Set, vec![Add(overloads::Add::IntInt)]), &mut Ctx::default(), &mut stack, ) .is_ok()); - assert_eq!(stack, stk![V::Int(0)]); + assert_eq!(stack, stk![V::int(0)]); } #[test] @@ -884,9 +882,9 @@ mod interpreter_tests { V::List(vec![].into()), V::Map( vec![ - (V::Int(1), V::Nat(1)), - (V::Int(2), V::Nat(2)), - (V::Int(3), V::Nat(3)), + (V::int(1), V::nat(1)), + (V::int(2), V::nat(2)), + (V::int(3), V::nat(3)), ] .into_iter() .collect() @@ -905,9 +903,9 @@ mod interpreter_tests { // list, thus the first element of the map is the last element // of the list. vec![ - V::new_pair(V::Int(3), V::Nat(3)), - V::new_pair(V::Int(2), V::Nat(2)), - V::new_pair(V::Int(1), V::Nat(1)), + V::new_pair(V::int(3), V::nat(3)), + V::new_pair(V::int(2), V::nat(2)), + V::new_pair(V::int(1), V::nat(1)), ] .into() )] @@ -916,20 +914,20 @@ mod interpreter_tests { #[test] fn test_iter_map_zero() { - let mut stack = stk![V::Int(0), V::Map(BTreeMap::new())]; + let mut stack = stk![V::int(0), V::Map(BTreeMap::new())]; assert!(interpret_one( &Iter(overloads::Iter::Map, vec![Car, Add(overloads::Add::IntInt)]), &mut Ctx::default(), &mut stack, ) .is_ok()); - assert_eq!(stack, stk![V::Int(0)]); + assert_eq!(stack, stk![V::int(0)]); } #[test] fn test_swap() { - let mut stack = stk![V::Nat(20), V::Int(10)]; - let expected_stack = stk![V::Int(10), V::Nat(20)]; + let mut stack = stk![V::nat(20), V::int(10)]; + let expected_stack = stk![V::int(10), V::nat(20)]; let mut ctx = Ctx::default(); assert!(interpret_one(&Swap, &mut ctx, &mut stack).is_ok()); assert_eq!(stack, expected_stack); @@ -941,9 +939,9 @@ mod interpreter_tests { interpret_one( &Failwith(Type::Nat), &mut Ctx::default(), - &mut stk![V::Nat(20)] + &mut stk![V::nat(20)] ), - Err(InterpretError::FailedWith(Type::Nat, V::Nat(20))) + Err(InterpretError::FailedWith(Type::Nat, V::nat(20))) ); } @@ -989,8 +987,8 @@ mod interpreter_tests { let mut ctx = Ctx::default(); assert!(interpret( &vec![Push(V::new_pair( - V::Int(-5), - V::new_pair(V::Nat(3), V::Bool(false)) + V::int(-5), + V::new_pair(V::nat(3), V::Bool(false)) ))], &mut ctx, &mut stack @@ -999,8 +997,8 @@ mod interpreter_tests { assert_eq!( stack, stk![V::new_pair( - V::Int(-5), - V::new_pair(V::Nat(3), V::Bool(false)) + V::int(-5), + V::new_pair(V::nat(3), V::Bool(false)) )] ); assert_eq!( @@ -1014,12 +1012,12 @@ mod interpreter_tests { let mut stack = stk![]; let mut ctx = Ctx::default(); assert!(interpret( - &vec![Push(V::new_option(Some(V::Int(-5))))], + &vec![Push(V::new_option(Some(V::int(-5))))], &mut ctx, &mut stack ) .is_ok()); - assert_eq!(stack, stk![V::new_option(Some(V::Int(-5)))]); + assert_eq!(stack, stk![V::new_option(Some(V::int(-5)))]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - interpret_cost::PUSH - interpret_cost::INTERPRET_RET @@ -1033,8 +1031,8 @@ mod interpreter_tests { assert!(interpret( &vec![ Push(V::new_pair( - V::Int(-5), - V::new_pair(V::Nat(3), V::Bool(false)) + V::int(-5), + V::new_pair(V::nat(3), V::Bool(false)) )), Car ], @@ -1042,7 +1040,7 @@ mod interpreter_tests { &mut stack ) .is_ok()); - assert_eq!(stack, stk![V::Int(-5)]); + assert_eq!(stack, stk![V::int(-5)]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() @@ -1059,8 +1057,8 @@ mod interpreter_tests { assert!(interpret( &vec![ Push(V::new_pair( - V::new_pair(V::Nat(3), V::Bool(false)), - V::Int(-5), + V::new_pair(V::nat(3), V::Bool(false)), + V::int(-5), )), Cdr ], @@ -1068,7 +1066,7 @@ mod interpreter_tests { &mut stack ) .is_ok()); - assert_eq!(stack, stk![V::Int(-5)]); + assert_eq!(stack, stk![V::int(-5)]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() @@ -1080,40 +1078,40 @@ mod interpreter_tests { #[test] fn pair() { - let mut stack = stk![V::Nat(42), V::Bool(false)]; // NB: bool is top + let mut stack = stk![V::nat(42), V::Bool(false)]; // NB: bool is top assert!(interpret(&vec![Pair], &mut Ctx::default(), &mut stack).is_ok()); - assert_eq!(stack, stk![V::new_pair(V::Bool(false), V::Nat(42))]); + assert_eq!(stack, stk![V::new_pair(V::Bool(false), V::nat(42))]); } #[test] fn unpair() { - let mut stack = stk![V::new_pair(V::Bool(false), V::Nat(42))]; + let mut stack = stk![V::new_pair(V::Bool(false), V::nat(42))]; assert!(interpret(&vec![Unpair], &mut Ctx::default(), &mut stack).is_ok()); - assert_eq!(stack, stk![V::Nat(42), V::Bool(false)]); + assert_eq!(stack, stk![V::nat(42), V::Bool(false)]); } #[test] fn pair_car() { - let mut stack = stk![V::Nat(42), V::Bool(false)]; // NB: bool is top + let mut stack = stk![V::nat(42), V::Bool(false)]; // NB: bool is top assert!(interpret(&vec![Pair, Car], &mut Ctx::default(), &mut stack).is_ok()); assert_eq!(stack, stk![V::Bool(false)]); } #[test] fn pair_cdr() { - let mut stack = stk![V::Nat(42), V::Bool(false)]; // NB: bool is top + let mut stack = stk![V::nat(42), V::Bool(false)]; // NB: bool is top assert!(interpret(&vec![Pair, Cdr], &mut Ctx::default(), &mut stack).is_ok()); - assert_eq!(stack, stk![V::Nat(42)]); + assert_eq!(stack, stk![V::nat(42)]); } #[test] fn if_none_1() { - let code = vec![IfNone(vec![Push(TypedValue::Int(5))], vec![])]; + let code = vec![IfNone(vec![Push(V::int(5))], vec![])]; // with Some - let mut stack = stk![V::new_option(Some(V::Int(42)))]; + let mut stack = stk![V::new_option(Some(V::int(42)))]; let mut ctx = Ctx::default(); assert_eq!(interpret(&code, &mut ctx, &mut stack), Ok(())); - assert_eq!(stack, stk![V::Int(42)]); + assert_eq!(stack, stk![V::int(42)]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - interpret_cost::IF_NONE - interpret_cost::INTERPRET_RET * 2 @@ -1122,12 +1120,12 @@ mod interpreter_tests { #[test] fn if_none_2() { - let code = vec![IfNone(vec![Push(TypedValue::Int(5))], vec![])]; + let code = vec![IfNone(vec![Push(V::int(5))], vec![])]; // with None let mut stack = stk![V::new_option(None)]; let mut ctx = Ctx::default(); assert_eq!(interpret(&code, &mut ctx, &mut stack), Ok(())); - assert_eq!(stack, stk![V::Int(5)]); + assert_eq!(stack, stk![V::int(5)]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() @@ -1139,11 +1137,11 @@ mod interpreter_tests { #[test] fn if_cons_cons() { - let code = vec![IfCons(vec![Swap, Drop(None)], vec![Push(V::Int(0))])]; - let mut stack = stk![V::List(vec![V::Int(1), V::Int(2)].into())]; + let code = vec![IfCons(vec![Swap, Drop(None)], vec![Push(V::int(0))])]; + let mut stack = stk![V::List(vec![V::int(1), V::int(2)].into())]; let mut ctx = Ctx::default(); assert_eq!(interpret(&code, &mut ctx, &mut stack), Ok(())); - assert_eq!(stack, stk![V::Int(1)]); + assert_eq!(stack, stk![V::int(1)]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() @@ -1156,11 +1154,11 @@ mod interpreter_tests { #[test] fn if_cons_nil() { - let code = vec![IfCons(vec![Swap, Drop(None)], vec![Push(V::Int(0))])]; + let code = vec![IfCons(vec![Swap, Drop(None)], vec![Push(V::int(0))])]; let mut stack = stk![V::List(vec![].into())]; let mut ctx = Ctx::default(); assert_eq!(interpret(&code, &mut ctx, &mut stack), Ok(())); - assert_eq!(stack, stk![V::Int(0)]); + assert_eq!(stack, stk![V::int(0)]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() @@ -1172,11 +1170,11 @@ mod interpreter_tests { #[test] fn if_left_left() { - let code = vec![IfLeft(vec![], vec![Drop(None), Push(V::Int(0))])]; - let mut stack = stk![V::new_or(Or::Left(V::Int(1)))]; + let code = vec![IfLeft(vec![], vec![Drop(None), Push(V::int(0))])]; + let mut stack = stk![V::new_or(Or::Left(V::int(1)))]; let mut ctx = Ctx::default(); assert_eq!(interpret(&code, &mut ctx, &mut stack), Ok(())); - assert_eq!(stack, stk![V::Int(1)]); + assert_eq!(stack, stk![V::int(1)]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - interpret_cost::IF_LEFT - interpret_cost::INTERPRET_RET * 2 @@ -1185,11 +1183,11 @@ mod interpreter_tests { #[test] fn if_left_right() { - let code = vec![IfLeft(vec![], vec![Drop(None), Push(V::Int(0))])]; + let code = vec![IfLeft(vec![], vec![Drop(None), Push(V::int(0))])]; let mut stack = stk![V::new_or(Or::Right(V::Unit))]; let mut ctx = Ctx::default(); assert_eq!(interpret(&code, &mut ctx, &mut stack), Ok(())); - assert_eq!(stack, stk![V::Int(0)]); + assert_eq!(stack, stk![V::int(0)]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() @@ -1202,10 +1200,10 @@ mod interpreter_tests { #[test] fn some() { - let mut stack = stk![V::Int(5)]; + let mut stack = stk![V::int(5)]; let mut ctx = Ctx::default(); assert!(interpret(&vec![ISome], &mut ctx, &mut stack).is_ok()); - assert_eq!(stack, stk![V::new_option(Some(V::Int(5)))]); + assert_eq!(stack, stk![V::new_option(Some(V::int(5)))]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - interpret_cost::SOME - interpret_cost::INTERPRET_RET @@ -1237,21 +1235,21 @@ mod interpreter_tests { assert_eq!(ctx.gas.milligas(), Gas::default().milligas() - expected_cost); }; } - test!([V::Int(5), V::Int(6)], [V::Int(1)]); - test!([V::Int(5), V::Int(5)], [V::Int(0)]); - test!([V::Int(6), V::Int(5)], [V::Int(-1)]); - test!([V::Bool(true), V::Bool(false)], [V::Int(-1)]); - test!([V::Bool(true), V::Bool(true)], [V::Int(0)]); - test!([V::Bool(false), V::Bool(true)], [V::Int(1)]); - test!([V::Bool(false), V::Bool(false)], [V::Int(0)]); + test!([V::int(5), V::int(6)], [V::int(1)]); + test!([V::int(5), V::int(5)], [V::int(0)]); + test!([V::int(6), V::int(5)], [V::int(-1)]); + test!([V::Bool(true), V::Bool(false)], [V::int(-1)]); + test!([V::Bool(true), V::Bool(true)], [V::int(0)]); + test!([V::Bool(false), V::Bool(true)], [V::int(1)]); + test!([V::Bool(false), V::Bool(false)], [V::int(0)]); test!( [V::String("foo".to_owned()), V::String("bar".to_owned())], - [V::Int(-1)] + [V::int(-1)] ); - test!([V::Unit, V::Unit], [V::Int(0)]); + test!([V::Unit, V::Unit], [V::int(0)]); test!( - [V::new_option(Some(V::Int(5))), V::Option(None)], - [V::Int(-1)] + [V::new_option(Some(V::int(5))), V::Option(None)], + [V::int(-1)] ); } @@ -1261,7 +1259,7 @@ mod interpreter_tests { let mut ctx = Ctx::default(); ctx.amount = 100500; assert_eq!(interpret(&vec![Amount], &mut ctx, &mut stack), Ok(())); - assert_eq!(stack, stk![TypedValue::Mutez(100500)]); + assert_eq!(stack, stk![V::Mutez(100500)]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - interpret_cost::INTERPRET_RET - interpret_cost::AMOUNT, @@ -1274,9 +1272,7 @@ mod interpreter_tests { let mut ctx = Ctx::default(); assert_eq!( interpret( - &vec![Push(TypedValue::List( - vec![TypedValue::Int(1), TypedValue::Int(2), TypedValue::Int(3),].into() - ))], + &vec![Push(V::List(vec![V::int(1), V::int(2), V::int(3),].into()))], &mut ctx, &mut stack ), @@ -1284,9 +1280,7 @@ mod interpreter_tests { ); assert_eq!( stack, - stk![TypedValue::List( - vec![TypedValue::Int(1), TypedValue::Int(2), TypedValue::Int(3),].into() - )] + stk![V::List(vec![V::int(1), V::int(2), V::int(3),].into())] ); assert_eq!( ctx.gas.milligas(), @@ -1299,7 +1293,7 @@ mod interpreter_tests { let mut stack = stk![]; let mut ctx = Ctx::default(); assert_eq!(interpret(&vec![Nil], &mut ctx, &mut stack), Ok(())); - assert_eq!(stack, stk![TypedValue::List(vec![].into())]); + assert_eq!(stack, stk![V::List(vec![].into())]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - interpret_cost::NIL - interpret_cost::INTERPRET_RET, @@ -1308,13 +1302,10 @@ mod interpreter_tests { #[test] fn cons() { - let mut stack = stk![V::List(vec![V::Int(321)].into()), V::Int(123)]; + let mut stack = stk![V::List(vec![V::int(321)].into()), V::int(123)]; let mut ctx = Ctx::default(); assert_eq!(interpret(&vec![Cons], &mut ctx, &mut stack), Ok(())); - assert_eq!( - stack, - stk![TypedValue::List(vec![V::Int(123), V::Int(321)].into())] - ); + assert_eq!(stack, stk![V::List(vec![V::int(123), V::int(321)].into())]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - interpret_cost::CONS - interpret_cost::INTERPRET_RET, @@ -1326,18 +1317,14 @@ mod interpreter_tests { let mut stack = stk![]; let mut ctx = Ctx::default(); let map = BTreeMap::from([ - (TypedValue::Int(1), TypedValue::String("foo".to_owned())), - (TypedValue::Int(2), TypedValue::String("bar".to_owned())), + (V::int(1), V::String("foo".to_owned())), + (V::int(2), V::String("bar".to_owned())), ]); assert_eq!( - interpret( - &vec![Push(TypedValue::Map(map.clone()))], - &mut ctx, - &mut stack - ), + interpret(&vec![Push(V::Map(map.clone()))], &mut ctx, &mut stack), Ok(()) ); - assert_eq!(stack, stk![TypedValue::Map(map)]); + assert_eq!(stack, stk![V::Map(map)]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - interpret_cost::PUSH - interpret_cost::INTERPRET_RET @@ -1348,24 +1335,22 @@ mod interpreter_tests { fn get_map() { let mut ctx = Ctx::default(); let map = BTreeMap::from([ - (TypedValue::Int(1), TypedValue::String("foo".to_owned())), - (TypedValue::Int(2), TypedValue::String("bar".to_owned())), + (V::int(1), V::String("foo".to_owned())), + (V::int(2), V::String("bar".to_owned())), ]); - let mut stack = stk![TypedValue::Map(map), TypedValue::Int(1)]; + let mut stack = stk![V::Map(map), V::int(1)]; assert_eq!( interpret(&vec![Get(overloads::Get::Map)], &mut ctx, &mut stack), Ok(()) ); assert_eq!( stack, - stk![TypedValue::new_option(Some(TypedValue::String( - "foo".to_owned() - )))] + stk![V::new_option(Some(V::String("foo".to_owned())))] ); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - - interpret_cost::map_get(&TypedValue::Int(1), 2).unwrap() + - interpret_cost::map_get(&V::int(1), 2).unwrap() - interpret_cost::INTERPRET_RET ); } @@ -1374,19 +1359,19 @@ mod interpreter_tests { fn get_map_none() { let mut ctx = Ctx::default(); let map = BTreeMap::from([ - (TypedValue::Int(1), TypedValue::String("foo".to_owned())), - (TypedValue::Int(2), TypedValue::String("bar".to_owned())), + (V::int(1), V::String("foo".to_owned())), + (V::int(2), V::String("bar".to_owned())), ]); - let mut stack = stk![TypedValue::Map(map), TypedValue::Int(100500)]; + let mut stack = stk![V::Map(map), V::int(100500)]; assert_eq!( interpret(&vec![Get(overloads::Get::Map)], &mut ctx, &mut stack), Ok(()) ); - assert_eq!(stack, stk![TypedValue::Option(None)]); + assert_eq!(stack, stk![V::Option(None)]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - - interpret_cost::map_get(&TypedValue::Int(100500), 2).unwrap() + - interpret_cost::map_get(&V::int(100500), 2).unwrap() - interpret_cost::INTERPRET_RET ); } @@ -1395,10 +1380,10 @@ mod interpreter_tests { fn mem_map() { let mut ctx = Ctx::default(); let map = BTreeMap::from([ - (TypedValue::Int(1), TypedValue::String("foo".to_owned())), - (TypedValue::Int(2), TypedValue::String("bar".to_owned())), + (TypedValue::int(1), TypedValue::String("foo".to_owned())), + (TypedValue::int(2), TypedValue::String("bar".to_owned())), ]); - let mut stack = stk![TypedValue::Map(map), TypedValue::Int(1)]; + let mut stack = stk![TypedValue::Map(map), TypedValue::int(1)]; assert_eq!( interpret(&vec![Mem(overloads::Mem::Map)], &mut ctx, &mut stack), Ok(()) @@ -1407,7 +1392,7 @@ mod interpreter_tests { assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - - interpret_cost::map_mem(&TypedValue::Int(1), 2).unwrap() + - interpret_cost::map_mem(&TypedValue::int(1), 2).unwrap() - interpret_cost::INTERPRET_RET ); } @@ -1416,10 +1401,10 @@ mod interpreter_tests { fn mem_map_absent() { let mut ctx = Ctx::default(); let map = BTreeMap::from([ - (TypedValue::Int(1), TypedValue::String("foo".to_owned())), - (TypedValue::Int(2), TypedValue::String("bar".to_owned())), + (TypedValue::int(1), TypedValue::String("foo".to_owned())), + (TypedValue::int(2), TypedValue::String("bar".to_owned())), ]); - let mut stack = stk![TypedValue::Map(map), TypedValue::Int(100500)]; + let mut stack = stk![TypedValue::Map(map), TypedValue::int(100500)]; assert_eq!( interpret(&vec![Mem(overloads::Mem::Map)], &mut ctx, &mut stack), Ok(()) @@ -1430,8 +1415,8 @@ mod interpreter_tests { #[test] fn mem_set() { let mut ctx = Ctx::default(); - let set = BTreeSet::from([TypedValue::Int(1), TypedValue::Int(2)]); - let mut stack = stk![TypedValue::Set(set), TypedValue::Int(1)]; + let set = BTreeSet::from([TypedValue::int(1), TypedValue::int(2)]); + let mut stack = stk![TypedValue::Set(set), TypedValue::int(1)]; assert_eq!( interpret(&vec![Mem(overloads::Mem::Set)], &mut ctx, &mut stack), Ok(()) @@ -1440,7 +1425,7 @@ mod interpreter_tests { assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - - interpret_cost::set_mem(&TypedValue::Int(1), 2).unwrap() + - interpret_cost::set_mem(&TypedValue::int(1), 2).unwrap() - interpret_cost::INTERPRET_RET ); } @@ -1448,8 +1433,8 @@ mod interpreter_tests { #[test] fn mem_set_absent() { let mut ctx = Ctx::default(); - let set = BTreeSet::from([TypedValue::Int(1), TypedValue::Int(2)]); - let mut stack = stk![TypedValue::Set(set), TypedValue::Int(100500)]; + let set = BTreeSet::from([TypedValue::int(1), TypedValue::int(2)]); + let mut stack = stk![TypedValue::Set(set), TypedValue::int(100500)]; assert_eq!( interpret(&vec![Mem(overloads::Mem::Set)], &mut ctx, &mut stack), Ok(()) @@ -1476,7 +1461,7 @@ mod interpreter_tests { let mut stack = stk![ TypedValue::Set(set), TypedValue::Bool(true), - TypedValue::Int(1) + TypedValue::int(1) ]; assert_eq!( interpret(&vec![Update(overloads::Update::Set)], &mut ctx, &mut stack), @@ -1484,12 +1469,12 @@ mod interpreter_tests { ); assert_eq!( stack, - stk![TypedValue::Set(BTreeSet::from([TypedValue::Int(1)])),] + stk![TypedValue::Set(BTreeSet::from([TypedValue::int(1)])),] ); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - - interpret_cost::set_update(&TypedValue::Int(1), 0).unwrap() + - interpret_cost::set_update(&TypedValue::int(1), 0).unwrap() - interpret_cost::INTERPRET_RET ); } @@ -1497,11 +1482,11 @@ mod interpreter_tests { #[test] fn update_set_remove() { let mut ctx = Ctx::default(); - let set = BTreeSet::from([TypedValue::Int(1)]); + let set = BTreeSet::from([TypedValue::int(1)]); let mut stack = stk![ TypedValue::Set(set), TypedValue::Bool(false), - TypedValue::Int(1) + TypedValue::int(1) ]; assert_eq!( interpret(&vec![Update(overloads::Update::Set)], &mut ctx, &mut stack), @@ -1511,7 +1496,7 @@ mod interpreter_tests { assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - - interpret_cost::set_update(&TypedValue::Int(1), 1).unwrap() + - interpret_cost::set_update(&TypedValue::int(1), 1).unwrap() - interpret_cost::INTERPRET_RET ); } @@ -1519,11 +1504,11 @@ mod interpreter_tests { #[test] fn update_set_insert_when_exists() { let mut ctx = Ctx::default(); - let set = BTreeSet::from([TypedValue::Int(1)]); + let set = BTreeSet::from([TypedValue::int(1)]); let mut stack = stk![ TypedValue::Set(set.clone()), TypedValue::Bool(true), - TypedValue::Int(1) + TypedValue::int(1) ]; assert_eq!( interpret(&vec![Update(overloads::Update::Set)], &mut ctx, &mut stack), @@ -1533,7 +1518,7 @@ mod interpreter_tests { assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - - interpret_cost::set_update(&TypedValue::Int(1), 1).unwrap() + - interpret_cost::set_update(&TypedValue::int(1), 1).unwrap() - interpret_cost::INTERPRET_RET ); } @@ -1544,7 +1529,7 @@ mod interpreter_tests { let mut stack = stk![ TypedValue::Set(BTreeSet::new()), TypedValue::Bool(false), - TypedValue::Int(1) + TypedValue::int(1) ]; assert_eq!( interpret(&vec![Update(overloads::Update::Set)], &mut ctx, &mut stack), @@ -1554,7 +1539,7 @@ mod interpreter_tests { assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - - interpret_cost::set_update(&TypedValue::Int(1), 0).unwrap() + - interpret_cost::set_update(&TypedValue::int(1), 0).unwrap() - interpret_cost::INTERPRET_RET ); } @@ -1564,9 +1549,9 @@ mod interpreter_tests { let mut ctx = Ctx::default(); let map = BTreeMap::new(); let mut stack = stk![ - TypedValue::Map(map), - TypedValue::new_option(Some(TypedValue::String("foo".to_owned()))), - TypedValue::Int(1) + V::Map(map), + V::new_option(Some(V::String("foo".to_owned()))), + V::int(1) ]; assert_eq!( interpret(&vec![Update(overloads::Update::Map)], &mut ctx, &mut stack), @@ -1574,15 +1559,15 @@ mod interpreter_tests { ); assert_eq!( stack, - stk![TypedValue::Map(BTreeMap::from([( - TypedValue::Int(1), - TypedValue::String("foo".to_owned()) + stk![V::Map(BTreeMap::from([( + V::int(1), + V::String("foo".to_owned()) )])),] ); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - - interpret_cost::map_update(&TypedValue::Int(1), 0).unwrap() + - interpret_cost::map_update(&V::int(1), 0).unwrap() - interpret_cost::INTERPRET_RET ); } @@ -1590,11 +1575,11 @@ mod interpreter_tests { #[test] fn update_map_update() { let mut ctx = Ctx::default(); - let map = BTreeMap::from([(TypedValue::Int(1), TypedValue::String("bar".to_owned()))]); + let map = BTreeMap::from([(V::int(1), V::String("bar".to_owned()))]); let mut stack = stk![ - TypedValue::Map(map), - TypedValue::new_option(Some(TypedValue::String("foo".to_owned()))), - TypedValue::Int(1) + V::Map(map), + V::new_option(Some(V::String("foo".to_owned()))), + V::int(1) ]; assert_eq!( interpret(&vec![Update(overloads::Update::Map)], &mut ctx, &mut stack), @@ -1602,15 +1587,15 @@ mod interpreter_tests { ); assert_eq!( stack, - stk![TypedValue::Map(BTreeMap::from([( - TypedValue::Int(1), - TypedValue::String("foo".to_owned()) + stk![V::Map(BTreeMap::from([( + V::int(1), + V::String("foo".to_owned()) )])),] ); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - - interpret_cost::map_update(&TypedValue::Int(1), 1).unwrap() + - interpret_cost::map_update(&V::int(1), 1).unwrap() - interpret_cost::INTERPRET_RET ); } @@ -1618,28 +1603,24 @@ mod interpreter_tests { #[test] fn update_map_remove() { let mut ctx = Ctx::default(); - let map = BTreeMap::from([(TypedValue::Int(1), TypedValue::String("bar".to_owned()))]); - let mut stack = stk![ - TypedValue::Map(map), - TypedValue::new_option(None), - TypedValue::Int(1) - ]; + let map = BTreeMap::from([(V::int(1), V::String("bar".to_owned()))]); + let mut stack = stk![V::Map(map), V::new_option(None), V::int(1)]; assert_eq!( interpret(&vec![Update(overloads::Update::Map)], &mut ctx, &mut stack), Ok(()) ); - assert_eq!(stack, stk![TypedValue::Map(BTreeMap::new())]); + assert_eq!(stack, stk![V::Map(BTreeMap::new())]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - - interpret_cost::map_update(&TypedValue::Int(1), 1).unwrap() + - interpret_cost::map_update(&V::int(1), 1).unwrap() - interpret_cost::INTERPRET_RET ); } #[test] fn seq() { - let mut stack = stk![TypedValue::Int(1), TypedValue::Nat(2)]; + let mut stack = stk![V::int(1), V::nat(2)]; assert_eq!( interpret( &vec![ @@ -1653,12 +1634,12 @@ mod interpreter_tests { ), Ok(()) ); - assert_eq!(stack, stk![TypedValue::Nat(2)]); + assert_eq!(stack, stk![V::nat(2)]); } #[test] fn add_int_nat() { - let mut stack = stk![TypedValue::Nat(123), TypedValue::Int(456)]; + let mut stack = stk![V::nat(123), V::int(456)]; assert_eq!( interpret( &vec![Add(overloads::Add::IntNat)], @@ -1667,12 +1648,12 @@ mod interpreter_tests { ), Ok(()) ); - assert_eq!(stack, stk![TypedValue::Int(579)]); + assert_eq!(stack, stk![V::int(579)]); } #[test] fn add_int_nat_2() { - let mut stack = stk![TypedValue::Nat(123), TypedValue::Int(-456)]; + let mut stack = stk![V::nat(123), V::int(-456)]; assert_eq!( interpret( &vec![Add(overloads::Add::IntNat)], @@ -1681,12 +1662,12 @@ mod interpreter_tests { ), Ok(()) ); - assert_eq!(stack, stk![TypedValue::Int(-333)]); + assert_eq!(stack, stk![V::int(-333)]); } #[test] fn add_nat_int() { - let mut stack = stk![TypedValue::Int(789), TypedValue::Nat(42)]; + let mut stack = stk![V::int(789), V::nat(42)]; assert_eq!( interpret( &vec![Add(overloads::Add::NatInt)], @@ -1695,12 +1676,12 @@ mod interpreter_tests { ), Ok(()) ); - assert_eq!(stack, stk![TypedValue::Int(831)]); + assert_eq!(stack, stk![V::int(831)]); } #[test] fn add_nat_int_2() { - let mut stack = stk![TypedValue::Int(-789), TypedValue::Nat(42)]; + let mut stack = stk![V::int(-789), V::nat(42)]; assert_eq!( interpret( &vec![Add(overloads::Add::NatInt)], @@ -1709,7 +1690,7 @@ mod interpreter_tests { ), Ok(()) ); - assert_eq!(stack, stk![TypedValue::Int(-747)]); + assert_eq!(stack, stk![V::int(-747)]); } #[test] @@ -1734,7 +1715,7 @@ mod interpreter_tests { let start_milligas = ctx.gas.milligas(); let stk = &mut stk![]; assert_eq!(interpret(&vec![Instruction::ChainId], ctx, stk), Ok(())); - assert_eq!(stk, &stk![TypedValue::ChainId(chain_id)]); + assert_eq!(stk, &stk![V::ChainId(chain_id)]); assert_eq!( start_milligas - ctx.gas.milligas(), interpret_cost::CHAIN_ID + interpret_cost::INTERPRET_RET @@ -1743,11 +1724,11 @@ mod interpreter_tests { #[test] fn pack_instr() { - let stack = &mut stk![TypedValue::new_pair(TypedValue::Int(12), TypedValue::Unit)]; + let stack = &mut stk![TypedValue::new_pair(TypedValue::int(12), TypedValue::Unit)]; assert_eq!(interpret(&vec![Pack], &mut Ctx::default(), stack), Ok(())); assert_eq!( stack, - &stk![TypedValue::Bytes(hex::decode("050707000c030b").unwrap())] + &stk![V::Bytes(hex::decode("050707000c030b").unwrap())] ); } @@ -1762,7 +1743,7 @@ mod interpreter_tests { ); assert_eq!( stk, - &stk![TypedValue::Contract( + &stk![V::Contract( "KT18amZmM5W7qDWVt2pH6uj7sCEd3kbzLrHT".try_into().unwrap() )] ); @@ -1771,13 +1752,14 @@ mod interpreter_tests { #[test] fn transfer_tokens() { let tt = super::TransferTokens { - param: TypedValue::Nat(42), - destination_address: addr::Address::try_from("tz1Nw5nr152qddEjKT2dKBH8XcBMDAg72iLw").unwrap(), + param: TypedValue::nat(42), + destination_address: addr::Address::try_from("tz1Nw5nr152qddEjKT2dKBH8XcBMDAg72iLw") + .unwrap(), amount: 0, }; let stk = &mut stk![ - TypedValue::Contract(tt.destination_address.clone()), - TypedValue::Mutez(tt.amount), + V::Contract(tt.destination_address.clone()), + V::Mutez(tt.amount), tt.param.clone() ]; let ctx = &mut Ctx::default(); @@ -1786,10 +1768,7 @@ mod interpreter_tests { assert_eq!(interpret(&vec![TransferTokens], ctx, stk), Ok(())); assert_eq!( stk, - &stk![TypedValue::new_operation( - Operation::TransferTokens(tt), - 101 - )] + &stk![V::new_operation(Operation::TransferTokens(tt), 101)] ); assert_eq!( start_milligas - ctx.gas.milligas(), @@ -1803,16 +1782,14 @@ mod interpreter_tests { let sd = super::SetDelegate(Some( KeyHash::try_from("tz3h4mjmMieZKSaSBWBC7XmeL6JQ3hucFDcP").unwrap(), )); - let stk = &mut stk![TypedValue::new_option(Some(TypedValue::KeyHash( - sd.0.clone().unwrap() - )))]; + let stk = &mut stk![V::new_option(Some(V::KeyHash(sd.0.clone().unwrap())))]; let ctx = &mut Ctx::default(); ctx.set_operation_counter(100); let start_milligas = ctx.gas.milligas(); assert_eq!(interpret(&vec![I::SetDelegate], ctx, stk), Ok(())); assert_eq!( stk, - &stk![TypedValue::new_operation(Operation::SetDelegate(sd), 101)] + &stk![V::new_operation(Operation::SetDelegate(sd), 101)] ); assert_eq!( start_milligas - ctx.gas.milligas(), @@ -1830,8 +1807,8 @@ mod interpreter_tests { KeyHash::try_from("tz3h4mjmMieZKSaSBWBC7XmeL6JQ3hucFDcP").unwrap(), )); let stk = &mut stk![ - TypedValue::new_option(Some(TypedValue::KeyHash(sd.0.clone().unwrap()))), - TypedValue::new_option(Some(TypedValue::KeyHash(sd.0.clone().unwrap()))) + V::new_option(Some(V::KeyHash(sd.0.clone().unwrap()))), + V::new_option(Some(V::KeyHash(sd.0.clone().unwrap()))) ]; let ctx = &mut Ctx::default(); ctx.set_operation_counter(100); @@ -1842,8 +1819,8 @@ mod interpreter_tests { assert_eq!( stk, &stk![ - TypedValue::new_operation(Operation::SetDelegate(sd.clone()), 101), - TypedValue::new_operation(Operation::SetDelegate(sd), 102) + V::new_operation(Operation::SetDelegate(sd.clone()), 101), + V::new_operation(Operation::SetDelegate(sd), 102) ] ); } @@ -1859,7 +1836,7 @@ mod interpreter_tests { ); assert_eq!( stk, - &stk![TypedValue::Contract( + &stk![V::Contract( "KT18amZmM5W7qDWVt2pH6uj7sCEd3kbzLrHT%foo" .try_into() .unwrap() @@ -1897,8 +1874,8 @@ mod interpreter_tests { #[test] fn slice_instr_string() { - fn test(str: &str, offset: u128, length: u128, expected: Option<&str>) { - let stk = &mut stk![V::String(str.to_string()), V::Nat(length), V::Nat(offset)]; + fn test(str: &str, offset: u32, length: u32, expected: Option<&str>) { + let stk = &mut stk![V::String(str.to_string()), V::nat(length), V::nat(offset)]; let ctx = &mut Ctx::default(); let expected = expected.map(|str| V::String(str.to_string())); assert_eq!( @@ -1919,8 +1896,8 @@ mod interpreter_tests { #[test] fn slice_instr_bytes() { - fn test(bytes: &[u8], offset: u128, length: u128, expected: Option<&[u8]>) { - let stk = &mut stk![V::Bytes(bytes.to_vec()), V::Nat(length), V::Nat(offset)]; + fn test(bytes: &[u8], offset: u32, length: u32, expected: Option<&[u8]>) { + let stk = &mut stk![V::Bytes(bytes.to_vec()), V::nat(length), V::nat(offset)]; let ctx = &mut Ctx::default(); let expected = expected.map(|bytes| V::Bytes(bytes.to_vec())); assert_eq!( @@ -1941,10 +1918,10 @@ mod interpreter_tests { #[test] fn left() { - let mut stack = stk![V::Nat(10)]; + let mut stack = stk![V::nat(10)]; let mut ctx = Ctx::default(); assert!(interpret(&vec![Instruction::Left], &mut ctx, &mut stack).is_ok()); - assert_eq!(stack, stk![V::new_or(Or::Left(V::Nat(10)))]); + assert_eq!(stack, stk![V::new_or(Or::Left(V::nat(10)))]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - interpret_cost::LEFT - interpret_cost::INTERPRET_RET @@ -1953,10 +1930,10 @@ mod interpreter_tests { #[test] fn right() { - let mut stack = stk![V::Nat(10)]; + let mut stack = stk![V::nat(10)]; let mut ctx = Ctx::default(); assert!(interpret(&vec![Instruction::Right], &mut ctx, &mut stack).is_ok()); - assert_eq!(stack, stk![V::new_or(Or::Right(V::Nat(10)))]); + assert_eq!(stack, stk![V::new_or(Or::Right(V::nat(10)))]); assert_eq!( ctx.gas.milligas(), Gas::default().milligas() - interpret_cost::RIGHT - interpret_cost::INTERPRET_RET diff --git a/contrib/mir/src/lexer.rs b/contrib/mir/src/lexer.rs index 22f5ade39e2e2fda03c6ccf54e3260d3e57b4156..ecd4c1a10a911b0eacc456edbdcf9b2918f7b383 100644 --- a/contrib/mir/src/lexer.rs +++ b/contrib/mir/src/lexer.rs @@ -11,6 +11,7 @@ pub mod macros; pub use errors::*; use macros::*; +use num_bigint::BigInt; /// Expand to the first argument if not empty; otherwise, the second argument. macro_rules! coalesce { @@ -161,7 +162,7 @@ pub enum Tok<'a> { Noun(Noun), #[regex("([+-]?)[0-9]+", lex_number)] - Number(i128), + Number(BigInt), #[regex(r#""(\\.|[^\\"])*""#, lex_string)] String(String), @@ -234,7 +235,7 @@ fn lex_noun(lex: &mut Lexer) -> Result { .map_err(LexerError::PrimError) } -fn lex_number(lex: &mut Lexer) -> Result { +fn lex_number(lex: &mut Lexer) -> Result { lex.slice() .parse() .map_err(|_| LexerError::NumericLiteral(lex.slice().to_owned())) diff --git a/contrib/mir/src/lexer/errors.rs b/contrib/mir/src/lexer/errors.rs index fb5e9f77d92ec17235931ef99e85c29cf13ee7d4..04d8ae70c3cba11c6866d190d65b0bd94ff89bfb 100644 --- a/contrib/mir/src/lexer/errors.rs +++ b/contrib/mir/src/lexer/errors.rs @@ -9,9 +9,10 @@ #[error("unknown primitive: {0}")] pub struct PrimError(pub String); -#[derive(Debug, PartialEq, Clone, thiserror::Error)] +#[derive(Debug, PartialEq, Clone, thiserror::Error, Default)] pub enum LexerError { #[error("unknown token")] + #[default] UnknownToken, #[error("parsing of numeric literal {0} failed")] NumericLiteral(String), @@ -24,9 +25,3 @@ pub enum LexerError { #[error("invalid hex sequence: {0}")] InvalidHex(#[from] hex::FromHexError), } - -impl Default for LexerError { - fn default() -> Self { - LexerError::UnknownToken - } -} diff --git a/contrib/mir/src/lib.rs b/contrib/mir/src/lib.rs index af596c72be30674ee86d142774ca07da28710ecb..d4eb6cd2da5c67e2bdea8a2f0bb453a1692442d5 100644 --- a/contrib/mir/src/lib.rs +++ b/contrib/mir/src/lib.rs @@ -44,9 +44,9 @@ mod tests { let ast = ast .typecheck_instruction(&mut Ctx::default(), None, &[app!(nat)]) .unwrap(); - let mut istack = stk![TypedValue::Nat(10)]; + let mut istack = stk![TypedValue::nat(10)]; assert!(ast.interpret(&mut Ctx::default(), &mut istack).is_ok()); - assert!(istack.len() == 1 && istack[0] == TypedValue::Int(55)); + assert!(istack.len() == 1 && istack[0] == TypedValue::int(55)); } #[test] @@ -65,12 +65,12 @@ mod tests { let ast = ast .typecheck_instruction(&mut Ctx::default(), None, &[app!(nat)]) .unwrap(); - let mut istack = stk![TypedValue::Nat(5)]; + let mut istack = stk![TypedValue::nat(5)]; let mut ctx = Ctx::default(); report_gas(&mut ctx, |ctx| { assert!(ast.interpret(ctx, &mut istack).is_ok()); }); - assert_eq!(Gas::default().milligas() - ctx.gas.milligas(), 1359); + assert_eq!(Gas::default().milligas() - ctx.gas.milligas(), 1287); } #[test] @@ -79,11 +79,11 @@ mod tests { let ast = ast .typecheck_instruction(&mut Ctx::default(), None, &[app!(nat)]) .unwrap(); - let mut istack = stk![TypedValue::Nat(5)]; - let mut ctx = &mut Ctx::default(); + let mut istack = stk![TypedValue::nat(5)]; + let ctx = &mut Ctx::default(); ctx.gas = Gas::new(1); assert_eq!( - ast.interpret(&mut ctx, &mut istack), + ast.interpret(ctx, &mut istack), Err(interpreter::InterpretError::OutOfGas(crate::gas::OutOfGas)), ); } @@ -94,9 +94,9 @@ mod tests { let ast = ast .typecheck_instruction(&mut Ctx::default(), None, &[app!(option[app!(nat)])]) .unwrap(); - let mut istack = stk![TypedValue::new_option(Some(TypedValue::Nat(5)))]; + let mut istack = stk![TypedValue::new_option(Some(TypedValue::nat(5)))]; assert!(ast.interpret(&mut Ctx::default(), &mut istack).is_ok()); - assert_eq!(istack, stk![TypedValue::Nat(6)]); + assert_eq!(istack, stk![TypedValue::nat(6)]); } #[test] @@ -128,10 +128,10 @@ mod tests { #[test] fn typecheck_out_of_gas() { let ast = parse(FIBONACCI_SRC).unwrap(); - let mut ctx = &mut Ctx::default(); + let ctx = &mut Ctx::default(); ctx.gas = Gas::new(1000); assert_eq!( - ast.typecheck_instruction(&mut ctx, None, &[app!(nat)]), + ast.typecheck_instruction(ctx, None, &[app!(nat)]), Err(typechecker::TcError::OutOfGas(crate::gas::OutOfGas)) ); } @@ -216,21 +216,21 @@ mod tests { #[test] fn vote_contract() { use crate::ast::micheline::test_helpers::*; - let mut ctx = &mut Ctx::default(); + let ctx = &mut Ctx::default(); ctx.amount = 5_000_000; let interp_res = parse_contract_script(VOTE_SRC) .unwrap() - .typecheck_script(&mut ctx) + .typecheck_script(ctx) .unwrap() .interpret( - &mut ctx, + ctx, "foo".into(), seq! {app!(Elt["bar", 0]); app!(Elt["baz", 0]); app!(Elt["foo", 0])}, ); use TypedValue as TV; match interp_res.unwrap() { (_, TV::Map(m)) => { - assert_eq!(m.get(&TV::String("foo".to_owned())).unwrap(), &TV::Int(1)) + assert_eq!(m.get(&TV::String("foo".to_owned())).unwrap(), &TV::int(1)) } _ => panic!("unexpected contract output"), } @@ -291,6 +291,7 @@ mod multisig_tests { use crate::context::Ctx; use crate::interpreter::{ContractInterpretError, InterpretError}; use crate::parser::test_helpers::parse_contract_script; + use num_bigint::BigUint; use Type as T; use TypedValue as TV; @@ -321,12 +322,15 @@ mod multisig_tests { ctx.chain_id = tezos_crypto_rs::hash::ChainId(hex::decode("f3d48554").unwrap()); ctx } - static ANTI_REPLAY_COUNTER: i128 = 111; + + fn anti_replay_counter() -> BigUint { + BigUint::from(111u32) + } #[test] fn multisig_transfer() { let mut ctx = make_ctx(); - let threshold = 1; + let threshold = BigUint::from(1u32); /* # Pack the parameter we will be sending to the multisig contract. @@ -354,7 +358,7 @@ mod multisig_tests { app!(Pair[ // :payload app!(Pair[ - ANTI_REPLAY_COUNTER, + anti_replay_counter(), app!(Left[ // :transfer app!(Pair[transfer_amount as i128,transfer_destination]) @@ -364,7 +368,7 @@ mod multisig_tests { seq!{ app!(Some[signature]) } ]), // make_initial_storage(), - app!(Pair[ANTI_REPLAY_COUNTER, threshold, seq!{ PUBLIC_KEY }]), + app!(Pair[anti_replay_counter(), threshold.clone(), seq!{ PUBLIC_KEY }]), ); assert_eq!( @@ -379,9 +383,9 @@ mod multisig_tests { counter: 1 }], TV::new_pair( - TV::Nat(ANTI_REPLAY_COUNTER as u128 + 1), + TV::Nat(anti_replay_counter() + BigUint::from(1u32)), TV::new_pair( - TV::Nat(threshold as u128), + TV::Nat(threshold), TV::List(MichelsonList::from(vec![TV::Key( PUBLIC_KEY.try_into().unwrap() )])) @@ -394,7 +398,7 @@ mod multisig_tests { #[test] fn multisig_set_delegate() { let mut ctx = make_ctx(); - let threshold = 1; + let threshold = BigUint::from(1u32); /* # Pack the parameter we will be sending to the multisig contract. @@ -421,7 +425,7 @@ mod multisig_tests { app!(Pair[ // :payload app!(Pair[ - ANTI_REPLAY_COUNTER, + anti_replay_counter(), app!(Right[ app!(Left[ // %delegate app!(Some[new_delegate]) @@ -430,7 +434,7 @@ mod multisig_tests { // %sigs seq!{ app!(Some[signature]) } ]), - app!(Pair[ANTI_REPLAY_COUNTER, threshold, seq!{ PUBLIC_KEY }]), + app!(Pair[anti_replay_counter(), threshold.clone(), seq!{ PUBLIC_KEY }]), ); assert_eq!( @@ -443,9 +447,9 @@ mod multisig_tests { counter: 1 }], TV::new_pair( - TV::Nat(ANTI_REPLAY_COUNTER as u128 + 1), + TV::Nat(anti_replay_counter() + BigUint::from(1u32)), TV::new_pair( - TV::Nat(threshold as u128), + TV::Nat(threshold), TV::List(MichelsonList::from(vec![TV::Key( PUBLIC_KEY.try_into().unwrap() )])) @@ -471,7 +475,7 @@ mod multisig_tests { app!(Pair[ // :payload app!(Pair[ - ANTI_REPLAY_COUNTER, + anti_replay_counter(), app!(Right[ app!(Left[ // %delegate app!(Some[new_delegate]) @@ -480,7 +484,7 @@ mod multisig_tests { // %sigs seq!{ app!(Some[invalid_signature]) } ]), - app!(Pair[ANTI_REPLAY_COUNTER, threshold, seq!{ PUBLIC_KEY }]), + app!(Pair[anti_replay_counter(), threshold, seq!{ PUBLIC_KEY }]), ); assert_eq!( diff --git a/contrib/mir/src/parser/macros.rs b/contrib/mir/src/parser/macros.rs index 0fb646eac1d78e797c9e6fd9b59c38da27633846..a9a765d6f887de658d0f98e585c520c1467fa2c0 100644 --- a/contrib/mir/src/parser/macros.rs +++ b/contrib/mir/src/parser/macros.rs @@ -91,10 +91,10 @@ pub fn expand_macro<'a>( // Do not wrap expansion of DII+P and DUU+P in a Seq to // match octez-client behavior. - (DIIP(c), OneArg(ib)) => Ok(M::prim2(arena, DIP, M::Int(*c as i128), ib)), + (DIIP(c), OneArg(ib)) => Ok(M::prim2(arena, DIP, M::Int((*c).into()), ib)), (DIIP(_), _) => Err(unex_arg_err), - (DUUP(c), NoArgs) => Ok(M::prim1(arena, DUP, M::Int(*c as i128))), + (DUUP(c), NoArgs) => Ok(M::prim1(arena, DUP, M::Int((*c).into()))), (DUUP(_), _) => Err(unex_arg_err), } } diff --git a/contrib/mir/src/serializer/encode.rs b/contrib/mir/src/serializer/encode.rs index a24b371b90d5ed180538412bb6120bc1dbda81e1..47d85dfb0b9ef4ba4e9458fd53256107dc47605e 100644 --- a/contrib/mir/src/serializer/encode.rs +++ b/contrib/mir/src/serializer/encode.rs @@ -162,7 +162,7 @@ fn encode_micheline(mich: &Micheline, out: &mut Vec) { use Micheline::*; match mich { Int(n) => { - let z = Zarith((*n).into()); + let z = Zarith(n.clone()); out.push(NUMBER_TAG); z.bin_write(out) .unwrap_or_else(|err| panic!("Encoding zarith number unexpectedly failed: {err}")) diff --git a/contrib/mir/src/serializer/integration_tests.rs b/contrib/mir/src/serializer/integration_tests.rs index 0b651f94d910a97c7e01c763217c17e53b390c43..86c57ed51ea06af642b4caba38e9c275aa613178 100644 --- a/contrib/mir/src/serializer/integration_tests.rs +++ b/contrib/mir/src/serializer/integration_tests.rs @@ -62,8 +62,8 @@ mod test_typed_encode { // Should be encoded as a tree check( TypedValue::new_pair( - TypedValue::Nat(1), - TypedValue::new_pair(TypedValue::Nat(2), TypedValue::Nat(3)), + TypedValue::nat(1), + TypedValue::new_pair(TypedValue::nat(2), TypedValue::nat(3)), ), "0x0507070001070700020003", ) diff --git a/contrib/mir/src/stack.rs b/contrib/mir/src/stack.rs index f8fbda0c945fa204340cc210f32f68a5808535ac..91bef040dc408dfe44ddb99407faa6732ebdc9aa 100644 --- a/contrib/mir/src/stack.rs +++ b/contrib/mir/src/stack.rs @@ -87,6 +87,7 @@ impl Stack { } /// Get the stack's element count. + #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { self.0.len() } diff --git a/contrib/mir/src/syntax.lalrpop b/contrib/mir/src/syntax.lalrpop index f648daf92853a4da953a156b2a66956c747f9d56..1fdc8ff7301298a59123bda7d23a26005959d453 100644 --- a/contrib/mir/src/syntax.lalrpop +++ b/contrib/mir/src/syntax.lalrpop @@ -20,6 +20,7 @@ use crate::tzt::*; use Noun::*; use Noun as PT; use typed_arena::Arena; +use num_bigint::BigInt; grammar<'a>(arena: &'a Arena>); @@ -37,7 +38,7 @@ extern { "StaticError" => Tok::Noun(TztPrim(TzP::StaticError)), "amount" => Tok::Noun(TztPrim(TzP::amount)), "self" => Tok::Noun(TztPrim(TzP::self_)), - number => Tok::Number(), + number => Tok::Number(), string => Tok::String(), bytes => Tok::Bytes(>), ann => Tok::Annotation(>), @@ -134,7 +135,7 @@ tztStack : Vec<(Micheline<'a>, Micheline<'a>)> = { } mutezAmount : i64 = - =>? i64::try_from(n) + =>? i64::try_from(&n) .map_err(|_| ParserError::LexerError(LexerError::NumericLiteral(n.to_string())).into() ); use ErrorExpectation::*; diff --git a/contrib/mir/src/typechecker.rs b/contrib/mir/src/typechecker.rs index 4c63571506edf2f37c772932f01f448e725e2695..93dea6ad6b3f81074b37770e780a8b1f1a2315f2 100644 --- a/contrib/mir/src/typechecker.rs +++ b/contrib/mir/src/typechecker.rs @@ -5,9 +5,10 @@ /* */ /******************************************************************************/ +use num_bigint::{BigInt, BigUint, TryFromBigIntError}; +use num_traits::{Signed, Zero}; use std::collections::hash_map::Entry; use std::collections::{BTreeMap, BTreeSet, HashMap}; -use std::num::TryFromIntError; use tezos_crypto_rs::{base58::FromBase58CheckError, hash::FromBytesError}; pub mod type_props; @@ -39,7 +40,7 @@ pub enum TcError { #[error("FAIL instruction is not in tail position")] FailNotInTail, #[error("numeric conversion failed: {0}")] - NumericConversion(#[from] TryFromIntError), + NumericConversion(#[from] TryFromBigIntError<()>), #[error(transparent)] TypesNotEqual(#[from] TypesNotEqual), #[error("DUP 0 is forbidden")] @@ -77,7 +78,7 @@ pub enum TcError { #[error("missing top-level element: {0}")] MissingTopLevelElt(Prim), #[error("expected a natural between 0 and 1023, but got {0}")] - ExpectedU10(i128), + ExpectedU10(BigInt), #[error(transparent)] AnnotationError(#[from] AnnotationError), #[error("duplicate entrypoint: {0}")] @@ -592,7 +593,7 @@ pub(crate) fn typecheck_instruction( (App(DIP, args, _), ..) => { let (opt_height, nested) = match args { - [Int(height), Seq(nested)] => (Option::Some(validate_u10(*height)?), nested), + [Int(height), Seq(nested)] => (Option::Some(validate_u10(height)?), nested), [Seq(nested)] => (Option::None, nested), _ => unexpected_micheline!(), }; @@ -613,7 +614,7 @@ pub(crate) fn typecheck_instruction( (App(DROP, args, _), ..) => { let opt_height = match args { - [Int(height)] => Option::Some(validate_u10(*height)?), + [Int(height)] => Option::Some(validate_u10(height)?), [] => Option::None, _ => unexpected_micheline!(), }; @@ -625,10 +626,10 @@ pub(crate) fn typecheck_instruction( } // DUP instruction requires an argument that is > 0. - (App(DUP, [Int(0)], _), ..) => return Err(TcError::Dup0), + (App(DUP, [Int(n)], _), ..) if n.is_zero() => return Err(TcError::Dup0), (App(DUP, args, _), ..) => { let opt_height = match args { - [Int(height)] => Option::Some(validate_u10(*height)?), + [Int(height)] => Option::Some(validate_u10(height)?), [] => Option::None, _ => unexpected_micheline!(), }; @@ -1121,11 +1122,11 @@ pub(crate) fn typecheck_value( use TypedValue as TV; ctx.gas.consume(gas::tc_cost::VALUE_STEP)?; Ok(match (t, v) { - (T::Nat, V::Int(n)) => TV::Nat((*n).try_into()?), - (T::Int, V::Int(n)) => TV::Int(*n), + (T::Nat, V::Int(n)) => TV::Nat(BigUint::try_from(n)?), + (T::Int, V::Int(n)) => TV::Int(n.clone()), (T::Bool, V::App(Prim::True, [], _)) => TV::Bool(true), (T::Bool, V::App(Prim::False, [], _)) => TV::Bool(false), - (T::Mutez, V::Int(n)) if *n >= 0 => TV::Mutez((*n).try_into()?), + (T::Mutez, V::Int(n)) if !n.is_negative() => TV::Mutez(i64::try_from(n)?), (T::String, V::String(s)) => TV::String(s.clone()), (T::Unit, V::App(Prim::Unit, [], _)) => TV::Unit, (T::Pair(pt), V::App(Prim::Pair, [vl, rest @ ..], _)) if !rest.is_empty() => { @@ -1286,10 +1287,10 @@ pub(crate) fn typecheck_value( }) } -fn validate_u10(n: i128) -> Result { - let res = u16::try_from(n).map_err(|_| TcError::ExpectedU10(n))?; +fn validate_u10(n: &BigInt) -> Result { + let res = u16::try_from(n).map_err(|_| TcError::ExpectedU10(n.clone()))?; if res >= 1024 { - return Err(TcError::ExpectedU10(n)); + return Err(TcError::ExpectedU10(n.clone())); } Ok(res) } @@ -1505,7 +1506,7 @@ mod typecheck_tests { let mut ctx = Ctx::default(); assert_eq!( typecheck_instruction(&app!(PUSH[app!(int), 1]), &mut ctx, &mut stack), - Ok(Push(TypedValue::Int(1))) + Ok(Push(TypedValue::int(1))) ); assert_eq!(stack, expected_stack); assert!(ctx.gas.milligas() < Gas::default().milligas()); @@ -1531,7 +1532,7 @@ mod typecheck_tests { let mut ctx = Ctx::default(); assert_eq!( typecheck_instruction(&parse("DIP 1 {PUSH nat 6}").unwrap(), &mut ctx, &mut stack), - Ok(Dip(Some(1), vec![Push(TypedValue::Nat(6))])) + Ok(Dip(Some(1), vec![Push(TypedValue::nat(6))])) ); assert_eq!(stack, expected_stack); assert!(ctx.gas.milligas() < Gas::default().milligas()); @@ -1847,8 +1848,8 @@ mod typecheck_tests { &mut stack ), Ok(Push(TypedValue::new_pair( - TypedValue::Int(-5), - TypedValue::new_pair(TypedValue::Nat(3), TypedValue::Bool(false)) + TypedValue::int(-5), + TypedValue::new_pair(TypedValue::nat(3), TypedValue::Bool(false)) ))) ); assert_eq!( @@ -1869,7 +1870,7 @@ mod typecheck_tests { &mut Ctx::default(), &mut stack ), - Ok(Push(TypedValue::new_or(Or::Left(TypedValue::Int(1))))) + Ok(Push(TypedValue::new_or(Or::Left(TypedValue::int(1))))) ); assert_eq!(stack, tc_stk![Type::new_or(Type::Int, Type::Bool)]); } @@ -1897,7 +1898,7 @@ mod typecheck_tests { &mut Ctx::default(), &mut stack ), - Ok(Push(TypedValue::new_option(Some(TypedValue::Nat(3))))) + Ok(Push(TypedValue::new_option(Some(TypedValue::nat(3))))) ); assert_eq!(stack, tc_stk![Type::new_option(Type::Nat)]); } @@ -1927,8 +1928,8 @@ mod typecheck_tests { ), Ok(Seq(vec![ Push(TypedValue::new_pair( - TypedValue::Int(-5), - TypedValue::new_pair(TypedValue::Nat(3), TypedValue::Bool(false)) + TypedValue::int(-5), + TypedValue::new_pair(TypedValue::nat(3), TypedValue::Bool(false)) )), Car ])) @@ -1947,8 +1948,8 @@ mod typecheck_tests { ), Ok(Seq(vec![ Push(TypedValue::new_pair( - TypedValue::Int(-5), - TypedValue::new_pair(TypedValue::Nat(3), TypedValue::Bool(false)) + TypedValue::int(-5), + TypedValue::new_pair(TypedValue::nat(3), TypedValue::Bool(false)) )), Cdr ])) @@ -2039,7 +2040,7 @@ mod typecheck_tests { &mut Ctx::default(), &mut stack ), - Ok(IfNone(vec![Push(TypedValue::Int(5))], vec![])) + Ok(IfNone(vec![Push(TypedValue::int(5))], vec![])) ); assert_eq!(stack, tc_stk![Type::Int]); } @@ -2240,7 +2241,7 @@ mod typecheck_tests { &mut stack ), Ok(Push(TypedValue::List( - vec![TypedValue::Int(1), TypedValue::Int(2), TypedValue::Int(3),].into() + vec![TypedValue::int(1), TypedValue::int(2), TypedValue::int(3),].into() ))) ); assert_eq!(stack, tc_stk![Type::new_list(Type::Int)]); @@ -2361,8 +2362,8 @@ mod typecheck_tests { &mut stack ), Ok(Push(TypedValue::Set(BTreeSet::from([ - TypedValue::Int(1), - TypedValue::Int(2) + TypedValue::int(1), + TypedValue::int(2) ])))) ); assert_eq!(stack, tc_stk![Type::new_set(Type::Int)]); @@ -2436,8 +2437,8 @@ mod typecheck_tests { &mut stack ), Ok(Push(TypedValue::Map(BTreeMap::from([ - (TypedValue::Int(1), TypedValue::String("foo".to_owned())), - (TypedValue::Int(2), TypedValue::String("bar".to_owned())) + (TypedValue::int(1), TypedValue::String("foo".to_owned())), + (TypedValue::int(2), TypedValue::String("bar".to_owned())) ])))) ); assert_eq!(stack, tc_stk![Type::new_map(Type::Int, Type::String)]); @@ -3026,14 +3027,10 @@ mod typecheck_tests { #[test] fn test_compare_gas_exhaustion() { - let mut ctx = &mut Ctx::default(); + let ctx = &mut Ctx::default(); ctx.gas = Gas::new(gas::tc_cost::INSTR_STEP); assert_eq!( - typecheck_instruction( - &app!(COMPARE), - &mut ctx, - &mut tc_stk![Type::Unit, Type::Unit] - ), + typecheck_instruction(&app!(COMPARE), ctx, &mut tc_stk![Type::Unit, Type::Unit]), Err(TcError::OutOfGas(OutOfGas)) ); } @@ -3854,19 +3851,19 @@ mod typecheck_tests { parse("DROP 1025") .unwrap() .typecheck_instruction(&mut Ctx::default(), None, &[]), - Err(TcError::ExpectedU10(1025)) + Err(TcError::ExpectedU10(1025.into())) ); assert_eq!( parse("DIP 1024 {}") .unwrap() .typecheck_instruction(&mut Ctx::default(), None, &[]), - Err(TcError::ExpectedU10(1024)) + Err(TcError::ExpectedU10(1024.into())) ); assert_eq!( parse("DUP 65536") .unwrap() .typecheck_instruction(&mut Ctx::default(), None, &[]), - Err(TcError::ExpectedU10(65536)) + Err(TcError::ExpectedU10(65536.into())) ); } diff --git a/contrib/mir/src/tzt.rs b/contrib/mir/src/tzt.rs index 4b2bc5a4e2fbbbfa82c10734c3b17ec0aa9defe6..529581eec36978d25cd914e578e50dd7fa4bef46 100644 --- a/contrib/mir/src/tzt.rs +++ b/contrib/mir/src/tzt.rs @@ -9,6 +9,8 @@ mod expectation; use std::fmt; +use num_bigint::BigInt; + use crate::ast::michelson_address::AddressHash; use crate::ast::*; use crate::context::*; @@ -201,7 +203,7 @@ impl fmt::Display for ErrorExpectation<'_> { #[derive(Debug, PartialEq, Eq, Clone)] pub enum InterpreterErrorExpectation<'a> { - GeneralOverflow(i128, i128), + GeneralOverflow(BigInt, BigInt), MutezOverflow(i64, i64), FailedWith(Micheline<'a>), }