Skip to content

Commit

Permalink
fix: use the correct wasm profile
Browse files Browse the repository at this point in the history
And update the integer overflow tests to match. It also gives us better
test coverage of panics/traps.
  • Loading branch information
Stebalien committed Oct 18, 2024
1 parent f25a3ac commit 65c3c2f
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 102 deletions.
17 changes: 5 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,13 @@ fvm_integration_tests = { path = "testing/integration", version = "~4.4.1" }
fvm_gas_calibration_shared = { path = "testing/calibration/shared" }
fvm_test_actors = { path = "testing/test_actors" }

[profile.actor]
inherits = "release"
panic = "abort"
overflow-checks = true
lto = true
opt-level = "z"
#strip = true

# Same as in the built-in actors repo
[profile.wasm]
inherits = "release"
panic = "abort"
overflow-checks = false
lto = true
opt-level = "z"
panic = "unwind"
overflow-checks = true
lto = "thin"
opt-level = 3
strip = true
codegen-units = 1
incremental = false
232 changes: 144 additions & 88 deletions testing/integration/tests/fil_integer_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,94 +60,150 @@ fn integer_overflow() {
// Instantiate machine
tester.instantiate_machine(DummyExterns).unwrap();

// Params setup
// X is the target value.
let x: i64 = 10000000000;
let params = RawBytes::serialize(x).unwrap();

// Send message to set
let message = Message {
from: sender.1,
to: actor_address,
gas_limit: 1000000000,
method_num: 1,
params,
..Message::default()
};

// Set inner state value
let res = tester
.executor
.as_mut()
.unwrap()
.execute_message(message, ApplyKind::Explicit, 100)
.unwrap();

assert_eq!(
ExitCode::OK,
res.msg_receipt.exit_code,
"{}",
res.failure_info.unwrap()
);

// Read inner state value
let message = Message {
from: sender.1,
to: actor_address,
gas_limit: 1000000000,
method_num: 3,
sequence: 1,
..Message::default()
};

let res = tester
.executor
.as_mut()
.unwrap()
.execute_message(message, ApplyKind::Explicit, 100)
.unwrap();

let current_state_value: i64 = res.msg_receipt.return_data.deserialize().unwrap();

assert_eq!(current_state_value, x);

// Overflow inner state integer
let message = Message {
from: sender.1,
to: actor_address,
gas_limit: 1000000000,
method_num: 2,
sequence: 2,
..Message::default()
};

// Set inner state value
tester
.executor
.as_mut()
.unwrap()
.execute_message(message, ApplyKind::Explicit, 100)
.unwrap();

// Read inner state value
let message = Message {
from: sender.1,
to: actor_address,
gas_limit: 1000000000,
method_num: 3,
sequence: 3,
..Message::default()
};

let res = tester
.executor
.unwrap()
.execute_message(message, ApplyKind::Explicit, 100)
.unwrap();

let current_state_value: i64 = res.msg_receipt.return_data.deserialize().unwrap();

// Check overflow
let overflow_value: i64 = -5340232216128654848;

assert_eq!(current_state_value, overflow_value);
{
// Params setup
let params = RawBytes::serialize(x).unwrap();

// Send message to set
let message = Message {
from: sender.1,
to: actor_address,
gas_limit: 1000000000,
method_num: 1,
params,
..Message::default()
};

// Set inner state value
let res = tester
.executor
.as_mut()
.unwrap()
.execute_message(message, ApplyKind::Explicit, 100)
.unwrap();

assert_eq!(
ExitCode::OK,
res.msg_receipt.exit_code,
"{}",
res.failure_info.unwrap()
);

// Read inner state value
let message = Message {
from: sender.1,
to: actor_address,
gas_limit: 1000000000,
method_num: 3,
sequence: 1,
..Message::default()
};

let res = tester
.executor
.as_mut()
.unwrap()
.execute_message(message, ApplyKind::Explicit, 100)
.unwrap();
assert!(res.msg_receipt.exit_code.is_success());

let current_state_value: i64 = res.msg_receipt.return_data.deserialize().unwrap();

assert_eq!(current_state_value, x);
}

{
// Overflow inner state integer with checked overflows.
let message = Message {
from: sender.1,
to: actor_address,
gas_limit: 1000000000,
method_num: 4,
sequence: 2,
..Message::default()
};

let res = tester
.executor
.as_mut()
.unwrap()
.execute_message(message, ApplyKind::Explicit, 100)
.unwrap();
assert_eq!(ExitCode::SYS_ILLEGAL_INSTRUCTION, res.msg_receipt.exit_code);

// Read inner state value
let message = Message {
from: sender.1,
to: actor_address,
gas_limit: 1000000000,
method_num: 3,
sequence: 3,
..Message::default()
};

let res = tester
.executor
.as_mut()
.unwrap()
.execute_message(message, ApplyKind::Explicit, 100)
.unwrap();
assert!(res.msg_receipt.exit_code.is_success());

let current_state_value: i64 = res.msg_receipt.return_data.deserialize().unwrap();
assert_eq!(current_state_value, x);
}

{
// Overflow inner state integer with wrapping.
let message = Message {
from: sender.1,
to: actor_address,
gas_limit: 1000000000,
method_num: 2,
sequence: 4,
..Message::default()
};

// Set inner state value
let res = tester
.executor
.as_mut()
.unwrap()
.execute_message(message, ApplyKind::Explicit, 100)
.unwrap();
assert_eq!(
ExitCode::OK,
res.msg_receipt.exit_code,
"{}",
res.failure_info.unwrap()
);

// Read inner state value
let message = Message {
from: sender.1,
to: actor_address,
gas_limit: 1000000000,
method_num: 3,
sequence: 5,
..Message::default()
};

let res = tester
.executor
.as_mut()
.unwrap()
.execute_message(message, ApplyKind::Explicit, 100)
.unwrap();
assert!(res.msg_receipt.exit_code.is_success());

let current_state_value: i64 = res.msg_receipt.return_data.deserialize().unwrap();

// Check overflow
let overflow_value: i64 = -5340232216128654848;

assert_eq!(current_state_value, overflow_value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ pub fn invoke(params_pointer: u32) -> u32 {

None
}
// Overflow value
// Overflow value, wrapping
2 => {
let mut state = State::load();

state.value = (state.value >> 1i64) * (state.value + 1);
state.value = (state.value >> 1i64).wrapping_mul(state.value.wrapping_add(1));
state.save();

None
Expand All @@ -109,6 +109,15 @@ pub fn invoke(params_pointer: u32) -> u32 {
}
}
}
// Overflow value, default
4 => {
let mut state = State::load();

state.value = (state.value >> 1i64) * (state.value + 1);
state.save();

None
}
_ => abort(
ExitCode::USR_UNHANDLED_MESSAGE.value(),
Some("unrecognized method"),
Expand Down

0 comments on commit 65c3c2f

Please sign in to comment.