You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An attacker can craft a transaction with a malicious script that crashes any node
which attempts to execute it.
The crash is triggered by an underflow in the OP_COMPARE_VERIFY opcode:
fn handle_compare_height(stack: &mut ExecutionStack, block_height:
u64) -> Result<(), ScriptError> {
let target_height = stack.pop_into_number::<i64>()?;
let block_height = i64::try_from(block_height)?;
let item = StackItem::Number(block_height - target_height);
stack.push(item)
}
An attacker creates a script which puts into the stack the i64::MIN. Any
subtraction will then cause the underflow. let script = TariScript::new(vec![PushInt(i64::MIN), CompareHeight]);
The text was updated successfully, but these errors were encountered:
)
Description
---
This PR corrects the operand position of the `handle_compare_height`
function. This was identified as incorrect based on the op code
description.
Additionally, protect it from underflows, and write test cases against
all possible returns and errors.
I added underflow protection in the `handle_check_height` function as
well but after some thought this function wouldn't currently be possible
to underflow. The values passed into the function would never be lower
than 0, and then converted to i64 which would handle subtraction from 0
fine. In opposition, the `handle_compare_height` uses a value from the
stack that could be i64::MIN and then have i64::MAX subtracted from it.
Which was the originally identified problem. This is all to say the
functions aren't quite equal so it felt worth a comment for future
readers.
Motivation and Context
---
Closes#5813
How Has This Been Tested?
---
Added new tests.
What process can a PR reviewer use to test or verify this change?
---
Double check the
[docs](https://github.com/tari-project/tari/blob/development/infrastructure/tari_script/src/op_codes.rs#L146)
to validate the operand switch is a valid change.
See the new underflow protection.
Breaking Changes
---
- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify
An attacker can craft a transaction with a malicious script that crashes any node
which attempts to execute it.
The crash is triggered by an underflow in the OP_COMPARE_VERIFY opcode:
An attacker creates a script which puts into the stack the i64::MIN. Any
subtraction will then cause the underflow.
let script = TariScript::new(vec![PushInt(i64::MIN), CompareHeight]);
The text was updated successfully, but these errors were encountered: