Skip to content

Compile panic expression to ABI error codes #7118

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1,938 changes: 1,224 additions & 714 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@ sway-ir-macros = { path = "sway-ir/sway-ir-macros", version = "0.68.4" }
#

# Dependencies from the `fuel-abi-types` repository:
fuel-abi-types = "0.8"
fuel-abi-types = "0.12"

# Dependencies from the `fuel-core` repository:
#
# Although ALL verions are "X.Y", we need the complete semver for
# Although ALL versions are "X.Y", we need the complete semver for
# fuel-core-client as the GitHub Actions workflow parses this value to pull down
# the correct tarball
# the correct tarball.
fuel-core-client = { version = "0.43.2", default-features = false }
fuel-core-types = { version = "0.43", default-features = false }

# Dependencies from the `fuels-rs` repository:

fuels = "0.72"
fuels-core = "0.72"
fuels-accounts = "0.72"
fuels = "0.73"
fuels-core = "0.73"
fuels-accounts = "0.73"

# Dependencies from the `fuel-vm` repository:
fuel-asm = "0.60"
Expand Down
42 changes: 24 additions & 18 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1768,9 +1768,15 @@ pub fn compile(
metrics
);

let mut asm = match asm_res {
Err(_) => return fail(handler),
Ok(asm) => asm,
};

const ENCODING_V0: &str = "0";
const ENCODING_V1: &str = "1";
const SPEC_VERSION: &str = "1";
const SPEC_VERSION_ERROR_TYPE: &str = "1.1";

let mut program_abi = match pkg.target {
BuildTarget::Fuel => {
Expand All @@ -1782,6 +1788,7 @@ pub fn compile(
&handler,
&mut AbiContext {
program: typed_program,
panic_occurrences: &asm.panic_occurrences,
abi_with_callpaths: true,
type_ids_to_full_type_str: HashMap::<String, String>::new(),
},
Expand All @@ -1791,7 +1798,11 @@ pub fn compile(
} else {
ENCODING_V0.into()
},
SPEC_VERSION.into(),
if experimental.error_type {
SPEC_VERSION_ERROR_TYPE.into()
} else {
SPEC_VERSION.into()
}
),
Some(sway_build_config.clone()),
metrics
Expand All @@ -1805,11 +1816,8 @@ pub fn compile(
BuildTarget::EVM => {
// Merge the ABI output of ASM gen with ABI gen to handle internal constructors
// generated by the ASM backend.
let mut ops = match &asm_res {
Ok(ref asm) => match &asm.0.abi {
Some(ProgramABI::Evm(ops)) => ops.clone(),
_ => vec![],
},
let mut ops = match &asm.finalized_asm.abi {
Some(ProgramABI::Evm(ops)) => ops.clone(),
_ => vec![],
};

Expand All @@ -1828,20 +1836,13 @@ pub fn compile(
}
};

let entries = asm_res
.as_ref()
.map(|asm| asm.0.entries.clone())
.unwrap_or_default();
let entries = entries
let entries = asm
.finalized_asm
.entries
.iter()
.map(|finalized_entry| PkgEntry::from_finalized_entry(finalized_entry, engines))
.collect::<anyhow::Result<_>>()?;

let mut asm = match asm_res {
Err(_) => return fail(handler),
Ok(asm) => asm,
};

let bc_res = time_expr!(
pkg.name,
"compile asm to bytecode",
Expand Down Expand Up @@ -1976,12 +1977,16 @@ fn report_assembly_information(
data_section: sway_core::asm_generation::DataSectionInformation {
size: data_section_size,
used: compiled_asm
.0
.finalized_asm
.data_section
.iter_all_entries()
.map(|entry| calculate_entry_size(&entry))
.sum(),
value_pairs: compiled_asm.0.data_section.iter_all_entries().collect(),
value_pairs: compiled_asm
.finalized_asm
.data_section
.iter_all_entries()
.collect(),
},
};

Expand Down Expand Up @@ -2866,6 +2871,7 @@ mod test {
configurables: None,
logged_types: None,
messages_types: None,
error_codes: None,
}),
storage_slots: vec![],
warnings: vec![],
Expand Down
24 changes: 22 additions & 2 deletions forc-plugins/forc-client/src/op/call/call_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use fuels::{
use fuels_core::{
codec::{
encode_fn_selector, log_formatters_lookup, ABIDecoder, ABIEncoder, DecoderConfig,
EncoderConfig, LogDecoder,
EncoderConfig, ErrorDetails, LogDecoder,
},
types::{
bech32::Bech32ContractId,
Expand Down Expand Up @@ -84,7 +84,27 @@ pub async fn call_function(

// Setup variable output policy and log decoder
let variable_output_policy = VariableOutputPolicy::Exactly(call_parameters.amount as usize);
let log_decoder = LogDecoder::new(log_formatters_lookup(vec![], contract_id));
let error_codes = unified_program_abi
.error_codes
.map_or(HashMap::new(), |error_codes| {
error_codes
.iter()
.map(|(revert_code, error_details)| {
(
*revert_code,
ErrorDetails::new(
error_details.pos.pkg.clone(),
error_details.pos.file.clone(),
error_details.pos.line,
error_details.pos.column,
error_details.log_id.clone(),
error_details.msg.clone(),
),
)
})
.collect()
});
let log_decoder = LogDecoder::new(log_formatters_lookup(vec![], contract_id), error_codes);

// Get external contracts (either provided or auto-detected)
let external_contracts = match external_contracts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
],
"functions": [
{
"name": "main",
"inputs": [
{
"name": "switch",
Expand All @@ -96,7 +97,6 @@
"concreteTypeId": "37cd1cba311039a851ac8bfa614cc41359b4ad95c8656fcef2e8f504fe7a1272"
}
],
"name": "main",
"output": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903",
"attributes": null
}
Expand All @@ -107,22 +107,27 @@
{
"name": "BOOL",
"concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903",
"offset": 1896
"offset": 1896,
"indirect": false
},
{
"name": "U8",
"concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b",
"offset": 1936
"offset": 1936,
"indirect": false
},
{
"name": "STRUCT",
"concreteTypeId": "563310524b4f4447a10d0e50556310253dfb3b5eb4b29c3773222b737c8b7075",
"offset": 1920
"offset": 1920,
"indirect": false
},
{
"name": "ENUM",
"concreteTypeId": "37cd1cba311039a851ac8bfa614cc41359b4ad95c8656fcef2e8f504fe7a1272",
"offset": 1904
"offset": 1904,
"indirect": false
}
]
],
"errorCodes": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
],
"functions": [
{
"name": "main",
"inputs": [
{
"name": "a",
Expand All @@ -235,7 +236,6 @@
"concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b"
}
],
"name": "main",
"output": "25fbba860b8a1983ebcfa3f135136266a7edb7ca3a7e1f8ec988135c12a9f873",
"attributes": null
}
Expand All @@ -251,62 +251,75 @@
{
"name": "BOOL",
"concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903",
"offset": 7792
"offset": 7792,
"indirect": false
},
{
"name": "U8",
"concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b",
"offset": 7904
"offset": 7904,
"indirect": false
},
{
"name": "U16",
"concreteTypeId": "29881aad8730c5ab11d275376323d8e4ff4179aae8ccb6c13fe4902137e162ef",
"offset": 7848
"offset": 7848,
"indirect": false
},
{
"name": "U32",
"concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc",
"offset": 7888
"offset": 7888,
"indirect": false
},
{
"name": "U64",
"concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0",
"offset": 7896
"offset": 7896,
"indirect": false
},
{
"name": "U256",
"concreteTypeId": "1b5759d94094368cfd443019e7ca5ec4074300e544e5ea993a979f5da627261e",
"offset": 7856
"offset": 7856,
"indirect": false
},
{
"name": "B256",
"concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b",
"offset": 7760
"offset": 7760,
"indirect": false
},
{
"name": "STR_4",
"concreteTypeId": "94f0fa95c830be5e4f711963e83259fe7e8bc723278ab6ec34449e791a99b53a",
"offset": 7832
"offset": 7832,
"indirect": false
},
{
"name": "TUPLE",
"concreteTypeId": "e0128f7be9902d1fe16326cafe703b52038064a7997b03ebfc1c9dd607e1536c",
"offset": 7840
"offset": 7840,
"indirect": false
},
{
"name": "ARRAY",
"concreteTypeId": "d9fac01ab38fe10950758ae9604da330d6406a71fda3ef1ea818121261132d56",
"offset": 7744
"offset": 7744,
"indirect": false
},
{
"name": "STRUCT",
"concreteTypeId": "563310524b4f4447a10d0e50556310253dfb3b5eb4b29c3773222b737c8b7075",
"offset": 7816
"offset": 7816,
"indirect": false
},
{
"name": "ENUM",
"concreteTypeId": "37cd1cba311039a851ac8bfa614cc41359b4ad95c8656fcef2e8f504fe7a1272",
"offset": 7800
"offset": 7800,
"indirect": false
}
]
],
"errorCodes": {}
}
Loading
Loading