Skip to content

Commit

Permalink
[moveos_std] fix error type
Browse files Browse the repository at this point in the history
  • Loading branch information
vegetabledogdog committed May 26, 2024
1 parent 1ee548e commit 6aacf7d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
12 changes: 6 additions & 6 deletions frameworks/moveos-stdlib/doc/evm.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@
## Constants


<a name="0x2_evm_E_EC_ADD_FAILED"></a>
<a name="0x2_evm_ErrorEcAddFailed"></a>



<pre><code><b>const</b> <a href="evm.md#0x2_evm_E_EC_ADD_FAILED">E_EC_ADD_FAILED</a>: u64 = 6;
<pre><code><b>const</b> <a href="evm.md#0x2_evm_ErrorEcAddFailed">ErrorEcAddFailed</a>: u64 = 6;
</code></pre>



<a name="0x2_evm_E_EC_PAIRING_FAILED"></a>
<a name="0x2_evm_ErrorEcPairingFailed"></a>



<pre><code><b>const</b> <a href="evm.md#0x2_evm_E_EC_PAIRING_FAILED">E_EC_PAIRING_FAILED</a>: u64 = 8;
<pre><code><b>const</b> <a href="evm.md#0x2_evm_ErrorEcPairingFailed">ErrorEcPairingFailed</a>: u64 = 8;
</code></pre>



<a name="0x2_evm_E_EXPECT_32_BYTES"></a>
<a name="0x2_evm_ErrorInvalidCoordinate"></a>



<pre><code><b>const</b> <a href="evm.md#0x2_evm_E_EXPECT_32_BYTES">E_EXPECT_32_BYTES</a>: u64 = 11;
<pre><code><b>const</b> <a href="evm.md#0x2_evm_ErrorInvalidCoordinate">ErrorInvalidCoordinate</a>: u64 = 11;
</code></pre>


Expand Down
16 changes: 8 additions & 8 deletions frameworks/moveos-stdlib/sources/evm.move
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
// Evm Precompiled Contracts https://www.evm.codes/precompiled?fork=cancun
module moveos_std::evm {

const E_EC_ADD_FAILED: u64 = 6;
const E_EC_PAIRING_FAILED: u64 = 8;
const ErrorEcAddFailed: u64 = 6;
const ErrorEcPairingFailed: u64 = 8;

// The coordinate must be 32 bytes.
const E_EXPECT_32_BYTES: u64 = 11;
const ErrorInvalidCoordinate: u64 = 11;

/// @param data: Arbitrary binary data to hash
///
Expand Down Expand Up @@ -46,8 +46,8 @@ module moveos_std::evm {
let y2 = x"0000000000000000000000000000000000000000000000000000000000000002";

let (x3, y3) = ec_add(x1, y1, x2, y2);
assert!(x3 == x"030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd3", E_EC_ADD_FAILED);
assert!(y3 == x"15ed738c0e0a7c92e7845f96b2ae9c0a68a6a449e3538fc7ff3ebf7a5a18a2c4", E_EC_ADD_FAILED);
assert!(x3 == x"030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd3", ErrorEcAddFailed);
assert!(y3 == x"15ed738c0e0a7c92e7845f96b2ae9c0a68a6a449e3538fc7ff3ebf7a5a18a2c4", ErrorEcAddFailed);
}

#[test]
Expand Down Expand Up @@ -78,11 +78,11 @@ module moveos_std::evm {
vector::append<u8>(&mut x1, y6);

let success = ec_pairing(x1);
assert!(success == x"0000000000000000000000000000000000000000000000000000000000000001", E_EC_PAIRING_FAILED);
assert!(success == x"0000000000000000000000000000000000000000000000000000000000000001", ErrorEcPairingFailed);
}

#[test]
#[expected_failure(abort_code = E_EXPECT_32_BYTES, location = Self)]
#[expected_failure(abort_code = ErrorInvalidCoordinate, location = Self)]
fun test_ec_add_input_not_match() {
let x1 = x"01";
let y1 = x"02";
Expand All @@ -93,7 +93,7 @@ module moveos_std::evm {
}

#[test]
#[expected_failure(abort_code = E_EC_PAIRING_FAILED, location = Self)]
#[expected_failure(abort_code = ErrorEcPairingFailed, location = Self)]
fun test_ec_pairing_input_not_match() {
let x1 = x"2cf44499d5d27bb186308b7af7af02ac5bc9eeb6a3d147c186b21fb1b76e18da";
let y1 = x"2c0f001f52110ccfe69108924926e45f0b0c868df0e7bde1fe16d3242dc715f6";
Expand Down
6 changes: 2 additions & 4 deletions frameworks/moveos-stdlib/src/natives/moveos_stdlib/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use std::collections::VecDeque;

pub const E_EC_ADD_FAILED: u64 = 6;
pub const E_EC_PAIRING_FAILED: u64 = 8;
pub const E_EXPECT_32_BYTES: u64 = 11;

pub const E_INVALID_COORDINATE: u64 = 11;

/***************************************************************************************************
* native fun ec_add
Expand All @@ -39,7 +38,7 @@ pub fn native_ec_add(
let x1 = pop_arg!(args, Vec<u8>);

if y2.len() != 32 || x2.len() != 32 || y1.len() != 32 || x1.len() != 32 {
return Ok(NativeResult::err(0.into(), E_EXPECT_32_BYTES));
return Ok(NativeResult::err(0.into(), E_INVALID_COORDINATE));
}

let cost = gas_params.base + (gas_params.per_byte * NumBytes::new(128_u64));
Expand All @@ -62,7 +61,6 @@ pub fn native_ec_add(
}
}


/***************************************************************************************************
* native fun ec_pairing
* Implementation of the Move native function `ec_pairing(data: vector<u8>): vector<u8>`
Expand Down

0 comments on commit 6aacf7d

Please sign in to comment.