From 92fca8f783506006b7e89940368e0dd9a74595e2 Mon Sep 17 00:00:00 2001 From: brianp Date: Mon, 6 Nov 2023 14:30:39 +0100 Subject: [PATCH] Realign the positions and update the docs --- infrastructure/tari_script/src/op_codes.rs | 2 +- infrastructure/tari_script/src/script.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/infrastructure/tari_script/src/op_codes.rs b/infrastructure/tari_script/src/op_codes.rs index 895bea560a..e8454bd0bf 100644 --- a/infrastructure/tari_script/src/op_codes.rs +++ b/infrastructure/tari_script/src/op_codes.rs @@ -143,7 +143,7 @@ pub enum Opcode { /// if there is not a valid integer value on top of the stack. Fails with `StackUnderflow` if the stack is empty. /// Fails with `VerifyFailed` if the block height < `height`. CompareHeightVerify, - /// Pops the top of the stack as `height`, then pushes the value of (`height` - the current height) to the stack. + /// Pops the top of the stack as `height`, then pushes the value of (the current height - `height`) to the stack. /// In other words, this opcode replaces the top of the stack with the difference between `height` and the /// current height. Fails with `InvalidInput` if there is not a valid integer value on top of the stack. Fails /// with `StackUnderflow` if the stack is empty. diff --git a/infrastructure/tari_script/src/script.rs b/infrastructure/tari_script/src/script.rs index d6adfcc258..449822d40d 100644 --- a/infrastructure/tari_script/src/script.rs +++ b/infrastructure/tari_script/src/script.rs @@ -368,7 +368,7 @@ impl TariScript { // Here it is possible to underflow because the stack can take lower numbers where check // height does not use a stack number and it's minimum can't be lower than 0. - let item = match target_height.checked_sub(block_height) { + let item = match block_height.checked_sub(target_height) { Some(num) => StackItem::Number(num), None => return Err(ScriptError::CompareFailed), }; @@ -921,7 +921,7 @@ mod test { let ctx = context_with_height(u64::try_from(block_height).unwrap()); assert_eq!( script.execute_with_context(&inputs, &ctx).unwrap(), - Number(5 - block_height) + Number(block_height - 5) ); } @@ -1778,7 +1778,7 @@ mod test { let ctx = context_with_height(24_u64); let stack_item = script.execute_with_context(&inputs, &ctx); assert!(stack_item.is_ok()); - assert_eq!(stack_item.unwrap(), Number(76)) + assert_eq!(stack_item.unwrap(), Number(-76)) } #[test] @@ -1789,7 +1789,7 @@ mod test { let ctx = context_with_height(110_u64); let stack_item = script.execute_with_context(&inputs, &ctx); assert!(stack_item.is_ok()); - assert_eq!(stack_item.unwrap(), Number(-10)) + assert_eq!(stack_item.unwrap(), Number(10)) } #[test]