mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Test createAddress
Benchmarks gas usage Note the estimator needs to be updated as this is now variable-gas to the state.
This commit is contained in:
@@ -414,7 +414,7 @@ contract Router is IRouterWithoutCollisions {
|
||||
* detrimental to other `OutInstruction`s within the same batch) is sufficiently concerning to
|
||||
* justify this.
|
||||
*/
|
||||
function createAddress(uint256 nonce) private view returns (address) {
|
||||
function createAddress(uint256 nonce) internal view returns (address) {
|
||||
unchecked {
|
||||
/*
|
||||
The hashed RLP-encoding is:
|
||||
@@ -438,9 +438,10 @@ contract Router is IRouterWithoutCollisions {
|
||||
bitsNeeded += 8;
|
||||
}
|
||||
uint256 bytesNeeded = bitsNeeded / 8;
|
||||
rlpEncodingLen = 22 + bytesNeeded;
|
||||
// 22 + 1 + the amount of bytes needed
|
||||
rlpEncodingLen = 23 + bytesNeeded;
|
||||
// Shift from byte 31 to byte 22
|
||||
rlpEncoding |= 0x80 + (bytesNeeded << 72);
|
||||
rlpEncoding |= (0x80 + bytesNeeded) << 72;
|
||||
// Shift past the unnecessary bytes
|
||||
rlpEncoding |= nonce << (72 - bitsNeeded);
|
||||
}
|
||||
|
||||
13
processor/ethereum/router/contracts/tests/CreateAddress.sol
Normal file
13
processor/ethereum/router/contracts/tests/CreateAddress.sol
Normal file
@@ -0,0 +1,13 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "Router.sol";
|
||||
|
||||
// Wrap the Router with a contract which exposes the address
|
||||
contract CreateAddress is Router {
|
||||
constructor() Router(bytes32(uint256(1))) {}
|
||||
|
||||
function createAddressForSelf(uint256 nonce) external returns (address) {
|
||||
return Router.createAddress(nonce);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user