Remove unused gasPrice fields (#527)
This commit is contained in:
parent
82e1864a51
commit
910cacdc37
|
@ -11,11 +11,9 @@ library ArbitraryMessage {
|
|||
* offset 104 : 4 bytes :: uint32 - gasLimit
|
||||
* offset 108 : 1 bytes :: uint8 - source chain id length (X)
|
||||
* offset 109 : 1 bytes :: uint8 - destination chain id length (Y)
|
||||
* offset 110 : 1 bytes :: bytes1 - dataType
|
||||
* (optional) 111 : 32 bytes :: uint256 - gasPrice
|
||||
* (optional) 111 : 1 bytes :: bytes1 - gasPriceSpeed
|
||||
* offset 111/143/112 : X bytes :: bytes - source chain id
|
||||
* offset 111/143/112 + X : Y bytes :: bytes - destination chain id
|
||||
* offset 110 : 1 bytes :: uint8 - dataType
|
||||
* offset 111 : X bytes :: bytes - source chain id
|
||||
* offset 111 + X : Y bytes :: bytes - destination chain id
|
||||
|
||||
* NOTE: when message structure is changed, make sure that MESSAGE_PACKING_VERSION from VersionableAMB is updated as well
|
||||
* NOTE: assembly code uses calldatacopy, make sure that message is passed as the first argument in the calldata
|
||||
|
@ -29,9 +27,8 @@ library ArbitraryMessage {
|
|||
address sender,
|
||||
address executor,
|
||||
uint32 gasLimit,
|
||||
bytes1 dataType,
|
||||
uint8 dataType,
|
||||
uint256[2] chainIds,
|
||||
uint256 gasPrice,
|
||||
bytes memory data
|
||||
)
|
||||
{
|
||||
|
@ -50,23 +47,16 @@ library ArbitraryMessage {
|
|||
executor := shr(96, blob)
|
||||
gasLimit := and(shr(64, blob), 0xffffffff)
|
||||
|
||||
dataType := byte(26, blob)
|
||||
if gt(dataType, 0) {
|
||||
// for now, only 0 datatype is supported - regular AMB calls
|
||||
// other dataType values are kept reserved for future use
|
||||
revert(0, 0)
|
||||
}
|
||||
|
||||
// load source chain id length
|
||||
let chainIdLength := byte(24, blob)
|
||||
|
||||
dataType := and(shl(208, blob), 0xFF00000000000000000000000000000000000000000000000000000000000000)
|
||||
switch dataType
|
||||
case 0x0000000000000000000000000000000000000000000000000000000000000000 {
|
||||
gasPrice := 0
|
||||
}
|
||||
case 0x0100000000000000000000000000000000000000000000000000000000000000 {
|
||||
gasPrice := mload(add(_data, 111)) // 32
|
||||
srcdataptr := add(srcdataptr, 32)
|
||||
}
|
||||
case 0x0200000000000000000000000000000000000000000000000000000000000000 {
|
||||
gasPrice := 0
|
||||
srcdataptr := add(srcdataptr, 1)
|
||||
}
|
||||
|
||||
// at this moment srcdataptr points to sourceChainId
|
||||
|
||||
// mask for sourceChainId
|
||||
|
|
|
@ -11,15 +11,12 @@ contract MessageTest {
|
|||
address sender,
|
||||
address executor,
|
||||
uint32 gasLimit,
|
||||
bytes1 dataType,
|
||||
uint8 dataType,
|
||||
uint256[2] chainIds,
|
||||
uint256 gasPrice,
|
||||
bytes memory data
|
||||
)
|
||||
{
|
||||
(messageId, sender, executor, gasLimit, dataType, chainIds, gasPrice, data) = ArbitraryMessage.unpackData(
|
||||
_data
|
||||
);
|
||||
(messageId, sender, executor, gasLimit, dataType, chainIds, data) = ArbitraryMessage.unpackData(_data);
|
||||
}
|
||||
|
||||
function unpackDataWithExtraParams(
|
||||
|
@ -33,15 +30,12 @@ contract MessageTest {
|
|||
address sender,
|
||||
address executor,
|
||||
uint32 gasLimit,
|
||||
bytes1 dataType,
|
||||
uint8 dataType,
|
||||
uint256[2] chainIds,
|
||||
uint256 gasPrice,
|
||||
bytes memory data
|
||||
)
|
||||
{
|
||||
(messageId, sender, executor, gasLimit, dataType, chainIds, gasPrice, data) = ArbitraryMessage.unpackData(
|
||||
_data
|
||||
);
|
||||
(messageId, sender, executor, gasLimit, dataType, chainIds, data) = ArbitraryMessage.unpackData(_data);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,19 +19,17 @@ contract BasicForeignAMB is BasicAMB, MessageRelay, MessageDelivery {
|
|||
address sender;
|
||||
address executor;
|
||||
uint32 gasLimit;
|
||||
bytes1 dataType;
|
||||
uint8 dataType;
|
||||
uint256[2] memory chainIds;
|
||||
uint256 gasPrice;
|
||||
bytes memory data;
|
||||
|
||||
(messageId, sender, executor, gasLimit, dataType, chainIds, gasPrice, data) = ArbitraryMessage.unpackData(
|
||||
_data
|
||||
);
|
||||
(messageId, sender, executor, gasLimit, dataType, chainIds, data) = ArbitraryMessage.unpackData(_data);
|
||||
|
||||
require(_isMessageVersionValid(messageId));
|
||||
require(_isDestinationChainIdValid(chainIds[1]));
|
||||
require(!relayedMessages(messageId));
|
||||
setRelayedMessages(messageId, true);
|
||||
processMessage(sender, executor, messageId, gasLimit, dataType, gasPrice, chainIds[0], data);
|
||||
processMessage(sender, executor, messageId, gasLimit, dataType, chainIds[0], data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,16 +46,15 @@ contract BasicHomeAMB is BasicAMB, MessageDelivery {
|
|||
address sender;
|
||||
address executor;
|
||||
uint32 gasLimit;
|
||||
bytes1 dataType;
|
||||
uint8 dataType;
|
||||
uint256[2] memory chainIds;
|
||||
uint256 gasPrice;
|
||||
bytes memory data;
|
||||
(messageId, sender, executor, gasLimit, dataType, chainIds, gasPrice, data) = ArbitraryMessage.unpackData(
|
||||
_message
|
||||
);
|
||||
|
||||
(messageId, sender, executor, gasLimit, dataType, chainIds, data) = ArbitraryMessage.unpackData(_message);
|
||||
|
||||
require(_isMessageVersionValid(messageId));
|
||||
require(_isDestinationChainIdValid(chainIds[1]));
|
||||
processMessage(sender, executor, messageId, gasLimit, dataType, gasPrice, chainIds[0], data);
|
||||
processMessage(sender, executor, messageId, gasLimit, dataType, chainIds[0], data);
|
||||
}
|
||||
|
||||
function submitSignature(bytes signature, bytes message) external onlyValidator {
|
||||
|
|
|
@ -158,8 +158,7 @@ contract MessageProcessor is EternalStorage {
|
|||
address _executor,
|
||||
bytes32 _messageId,
|
||||
uint256 _gasLimit,
|
||||
bytes1, /* dataType */
|
||||
uint256, /* gasPrice */
|
||||
uint8, /* dataType */
|
||||
uint256 _sourceChainId,
|
||||
bytes memory _data
|
||||
) internal {
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
const MessageTest = artifacts.require('MessageTest.sol')
|
||||
|
||||
require('../setup')
|
||||
const { expect } = require('chai')
|
||||
|
||||
contract('ArbitraryMessage.sol', async () => {
|
||||
describe('unpackData', () => {
|
||||
it('unpack dataType 0x00', async () => {
|
||||
it('unpack dataType 0', async () => {
|
||||
// given
|
||||
const msgSender = '0x003667154bb32E42bb9e1E6532F19d187fa0082e'
|
||||
const msgContractAddress = '0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955'
|
||||
|
@ -12,8 +13,7 @@ contract('ArbitraryMessage.sol', async () => {
|
|||
const msgSrcChainId = '1122'
|
||||
const msgDstChainId = '3344'
|
||||
const msgGasLimit = '1535604485'
|
||||
const msgGasPrice = '0'
|
||||
const msgDataType = '0x00'
|
||||
const msgDataType = '0'
|
||||
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
||||
// event message generated by
|
||||
// requireToPassMessage(address _contract, bytes _data, uint256 _gas)
|
||||
|
@ -33,19 +33,18 @@ contract('ArbitraryMessage.sol', async () => {
|
|||
const result = await messageTest.unpackData(message)
|
||||
|
||||
// then
|
||||
const { messageId, chainIds, sender, executor, gasLimit, dataType, gasPrice, data } = result
|
||||
const { messageId, chainIds, sender, executor, gasLimit, dataType, data } = result
|
||||
expect(messageId).to.be.equal(msgId)
|
||||
expect(chainIds[0].toString(16)).to.be.equal(msgSrcChainId)
|
||||
expect(chainIds[1].toString(16)).to.be.equal(msgDstChainId)
|
||||
expect(sender).to.be.equal(msgSender)
|
||||
expect(executor).to.be.equal(msgContractAddress)
|
||||
expect(gasLimit.toString()).to.be.equal(msgGasLimit)
|
||||
expect(dataType).to.be.equal(msgDataType)
|
||||
expect(gasPrice.toString()).to.be.equal(msgGasPrice)
|
||||
expect(dataType).to.be.bignumber.equal(msgDataType)
|
||||
expect(data).to.be.equal(msgData)
|
||||
})
|
||||
|
||||
it('unpack dataType 0x00 with different chain ids', async () => {
|
||||
it('unpack dataType 0 with different chain ids', async () => {
|
||||
// given
|
||||
const msgSender = '0x003667154bb32E42bb9e1E6532F19d187fa0082e'
|
||||
const msgContractAddress = '0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955'
|
||||
|
@ -64,8 +63,7 @@ contract('ArbitraryMessage.sol', async () => {
|
|||
['aabbccddeeff', '112233445566']
|
||||
]
|
||||
const msgGasLimit = '1535604485'
|
||||
const msgGasPrice = '0'
|
||||
const msgDataType = '0x00'
|
||||
const msgDataType = '0'
|
||||
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
||||
// event message generated by
|
||||
// requireToPassMessage(address _contract, bytes _data, uint256 _gas)
|
||||
|
@ -84,105 +82,21 @@ contract('ArbitraryMessage.sol', async () => {
|
|||
const result = await messageTest.unpackData(message)
|
||||
|
||||
// then
|
||||
const { messageId, chainIds, sender, executor, gasLimit, dataType, gasPrice, data } = result
|
||||
const { messageId, chainIds, sender, executor, gasLimit, dataType, data } = result
|
||||
expect(messageId).to.be.equal(msgId)
|
||||
expect(chainIds[0].toString(16).padStart(msgSrcChainId.length, '0')).to.be.equal(msgSrcChainId)
|
||||
expect(chainIds[1].toString(16).padStart(msgDstChainId.length, '0')).to.be.equal(msgDstChainId)
|
||||
expect(sender).to.be.equal(msgSender)
|
||||
expect(executor).to.be.equal(msgContractAddress)
|
||||
expect(gasLimit.toString()).to.be.equal(msgGasLimit)
|
||||
expect(dataType).to.be.equal(msgDataType)
|
||||
expect(gasPrice.toString()).to.be.equal(msgGasPrice)
|
||||
expect(dataType).to.be.bignumber.equal(msgDataType)
|
||||
expect(data).to.be.equal(msgData)
|
||||
}
|
||||
})
|
||||
|
||||
it('unpack dataType 0x01', async () => {
|
||||
// given
|
||||
const msgSender = '0xc95e32f5b21AEA8107aA2c645636E909489031e8'
|
||||
const msgContractAddress = '0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955'
|
||||
const msgId = '0x27aa676e59e4feaafcfde2b88c6002b756795c1260762512ba26ff28fdaf0f64'
|
||||
const msgSrcChainId = '1122'
|
||||
const msgDstChainId = '3344'
|
||||
const msgGasLimit = '1535604485'
|
||||
const msgGasPrice = '6000000000'
|
||||
const msgDataType = '0x01'
|
||||
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
||||
// event message generated by
|
||||
// requireToPassMessage(address _contract, bytes _data, uint256 _gas, uint256 _gasPrice)
|
||||
const message =
|
||||
`${msgId}c95e32f5b21aea8107aa2c645636e909489031e8` + // sender
|
||||
'f4bef13f9f4f2b203faf0c3cbbaabe1afe056955' + // contractAddress
|
||||
'5b877705' + // gasLimit
|
||||
'02' + // source chain id length
|
||||
'02' + // destination chain id length
|
||||
'01' + // dataType
|
||||
'0000000000000000000000000000000000000000000000000000000165a0bc00' + // gasPrice
|
||||
'1122' + // source chain id
|
||||
'3344' + // destination chain id
|
||||
'b1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03' // data
|
||||
|
||||
// when
|
||||
const messageTest = await MessageTest.new()
|
||||
const result = await messageTest.unpackData(message)
|
||||
|
||||
// then
|
||||
const { messageId, chainIds, sender, executor, gasLimit, dataType, gasPrice, data } = result
|
||||
expect(messageId).to.be.equal(msgId)
|
||||
expect(chainIds[0].toString(16)).to.be.equal(msgSrcChainId)
|
||||
expect(chainIds[1].toString(16)).to.be.equal(msgDstChainId)
|
||||
expect(sender).to.be.equal(msgSender)
|
||||
expect(executor).to.be.equal(msgContractAddress)
|
||||
expect(gasLimit.toString()).to.be.equal(msgGasLimit)
|
||||
expect(dataType).to.be.equal(msgDataType)
|
||||
expect(gasPrice.toString()).to.be.equal(msgGasPrice)
|
||||
expect(data).to.be.equal(msgData)
|
||||
})
|
||||
|
||||
it('unpack dataType 0x02', async () => {
|
||||
// given
|
||||
const msgSender = '0xe0241f385c58c88911531DDFe3B5f0fc729BdaEe'
|
||||
const msgContractAddress = '0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955'
|
||||
const msgId = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10'
|
||||
const msgSrcChainId = '1122'
|
||||
const msgDstChainId = '3344'
|
||||
const msgGasLimit = '1535604485'
|
||||
const msgGasPrice = '0'
|
||||
const msgDataType = '0x02'
|
||||
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
||||
// event message generated by
|
||||
// requireToPassMessage(address _contract, bytes _data, uint256 _gas, bytes1 _oracleGasPriceSpeed)
|
||||
const message =
|
||||
`${msgId}e0241f385c58c88911531ddfe3b5f0fc729bdaee` + // sender
|
||||
'f4bef13f9f4f2b203faf0c3cbbaabe1afe056955' + // contractAddress
|
||||
'5b877705' + // gasLimit
|
||||
'02' + // source chain id length
|
||||
'02' + // destination chain id length
|
||||
'02' + // dataType
|
||||
'10' + // gasPriceSpeed
|
||||
'1122' + // source chain id
|
||||
'3344' + // destination chain id
|
||||
'b1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03' // data
|
||||
|
||||
// when
|
||||
const messageTest = await MessageTest.new()
|
||||
const result = await messageTest.unpackData(message)
|
||||
|
||||
// then
|
||||
const { messageId, chainIds, sender, executor, gasLimit, dataType, gasPrice, data } = result
|
||||
expect(messageId).to.be.equal(msgId)
|
||||
expect(chainIds[0].toString(16)).to.be.equal(msgSrcChainId)
|
||||
expect(chainIds[1].toString(16)).to.be.equal(msgDstChainId)
|
||||
expect(sender).to.be.equal(msgSender)
|
||||
expect(executor).to.be.equal(msgContractAddress)
|
||||
expect(gasLimit.toString()).to.be.equal(msgGasLimit)
|
||||
expect(dataType).to.be.equal(msgDataType)
|
||||
expect(gasPrice.toString()).to.be.equal(msgGasPrice)
|
||||
expect(data).to.be.equal(msgData)
|
||||
})
|
||||
})
|
||||
|
||||
describe('unpackData with signatures parameters', () => {
|
||||
it('unpack dataType 0x00', async () => {
|
||||
it('unpack dataType 0', async () => {
|
||||
// given
|
||||
const msgSender = '0x003667154bb32E42bb9e1E6532F19d187fa0082e'
|
||||
const msgContractAddress = '0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955'
|
||||
|
@ -190,8 +104,7 @@ contract('ArbitraryMessage.sol', async () => {
|
|||
const msgSrcChainId = '1122'
|
||||
const msgDstChainId = '3344'
|
||||
const msgGasLimit = '1535604485'
|
||||
const msgGasPrice = '0'
|
||||
const msgDataType = '0x00'
|
||||
const msgDataType = '0'
|
||||
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
||||
// event message generated by
|
||||
// requireToPassMessage(address _contract, bytes _data, uint256 _gas)
|
||||
|
@ -211,99 +124,14 @@ contract('ArbitraryMessage.sol', async () => {
|
|||
const result = await messageTest.unpackDataWithExtraParams(message, '0x')
|
||||
|
||||
// then
|
||||
const { messageId, chainIds, sender, executor, gasLimit, dataType, gasPrice, data } = result
|
||||
const { messageId, chainIds, sender, executor, gasLimit, dataType, data } = result
|
||||
expect(messageId).to.be.equal(msgId)
|
||||
expect(chainIds[0].toString(16)).to.be.equal(msgSrcChainId)
|
||||
expect(chainIds[1].toString(16)).to.be.equal(msgDstChainId)
|
||||
expect(sender).to.be.equal(msgSender)
|
||||
expect(executor).to.be.equal(msgContractAddress)
|
||||
expect(gasLimit.toString()).to.be.equal(msgGasLimit)
|
||||
expect(dataType).to.be.equal(msgDataType)
|
||||
expect(gasPrice.toString()).to.be.equal(msgGasPrice)
|
||||
expect(data).to.be.equal(msgData)
|
||||
})
|
||||
|
||||
it('unpack dataType 0x01', async () => {
|
||||
// given
|
||||
const msgSender = '0xc95e32f5b21AEA8107aA2c645636E909489031e8'
|
||||
const msgContractAddress = '0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955'
|
||||
const msgId = '0x27aa676e59e4feaafcfde2b88c6002b756795c1260762512ba26ff28fdaf0f64'
|
||||
const msgSrcChainId = '1122'
|
||||
const msgDstChainId = '3344'
|
||||
const msgGasLimit = '1535604485'
|
||||
const msgGasPrice = '6000000000'
|
||||
const msgDataType = '0x01'
|
||||
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
||||
// event message generated by
|
||||
// requireToPassMessage(address _contract, bytes _data, uint256 _gas, uint256 _gasPrice)
|
||||
const message =
|
||||
`${msgId}c95e32f5b21aea8107aa2c645636e909489031e8` + // sender
|
||||
'f4bef13f9f4f2b203faf0c3cbbaabe1afe056955' + // contractAddress
|
||||
'5b877705' + // gasLimit
|
||||
'02' + // source chain id length
|
||||
'02' + // destination chain id length
|
||||
'01' + // dataType
|
||||
'0000000000000000000000000000000000000000000000000000000165a0bc00' + // gasPrice
|
||||
'1122' + // source chain id
|
||||
'3344' + // destination chain id
|
||||
'b1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03' // data
|
||||
|
||||
// when
|
||||
const messageTest = await MessageTest.new()
|
||||
const result = await messageTest.unpackDataWithExtraParams(message, '0x')
|
||||
|
||||
// then
|
||||
const { messageId, chainIds, sender, executor, gasLimit, dataType, gasPrice, data } = result
|
||||
expect(messageId).to.be.equal(msgId)
|
||||
expect(chainIds[0].toString(16)).to.be.equal(msgSrcChainId)
|
||||
expect(chainIds[1].toString(16)).to.be.equal(msgDstChainId)
|
||||
expect(sender).to.be.equal(msgSender)
|
||||
expect(executor).to.be.equal(msgContractAddress)
|
||||
expect(gasLimit.toString()).to.be.equal(msgGasLimit)
|
||||
expect(dataType).to.be.equal(msgDataType)
|
||||
expect(gasPrice.toString()).to.be.equal(msgGasPrice)
|
||||
expect(data).to.be.equal(msgData)
|
||||
})
|
||||
|
||||
it('unpack dataType 0x02', async () => {
|
||||
// given
|
||||
const msgSender = '0xe0241f385c58c88911531DDFe3B5f0fc729BdaEe'
|
||||
const msgContractAddress = '0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955'
|
||||
const msgId = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10'
|
||||
const msgSrcChainId = '1122'
|
||||
const msgDstChainId = '3344'
|
||||
const msgGasLimit = '1535604485'
|
||||
const msgGasPrice = '0'
|
||||
const msgDataType = '0x02'
|
||||
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
||||
// event message generated by
|
||||
// requireToPassMessage(address _contract, bytes _data, uint256 _gas, bytes1 _oracleGasPriceSpeed)
|
||||
const message =
|
||||
`${msgId}e0241f385c58c88911531ddfe3b5f0fc729bdaee` + // sender
|
||||
'f4bef13f9f4f2b203faf0c3cbbaabe1afe056955' + // contractAddress
|
||||
'5b877705' + // gasLimit
|
||||
'02' + // source chain id length
|
||||
'02' + // destination chain id length
|
||||
'02' + // dataType
|
||||
'10' + // gasPriceSpeed
|
||||
'1122' + // source chain id
|
||||
'3344' + // destination chain id
|
||||
'b1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03' // data
|
||||
|
||||
// when
|
||||
const messageTest = await MessageTest.new()
|
||||
const result = await messageTest.unpackDataWithExtraParams(message, '0x')
|
||||
|
||||
// then
|
||||
const { messageId, chainIds, sender, executor, gasLimit, dataType, gasPrice, data } = result
|
||||
expect(messageId).to.be.equal(msgId)
|
||||
expect(chainIds[0].toString(16)).to.be.equal(msgSrcChainId)
|
||||
expect(chainIds[1].toString(16)).to.be.equal(msgDstChainId)
|
||||
expect(sender).to.be.equal(msgSender)
|
||||
expect(executor).to.be.equal(msgContractAddress)
|
||||
expect(gasLimit.toString()).to.be.equal(msgGasLimit)
|
||||
expect(dataType).to.be.equal(msgDataType)
|
||||
expect(gasPrice.toString()).to.be.equal(msgGasPrice)
|
||||
expect(dataType).to.be.bignumber.equal(msgDataType)
|
||||
expect(data).to.be.equal(msgData)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue