Skip to content
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

Add extra cost to is_precompile check for PrecompileSets #848

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
26 changes: 13 additions & 13 deletions e2e/test/ERC1155/TxCosts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
| uri | 27560 | 22400 | 0 |
| balanceOf | 25957 | 22433 | 0 |
| balanceOfBatch | 32585 | 24106 | 0 |
| setApprovalForAll | 47025 | 26466 | 0 |
| setApprovalForAll | 47025 | 27501 | 0 |
| isApprovedForAll | 26076 | 23184 | 0 |
| safeTransferFrom | 59163 | 31608 | 23335 |
| safeBatchTransferFrom | 50205 | 35107 | 26669 |
| mint | 33152 | 31645 | 23502 |
| mintBatch | 42210 | 32033 | 26835 |
| burn | 32581 | 26332 | 20002 |
| burnBatch | 38043 | 28962 | 23335 |
| safeTransferFrom | 59163 | 32160 | 23335 |
| safeBatchTransferFrom | 50205 | 35812 | 26670 |
| mint | 33152 | 32245 | 23503 |
| mintBatch | 42210 | 32633 | 26836 |
| burn | 32581 | 27608 | 20002 |
| burnBatch | 38043 | 31828 | 23335 |


## Generated tx costs(fees) for ERC1155 Precompiles

| Function Call | Contract cost (Drops) | Precompile cost (Drops) | Extrinsic cost (Drops) |
|:----------------------|:---------------------:|:-----------------------:|:----------------------:|
| safeTransferFrom | 880468 | 444524 | 350033 |
| safeBatchTransferFrom | 728112 | 515451 | 400049 |
| mint | 493954 | 445709 | 352539 |
| mintBatch | 589858 | 458130 | 402539 |
| burn | 475652 | 389438 | 300033 |
| burnBatch | 569231 | 433828 | 350033 |
| safeTransferFrom | 880468 | 462181 | 350038 |
| safeBatchTransferFrom | 728112 | 535973 | 400055 |
| mint | 493954 | 464911 | 352545 |
| mintBatch | 589858 | 477332 | 402545 |
| burn | 475652 | 407185 | 300038 |
| burnBatch | 569231 | 451575 | 350038 |
12 changes: 6 additions & 6 deletions e2e/test/ERC20/TxCosts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
| totalSupply | 23717 | 22388 | 0 |
| balanceOf | 25860 | 23974 | 0 |
| allowance | 26064 | 23273 | 0 |
| approval | 47152 | 26364 | 20170 |
| transfer | 52698 | 44134 | 20173 |
| transferFrom | 44716 | 51794 | 23174 |
| approval | 47152 | 26470 | 20170 |
| transfer | 52698 | 43641 | 20172 |
| transferFrom | 44716 | 51726 | 23340 |
| name | 25926 | 22388 | 0 |
| decimals | 22354 | 22388 | 0 |
| symbol | 25945 | 22388 | 0 |
Expand All @@ -17,6 +17,6 @@

| Function Call | Contract cost (Drops) | Precompile cost (Drops) | Extrinsic cost (Drops) |
|:--------------|:---------------------:|:-----------------------:|:----------------------:|
| approval | 702835 | 391134 | 302559 |
| transfer | 781323 | 633958 | 302595 |
| transferFrom | 647164 | 761966 | 347616 |
| approval | 702835 | 396804 | 302557 |
| transfer | 781323 | 622692 | 302592 |
| transferFrom | 647164 | 760526 | 350114 |
30 changes: 15 additions & 15 deletions e2e/test/ERC721/TxCosts.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
| ownerOf | 25847 | 23242 | 0 |
| getApproved | 27395 | 23242 | 0 |
| isApprovedForAll | 26082 | 23973 | 0 |
| mint | 53193 | 28898 | 17335 |
| burn | 37870 | 35114 | 17169 |
| approve | 50740 | 27831 | 23835 |
| setApprovalForAll | 47011 | 26360 | 23335 |
| safetransferFrom | 67181 | 35303 | 0 |
| transferFrom | 66839 | 34917 | 20669 |
| mint | 53193 | 31731 | 17336 |
| burn | 37870 | 35731 | 17170 |
| approve | 50740 | 28884 | 23835 |
| setApprovalForAll | 47011 | 26467 | 23335 |
| safetransferFrom | 67181 | 36625 | 0 |
| transferFrom | 66839 | 35560 | 20670 |
| name | 25932 | 22388 | 0 |
| symbol | 25938 | 22388 | 0 |
| tokenURI | 25964 | 23242 | 0 |
| owner | 23728 | 22388 | 0 |
| transferOwnership | 29147 | 27675 | 19835 |
| renounceOwnership | 30272 | 27559 | 19668 |
| transferOwnership | 29147 | 28498 | 19835 |
| renounceOwnership | 30272 | 28372 | 19835 |


## Generated tx costs(fees) for ERC721 Precompiles

| Function Call | Contract cost (Drops) | Precompile cost (Drops) | Extrinsic cost (Drops) |
|:------------------|:---------------------:|:-----------------------:|:----------------------:|
| mint | 791884 | 431188 | 260036 |
| burn | 490684 | 515676 | 257548 |
| approve | 739543 | 417326 | 357535 |
| setApprovalForAll | 699609 | 390954 | 350028 |
| transferFrom | 884488 | 509930 | 310049 |
| transferOwnership | 436153 | 410231 | 297532 |
| renounceOwnership | 352310 | 404890 | 295032 |
| mint | 791884 | 448454 | 260041 |
| burn | 490684 | 533648 | 257553 |
| approve | 739543 | 430633 | 357539 |
| setApprovalForAll | 699609 | 396639 | 350030 |
| transferFrom | 884488 | 528637 | 310054 |
| transferOwnership | 436153 | 424962 | 297536 |
| renounceOwnership | 352310 | 419621 | 297536 |
5 changes: 3 additions & 2 deletions evm-precompiles/erc1155/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,17 @@ where
}

fn is_precompile(&self, address: H160, _remaining_gas: u64) -> IsPrecompileResult {
let extra_cost = RuntimeHelper::<Runtime>::db_read_gas_cost();
if let Some(collection_id) =
Runtime::evm_id_to_runtime_id(Address(address), ERC1155_PRECOMPILE_ADDRESS_PREFIX)
{
// Check whether the collection exists
IsPrecompileResult::Answer {
is_precompile: pallet_sft::Pallet::<Runtime>::collection_exists(collection_id),
extra_cost: 0, // TODO: account gas for above storage read?
extra_cost
}
} else {
IsPrecompileResult::Answer { is_precompile: false, extra_cost: 0 }
IsPrecompileResult::Answer { is_precompile: false, extra_cost }
JasonTulp marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions evm-precompiles/erc20/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,17 @@ where
}

fn is_precompile(&self, address: H160, _remaining_gas: u64) -> IsPrecompileResult {
let extra_cost = RuntimeHelper::<Runtime>::db_read_gas_cost();
if let Some(asset_id) =
Runtime::evm_id_to_runtime_id(Address(address), ERC20_PRECOMPILE_ADDRESS_PREFIX)
{
// Check if the asset exists
IsPrecompileResult::Answer {
is_precompile: <pallet_assets_ext::Pallet<Runtime>>::asset_exists(asset_id),
extra_cost: 0, // TODO: account gas for above storage read?
extra_cost
}
} else {
IsPrecompileResult::Answer { is_precompile: false, extra_cost: 0 }
IsPrecompileResult::Answer { is_precompile: false, extra_cost }
JasonTulp marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions evm-precompiles/erc721/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,17 @@ where
}

fn is_precompile(&self, address: H160, _remaining_gas: u64) -> IsPrecompileResult {
let extra_cost = RuntimeHelper::<Runtime>::db_read_gas_cost();
if let Some(collection_id) =
Runtime::evm_id_to_runtime_id(Address(address), ERC721_PRECOMPILE_ADDRESS_PREFIX)
{
// Check whether the collection exists
IsPrecompileResult::Answer {
is_precompile: pallet_nft::Pallet::<Runtime>::collection_exists(collection_id),
extra_cost: 0, // TODO: account gas for above storage read?
extra_cost
}
} else {
IsPrecompileResult::Answer { is_precompile: false, extra_cost: 0 }
IsPrecompileResult::Answer { is_precompile: false, extra_cost }
JasonTulp marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down