mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-22 06:48:03 +00:00
Merge branch 'main' into as-release-json
This commit is contained in:
@@ -16,6 +16,7 @@ Supported `polkadot-sdk` rev:`c29e72a8628835e34deb6aa7db9a78a2e4eabcee`
|
||||
- Runner `resolc` using webkit is no longer supported.
|
||||
|
||||
### Fixed
|
||||
- A missing byte swap for the create2 salt value.
|
||||
|
||||
## v0.1.0-dev.12
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.28;
|
||||
|
||||
contract Predicted {
|
||||
uint public salt;
|
||||
|
||||
constructor(uint _salt) {
|
||||
salt = _salt;
|
||||
}
|
||||
}
|
||||
|
||||
contract AddressPredictor {
|
||||
constructor(uint _salt, bytes memory _bytecode) payable {
|
||||
address deployed = address(new Predicted{salt: bytes32(_salt)}(_salt));
|
||||
address predicted = predictAddress(_salt, _bytecode);
|
||||
assert(deployed == predicted);
|
||||
}
|
||||
|
||||
function predictAddress(
|
||||
uint _foo,
|
||||
bytes memory _bytecode
|
||||
) public view returns (address predicted) {
|
||||
bytes32 addr = keccak256(
|
||||
abi.encodePacked(
|
||||
bytes1(0xff),
|
||||
address(this),
|
||||
bytes32(_foo),
|
||||
keccak256(abi.encodePacked(_bytecode, abi.encode(_foo)))
|
||||
)
|
||||
);
|
||||
predicted = address(uint160(uint(addr)));
|
||||
}
|
||||
}
|
||||
@@ -250,6 +250,17 @@ sol!(
|
||||
);
|
||||
case!("Storage.sol", Storage, transientCall, storage_transient, value: U256);
|
||||
|
||||
sol!(
|
||||
contract Predicted {
|
||||
constructor(uint _foo);
|
||||
}
|
||||
contract AddressPredictor {
|
||||
constructor(uint _foo, bytes memory _bytecode) payable;
|
||||
}
|
||||
);
|
||||
case!("AddressPredictor.sol", Predicted, constructorCall, predicted_constructor, salt: U256);
|
||||
case!("AddressPredictor.sol", AddressPredictor, constructorCall, address_predictor_constructor, salt: U256, bytecode: Bytes);
|
||||
|
||||
impl Contract {
|
||||
pub fn build(calldata: Vec<u8>, name: &'static str, code: &str) -> Self {
|
||||
Self {
|
||||
|
||||
@@ -486,3 +486,31 @@ fn transfer_denies_reentrancy() {
|
||||
}
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create2_salt() {
|
||||
let salt = U256::from(777);
|
||||
let predicted = Contract::predicted_constructor(salt).pvm_runtime;
|
||||
let predictor = Contract::address_predictor_constructor(salt, predicted.clone().into());
|
||||
Specs {
|
||||
actions: vec![
|
||||
Upload {
|
||||
origin: TestAddress::Alice,
|
||||
code: Code::Bytes(predicted),
|
||||
storage_deposit_limit: None,
|
||||
},
|
||||
Instantiate {
|
||||
origin: TestAddress::Alice,
|
||||
value: 0,
|
||||
gas_limit: Some(GAS_LIMIT),
|
||||
storage_deposit_limit: None,
|
||||
code: Code::Bytes(predictor.pvm_runtime),
|
||||
data: predictor.calldata,
|
||||
salt: OptionalHex::default(),
|
||||
},
|
||||
],
|
||||
differential: false,
|
||||
..Default::default()
|
||||
}
|
||||
.run();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ where
|
||||
let salt_pointer = match salt {
|
||||
Some(salt) => {
|
||||
let salt_pointer = context.build_alloca_at_entry(context.word_type(), "salt_pointer");
|
||||
let salt = context.build_byte_swap(salt.into())?;
|
||||
context.build_store(salt_pointer, salt)?;
|
||||
salt_pointer
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ impl Source {
|
||||
_ => None,
|
||||
},
|
||||
)
|
||||
.last()
|
||||
.next_back()
|
||||
.ok_or_else(|| anyhow::anyhow!("The last contract not found in the AST"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user