mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-15 08:01:09 +00:00
remove support for legacy evm assembly (#186)
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::solc::pipeline::Pipeline as SolcPipeline;
|
||||
use crate::warning::Warning;
|
||||
|
||||
pub const ECRECOVER_TEST_SOURCE: &str = r#"
|
||||
@@ -30,7 +29,6 @@ fn ecrecover() {
|
||||
ECRECOVER_TEST_SOURCE,
|
||||
"Warning: It looks like you are using 'ecrecover' to validate a signature of a user account.",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::Yul,
|
||||
false,
|
||||
None,
|
||||
).expect("Test failure")
|
||||
@@ -44,7 +42,6 @@ fn ecrecover_suppressed() {
|
||||
ECRECOVER_TEST_SOURCE,
|
||||
"Warning: It looks like you are using 'ecrecover' to validate a signature of a user account.",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::Yul,
|
||||
false,
|
||||
Some(vec![Warning::EcRecover]),
|
||||
).expect("Test failure")
|
||||
@@ -76,7 +73,6 @@ fn send() {
|
||||
SEND_TEST_SOURCE,
|
||||
"Warning: It looks like you are using '<address payable>.send/transfer(<X>)' without providing",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::Yul,
|
||||
false,
|
||||
None,
|
||||
).expect("Test failure")
|
||||
@@ -90,7 +86,6 @@ fn send_suppressed() {
|
||||
SEND_TEST_SOURCE,
|
||||
"Warning: It looks like you are using '<address payable>.send/transfer(<X>)' without providing",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::Yul,
|
||||
false,
|
||||
Some(vec![Warning::SendTransfer]),
|
||||
).expect("Test failure")
|
||||
@@ -121,7 +116,6 @@ fn transfer() {
|
||||
TRANSFER_TEST_SOURCE,
|
||||
"Warning: It looks like you are using '<address payable>.send/transfer(<X>)' without providing",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::Yul,
|
||||
false,
|
||||
None,
|
||||
).expect("Test failure")
|
||||
@@ -135,7 +129,6 @@ fn transfer_suppressed() {
|
||||
TRANSFER_TEST_SOURCE,
|
||||
"Warning: It looks like you are using '<address payable>.send/transfer(<X>)' without providing",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::Yul,
|
||||
false,
|
||||
Some(vec![Warning::SendTransfer]),
|
||||
).expect("Test failure")
|
||||
@@ -163,7 +156,6 @@ fn extcodesize() {
|
||||
EXTCODESIZE_TEST_SOURCE,
|
||||
"Warning: Your code or one of its dependencies uses the 'extcodesize' instruction,",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::Yul,
|
||||
false,
|
||||
None,
|
||||
)
|
||||
@@ -176,7 +168,6 @@ fn extcodesize_suppressed() {
|
||||
EXTCODESIZE_TEST_SOURCE,
|
||||
"Warning: Your code or one of its dependencies uses the 'extcodesize' instruction,",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::Yul,
|
||||
false,
|
||||
Some(vec![Warning::ExtCodeSize]),
|
||||
)
|
||||
@@ -200,7 +191,6 @@ fn tx_origin() {
|
||||
TX_ORIGIN_TEST_SOURCE,
|
||||
"Warning: You are checking for 'tx.origin' in your code, which might lead to",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::Yul,
|
||||
false,
|
||||
None,
|
||||
)
|
||||
@@ -213,7 +203,6 @@ fn tx_origin_suppressed() {
|
||||
TX_ORIGIN_TEST_SOURCE,
|
||||
"Warning: You are checking for 'tx.origin' in your code, which might lead to",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::Yul,
|
||||
false,
|
||||
Some(vec![Warning::TxOrigin]),
|
||||
)
|
||||
@@ -244,7 +233,6 @@ fn tx_origin_assembly() {
|
||||
TX_ORIGIN_ASSEMBLY_TEST_SOURCE,
|
||||
"Warning: You are checking for 'tx.origin' in your code, which might lead to",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::Yul,
|
||||
false,
|
||||
None,
|
||||
)
|
||||
@@ -257,136 +245,8 @@ fn tx_origin_assembly_suppressed() {
|
||||
TX_ORIGIN_ASSEMBLY_TEST_SOURCE,
|
||||
"Warning: You are checking for 'tx.origin' in your code, which might lead to",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::Yul,
|
||||
false,
|
||||
Some(vec![Warning::TxOrigin]),
|
||||
)
|
||||
.expect("Test failure"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn internal_function_pointer_argument() {
|
||||
let source_code = r#"
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
contract InternalFunctionPointerExample {
|
||||
function add(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
function executeOperation(
|
||||
function (uint256, uint256) internal pure returns (uint256) operation,
|
||||
uint256 a,
|
||||
uint256 b
|
||||
) private pure returns (uint256) {
|
||||
return operation(a, b);
|
||||
}
|
||||
|
||||
function testAdd(uint256 a, uint256 b) public pure returns (uint256) {
|
||||
return executeOperation(add, a, b);
|
||||
}
|
||||
|
||||
function testSub(uint256 a, uint256 b) public pure returns (uint256) {
|
||||
return executeOperation(sub, a, b);
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
assert!(super::check_solidity_warning(
|
||||
source_code,
|
||||
"Error: Internal function pointers are not supported in EVM legacy assembly pipeline.",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::EVMLA,
|
||||
true,
|
||||
None,
|
||||
)
|
||||
.expect("Test failure"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn internal_function_pointer_stack() {
|
||||
let source_code = r#"
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
contract StackFunctionPointerExample {
|
||||
function add(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
function testAdd(uint256 a, uint256 b) public pure returns (uint256) {
|
||||
function (uint256, uint256) internal pure returns (uint256) operation = add;
|
||||
return operation(a, b);
|
||||
}
|
||||
|
||||
function testSub(uint256 a, uint256 b) public pure returns (uint256) {
|
||||
function (uint256, uint256) internal pure returns (uint256) operation = sub;
|
||||
return operation(a, b);
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
assert!(super::check_solidity_warning(
|
||||
source_code,
|
||||
"Error: Internal function pointers are not supported in EVM legacy assembly pipeline.",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::EVMLA,
|
||||
true,
|
||||
None,
|
||||
)
|
||||
.expect("Test failure"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn internal_function_pointer_storage() {
|
||||
let source_code = r#"
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
contract StorageFunctionPointerExample {
|
||||
function add(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
function (uint256, uint256) internal pure returns (uint256) operation;
|
||||
bool private isOperationSet = false;
|
||||
|
||||
function setOperation(bool isAdd) public {
|
||||
if (isAdd) {
|
||||
operation = add;
|
||||
} else {
|
||||
operation = sub;
|
||||
}
|
||||
isOperationSet = true;
|
||||
}
|
||||
|
||||
function executeOperation(uint256 a, uint256 b) public view returns (uint256) {
|
||||
require(isOperationSet, "Operation not set");
|
||||
return operation(a, b);
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
assert!(super::check_solidity_warning(
|
||||
source_code,
|
||||
"Error: Internal function pointers are not supported in EVM legacy assembly pipeline.",
|
||||
BTreeMap::new(),
|
||||
SolcPipeline::EVMLA,
|
||||
true,
|
||||
None,
|
||||
)
|
||||
.expect("Test failure"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user