Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/contracts-bedrock/contracts/libraries/Encoding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ library Encoding {
/**
* @notice RLP encodes the L2 transaction that would be generated when a given deposit is sent
* to the L2 system. Useful for searching for a deposit in the L2 system.
* This currently only supports user deposits and not system
* transactions.
*
* @param _tx User deposit transaction to encode.
*
Expand All @@ -31,7 +33,7 @@ library Encoding {
raw[3] = RLPWriter.writeUint(_tx.mint);
raw[4] = RLPWriter.writeUint(_tx.value);
raw[5] = RLPWriter.writeUint(uint256(_tx.gasLimit));
raw[6] = RLPWriter.writeBool(_tx.isSystemTransaction);
raw[6] = RLPWriter.writeBool(false);
raw[7] = RLPWriter.writeBytes(_tx.data);
return abi.encodePacked(uint8(0x7e), RLPWriter.writeList(raw));
}
Expand Down
1 change: 0 additions & 1 deletion packages/contracts-bedrock/contracts/libraries/Types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ library Types {
uint256 value;
uint256 mint;
uint64 gasLimit;
bool isSystemTransaction;
bytes data;
bytes32 l1BlockHash;
uint256 logIndex;
Expand Down
29 changes: 24 additions & 5 deletions packages/contracts-bedrock/contracts/test/CommonTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,10 @@ contract FFIInterface is Test {
uint256 _mint,
uint256 _value,
uint64 _gas,
bool _isSystemTransaction,
bytes memory _data,
uint256 _logIndex
) external returns (bytes32) {
string[] memory cmds = new string[](12);
string[] memory cmds = new string[](11);
cmds[0] = "node";
cmds[1] = "dist/scripts/differential-testing.js";
cmds[2] = "hashDepositTransaction";
Expand All @@ -576,13 +575,33 @@ contract FFIInterface is Test {
cmds[7] = vm.toString(_mint);
cmds[8] = vm.toString(_value);
cmds[9] = vm.toString(_gas);
cmds[10] = _isSystemTransaction ? "1" : "0";
cmds[11] = vm.toString(_data);
bytes memory result = vm.ffi(cmds);
cmds[10] = vm.toString(_data);

bytes memory result = vm.ffi(cmds);
return abi.decode(result, (bytes32));
}

function encodeDepositTransaction(
Types.UserDepositTransaction calldata txn
) external returns (bytes memory) {
string[] memory cmds = new string[](12);
cmds[0] = "node";
cmds[1] = "dist/scripts/differential-testing.js";
cmds[2] = "encodeDepositTransaction";
cmds[3] = vm.toString(txn.from);
cmds[4] = vm.toString(txn.to);
cmds[5] = vm.toString(txn.value);
cmds[6] = vm.toString(txn.mint);
cmds[7] = vm.toString(txn.gasLimit);
cmds[8] = vm.toString(txn.isCreation);
cmds[9] = vm.toString(txn.data);
cmds[10] = vm.toString(txn.l1BlockHash);
cmds[11] = vm.toString(txn.logIndex);

bytes memory result = vm.ffi(cmds);
return abi.decode(result, (bytes));
}

function encodeCrossDomainMessage(
uint256 _nonce,
address _sender,
Expand Down
30 changes: 30 additions & 0 deletions packages/contracts-bedrock/contracts/test/Encoding.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,34 @@ contract Encoding_Test is CommonTest {

assertEq(encoding, _encoding);
}

function test_encodeDepositTransaction_differential(
address _from,
address _to,
uint256 _mint,
uint256 _value,
uint64 _gas,
bytes memory _data,
uint256 _logIndex
) external {
Types.UserDepositTransaction memory t = Types.UserDepositTransaction(
_from,
_to,
false, // isCreate
_value,
_mint,
_gas,
_data,
bytes32(uint256(0)),
_logIndex
);

bytes memory txn = Encoding.encodeDepositTransaction(t);
bytes memory _txn = ffi.encodeDepositTransaction(t);

assertEq(
txn,
_txn
);
}
}
3 changes: 0 additions & 3 deletions packages/contracts-bedrock/contracts/test/Hashing.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ contract Hashing_Test is CommonTest {
uint256 _mint,
uint256 _value,
uint64 _gas,
bool _isSystemTransaction,
bytes memory _data,
uint256 _logIndex
) external {
Expand All @@ -132,7 +131,6 @@ contract Hashing_Test is CommonTest {
_value,
_mint,
_gas,
_isSystemTransaction,
_data,
bytes32(uint256(0)),
_logIndex
Expand All @@ -145,7 +143,6 @@ contract Hashing_Test is CommonTest {
_mint,
_value,
_gas,
_isSystemTransaction,
_data,
_logIndex
);
Expand Down
30 changes: 30 additions & 0 deletions packages/contracts-bedrock/scripts/differential-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,44 @@ const command = args[0]
gas,
isSystemTransaction,
data,
isSystemTransaction: false,
domain: SourceHashDomain.UserDeposit,
})

const digest = tx.hash()

const output = utils.defaultAbiCoder.encode(['bytes32'], [digest])
process.stdout.write(output)
break
}
case 'encodeDepositTransaction': {
const from = args[1]
const to = args[2]
const value = BigNumber.from(args[3])
const mint = BigNumber.from(args[4])
const gasLimit = BigNumber.from(args[5])
const isCreate = Boolean(args[6])
const data = args[7]
const l1BlockHash = args[8]
const logIndex = BigNumber.from(args[9])

const tx = new DepositTx({
from,
to: isCreate ? constants.AddressZero : to,
value,
mint,
gas: gasLimit,
data,
l1BlockHash,
logIndex,
domain: SourceHashDomain.UserDeposit,
})

const raw = tx.encode()
const output = utils.defaultAbiCoder.encode(['bytes'], [raw])
process.stdout.write(output)
break
}
case 'hashWithdrawal': {
const nonce = BigNumber.from(args[1])
const sender = args[2]
Expand Down
2 changes: 1 addition & 1 deletion packages/core-utils/src/optimism/deposit-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class DepositTx {
this.mint = opts.mint!
this.value = opts.value!
this.gas = opts.gas!
this.isSystemTransaction = opts.isSystemTransaction!
this.isSystemTransaction = opts.isSystemTransaction || false
this.data = opts.data!
this.domain = opts.domain
this.l1BlockHash = opts.l1BlockHash
Expand Down