Skip to content

Commit

Permalink
[gh-2295] roolback from parse to new.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feliciss committed Jul 29, 2024
1 parent 667f511 commit b808759
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,14 @@ module rooch_framework::bitcoin_address {
let expected_xonly_pubkey = x"ffa540e2d3df158dfb202fc1a2cbb20c4920ba35e8f75bb11101bfa47d71449a";
let pk_list = vector::empty<vector<u8>>();

let pk_1 = x"03935f972da013f80ae011890fa89b67a27b7be6ccb24d3274d18b2d4067f261a9";
let pk_2 = x"02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9";
let pk_3 = x"02dff1d77f2a671c5f36183726db2341be58feae1da2deced843240f7b502ba659";
let pk_1 = x"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9";
let pk_2 = x"ffa540e2d3df158dfb202fc1a2cbb20c4920ba35e8f75bb11101bfa47d71449a";

vector::push_back(&mut pk_list, pk_1);
vector::push_back(&mut pk_list, pk_2);
vector::push_back(&mut pk_list, pk_3);

let xonly_pubkey = derive_multisig_xonly_pubkey_from_xonly_pubkeys(&pk_list, 3);
// TODO: fix MISSING_DEPENDENCY (code 1021) error
let xonly_pubkey = derive_multisig_xonly_pubkey_from_xonly_pubkeys(&pk_list, 2);

std::debug::print(&xonly_pubkey);
std::debug::print(&expected_xonly_pubkey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::natives::gas_parameter::native::MUL;
use crate::natives::rooch_framework::bitcoin_address::GasParameters;

crate::natives::gas_parameter::native::define_gas_parameters_for_natives!(GasParameters, "bitcoin_address", [
[.parse.base, "parse.base", 1000 * MUL],
[.parse.per_byte, "parse.per_byte", 30 * MUL],
[.new.base, "parse.base", 1000 * MUL],
[.new.per_byte, "parse.per_byte", 30 * MUL],
[.verify_bitcoin_address_with_public_key.base, "verify_bitcoin_address_with_public_key.base", 1000 * MUL],
[.verify_bitcoin_address_with_public_key.per_byte, "verify_bitcoin_address_with_public_key.per_byte", 30 * MUL],
[.derive_multisig_xonly_pubkey_from_xonly_pubkeys.base, "derive_multisig_xonly_pubkey_from_xonly_pubkeys.base", 1000 * MUL],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ use move_vm_types::{
pop_arg,
values::{StructRef, Value, VectorRef},
};
use moveos_stdlib::natives::{
helpers::{make_module_natives, make_native},
moveos_stdlib::move_module::ConstantOps,
};
use moveos_stdlib::natives::helpers::{make_module_natives, make_native};
use moveos_types::state::{MoveState, MoveStructState};
use musig2::{secp::Point, KeyAggContext};
use rooch_types::address::BitcoinAddress;
Expand Down Expand Up @@ -120,7 +117,7 @@ pub fn derive_multisig_xonly_pubkey_from_xonly_pubkeys(
let threshold_bytes = pop_arg!(args, u64);
let pk_list = pop_arg!(args, Vec<Value>);

let cost = gas_params.base + gas_params.per_byte * NumBytes::new(threshold_bytes);
let mut cost = gas_params.base + gas_params.per_byte * NumBytes::new(threshold_bytes);

if pk_list.len() < threshold_bytes as usize {
return Ok(NativeResult::err(cost, E_INVALID_THRESHOLD));
Expand All @@ -133,6 +130,7 @@ pub fn derive_multisig_xonly_pubkey_from_xonly_pubkeys(
Ok(v) => {
match Point::lift_x_hex(&v.as_hex().to_string()) {
Ok(pk_args) => {
cost += gas_params.per_byte * NumBytes::new(v.len() as u64);
pubkeys.push(pk_args);
}
Err(_) => {
Expand Down Expand Up @@ -217,7 +215,7 @@ impl FromBytesGasParameters {

#[derive(Debug, Clone)]
pub struct GasParameters {
pub parse: FromBytesGasParameters,
pub new: FromBytesGasParameters,
pub verify_bitcoin_address_with_public_key: FromBytesGasParameters,
pub derive_multisig_xonly_pubkey_from_xonly_pubkeys: FromBytesGasParameters,
pub derive_bitcoin_taproot_address_from_multisig_xonly_pubkey: FromBytesGasParameters,
Expand All @@ -226,7 +224,7 @@ pub struct GasParameters {
impl GasParameters {
pub fn zeros() -> Self {
Self {
parse: FromBytesGasParameters::zeros(),
new: FromBytesGasParameters::zeros(),
verify_bitcoin_address_with_public_key: FromBytesGasParameters::zeros(),
derive_multisig_xonly_pubkey_from_xonly_pubkeys: FromBytesGasParameters::zeros(),
derive_bitcoin_taproot_address_from_multisig_xonly_pubkey:
Expand All @@ -237,7 +235,7 @@ impl GasParameters {

pub fn make_all(gas_params: GasParameters) -> impl Iterator<Item = (String, NativeFunction)> {
let natives = [
("parse", make_native(gas_params.parse, parse)),
("parse", make_native(gas_params.new, parse)),
(
"verify_bitcoin_address_with_public_key",
make_native(
Expand Down

0 comments on commit b808759

Please sign in to comment.