-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from Zondax/feat/zip-0317
[ZIP-0317] Adopt proportional transfer fee convention
- Loading branch information
Showing
4 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "zip-0317.h" | ||
|
||
#define DIV_CEIL(x, y) ((x + (y - 1)) / y) | ||
|
||
#define MARGINAL_FEE 5000 | ||
#define GRACE_ACTIONS 2 | ||
#define P2PKH_STANDARD_INPUT_SIZE 150 | ||
#define P2PKH_STANDARD_OUTPUT_SIZE 34 | ||
|
||
uint64_t zip_0317_fee_raw(uint64_t tx_in_total_size, uint64_t tx_out_total_size, | ||
uint64_t n_join_split, uint64_t n_spends_sapling, | ||
uint64_t n_outputs_sapling, | ||
uint64_t n_actions_orchard) { | ||
|
||
uint64_t tin_actions = DIV_CEIL(tx_in_total_size, P2PKH_STANDARD_INPUT_SIZE); | ||
uint64_t tout_actions = | ||
DIV_CEIL(tx_out_total_size, P2PKH_STANDARD_OUTPUT_SIZE); | ||
|
||
uint64_t transparent_actions = | ||
(tin_actions > tout_actions) ? tin_actions : tout_actions; | ||
uint64_t sapling_actions = (n_spends_sapling > n_outputs_sapling) | ||
? n_spends_sapling | ||
: n_outputs_sapling; | ||
uint64_t joinsplit_actions = 2 * n_join_split; | ||
uint64_t orchard_actions = n_actions_orchard; | ||
|
||
uint64_t logical_actions = transparent_actions + sapling_actions + | ||
joinsplit_actions + orchard_actions; | ||
|
||
return MARGINAL_FEE * | ||
((GRACE_ACTIONS > logical_actions) ? GRACE_ACTIONS : logical_actions); | ||
} | ||
|
||
uint64_t zip_0317(uint64_t n_tin, uint64_t n_tout, uint64_t n_sapling_spends, | ||
uint64_t n_sapling_outs) { | ||
return zip_0317_fee_raw(n_tin * P2PKH_STANDARD_INPUT_SIZE, | ||
n_tout * P2PKH_STANDARD_OUTPUT_SIZE, 0, | ||
n_sapling_spends, n_sapling_outs, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/******************************************************************************* | ||
* (c) 2018 - 2023 Zondax AG | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
********************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
uint64_t zip_0317(uint64_t n_tin, uint64_t n_tout, uint64_t n_sapling_spends, | ||
uint64_t n_sapling_outs); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |